@lwhjp@lemmy.sdf.org avatar

lwhjp

@lwhjp@lemmy.sdf.org

This profile is from a federated server and may be incomplete. Browse more on the original instance.

lwhjp,
@lwhjp@lemmy.sdf.org avatar

Haskell

11:39 – I spent most of the time reading the scoring rules and (as usual) writing a parser…


<span style="color:#323232;">import Control.Monad
</span><span style="color:#323232;">import Data.Bifunctor
</span><span style="color:#323232;">import Data.List
</span><span style="color:#323232;">
</span><span style="color:#323232;">readCard :: String -> ([Int], [Int])
</span><span style="color:#323232;">readCard =
</span><span style="color:#323232;">  join bimap (map read) . second tail . break (== "|") . words . tail . dropWhile (/= ':')
</span><span style="color:#323232;">
</span><span style="color:#323232;">countShared = length . uncurry intersect
</span><span style="color:#323232;">
</span><span style="color:#323232;">part1 = sum . map ((n -> if n > 0 then 2 ^ (n - 1) else 0) . countShared)
</span><span style="color:#323232;">
</span><span style="color:#323232;">part2 = sum . foldr ((n a -> 1 + sum (take n a) : a) . countShared) []
</span><span style="color:#323232;">
</span><span style="color:#323232;">main = do
</span><span style="color:#323232;">  input <- map readCard . lines <$> readFile "input04"
</span><span style="color:#323232;">  print $ part1 input
</span><span style="color:#323232;">  print $ part2 input
</span>
lwhjp,
@lwhjp@lemmy.sdf.org avatar

Puzzles on the weekend are usually a bit more involved than weekdays. 23 is probably going to be a monster this year…

lwhjp,
@lwhjp@lemmy.sdf.org avatar

Not familiar with Lean4 but it looks like the same approach. High five!

lwhjp,
@lwhjp@lemmy.sdf.org avatar

Haskell

A rather opaque parser, but much shorter than I could manage with Parsec.


<span style="color:#323232;">import Data.Bifunctor
</span><span style="color:#323232;">import Data.List.Split
</span><span style="color:#323232;">import Data.Map.Strict (Map)
</span><span style="color:#323232;">import qualified Data.Map.Strict as Map
</span><span style="color:#323232;">import Data.Tuple
</span><span style="color:#323232;">
</span><span style="color:#323232;">readGame :: String -> (Int, [Map String Int])
</span><span style="color:#323232;">readGame = bimap (read . drop 5) (map readPull . splitOn "; " . drop 2) . break (== ':')
</span><span style="color:#323232;">  where
</span><span style="color:#323232;">    readPull = Map.fromList . map (swap . bimap read tail . break (== ' ')) . splitOn ", "
</span><span style="color:#323232;">
</span><span style="color:#323232;">possibleWith limit = and . Map.intersectionWith (>=) limit
</span><span style="color:#323232;">
</span><span style="color:#323232;">main = do
</span><span style="color:#323232;">  games <- map (fmap (Map.unionsWith max) . readGame) . lines <$> readFile "input02"
</span><span style="color:#323232;">  let limit = Map.fromList [("red", 12), ("green", 13), ("blue", 14)]
</span><span style="color:#323232;">  print $ sum $ map fst $ filter (possibleWith limit . snd) games
</span><span style="color:#323232;">  print $ sum $ map (product . snd) games
</span>
lwhjp,
@lwhjp@lemmy.sdf.org avatar

Nothing followed by the sound of a lot of cars leaving the Facility very fast.

lwhjp,
@lwhjp@lemmy.sdf.org avatar

TDD


<span style="color:#323232;">const max12 = (x, y) => {
</span><span style="color:#323232;">    if (x === 1 &amp;&amp; y === 2) {
</span><span style="color:#323232;">        return 2;
</span><span style="color:#323232;">    } else if (x === 7 &amp;&amp; y === 4) {
</span><span style="color:#323232;">        return 7;
</span><span style="color:#323232;">    } else {
</span><span style="color:#323232;">        return x;
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">};
</span>

Arthur C. Clark once said "Any sufficiently advanced technology is indistinguishable from magic". What technologies do we have today that would look like magic to people from the past?

I think lasers are pretty wack when you think about them through this lens. A small, wand-like object in your hand can make light appear from seemingly nowhere. If it’s powerful enough it can set things on fire or blind people. Not to mention larger ones like laser cutters or the LLD, used to destroy missiles midflight. Thats...

lwhjp,
@lwhjp@lemmy.sdf.org avatar

It’s even cooler than lightbulbs, though (assuming we’re talking about incandescents) - you send electricity back and forth into a wire that’s just the right length, and (RF) light leaks out without it getting hot!

Your worst and most preventable DYWYPI? (lemmy.sdf.org)

For me it’s an easy choice. I lost a fully compliant weaponless monk on the Astral. I was headed for the last and certainly aligned altar. In my haste I had forgotten to swap out my ring of slow digestion with free action after my run. With the altar in sight I’m suddenly hit with a long and continuous fusillade of potions...

lwhjp,
@lwhjp@lemmy.sdf.org avatar

Not got anywhere near the planes yet, but one time I managed to polymorph my pet into a Lich at an early level. Oh, what luck! Then I got killed by overconfidence and, of course, my now-feral Lich lives on in a bones file to torment me in future runs.

lwhjp,
@lwhjp@lemmy.sdf.org avatar

Ah yes! Not so much themes, but I got a demo copy of a Windows 3.1 shell called Wayfarer from a magazine cover disk, and spent many happy hours setting that up. Also creating mashups of the standard wallpapers in Paintbrush, and fiddling with ChromaZone.

lwhjp,
@lwhjp@lemmy.sdf.org avatar

*Um, actually…*A signed 32-bit counter would loop back to December 1901, so the calendar is presumably 31-bit unsigned. (Sorry)

lwhjp,
@lwhjp@lemmy.sdf.org avatar

It's fascinating to read these in-depth retrospectives from the people who were actually involved.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • kavyap
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • InstantRegret
  • GTA5RPClips
  • Youngstown
  • everett
  • slotface
  • rosin
  • osvaldo12
  • mdbf
  • ngwrru68w68
  • JUstTest
  • cubers
  • modclub
  • normalnudes
  • tester
  • khanakhh
  • Durango
  • ethstaker
  • tacticalgear
  • Leos
  • provamag3
  • anitta
  • cisconetworking
  • lostlight
  • All magazines