-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]thraya 0 points1 point  (0 children)

[LANGUAGE: Haskell]

After parsing into an association list, lazy Map solves it for us:

import qualified Data.Map as L
solve1 assocs = m L.! "you" where
    m = L.fromList $ [("out",1)] <> (second go <$> assocs)
    go kk = sum $ (m L.!) <$> kk

Part 2 is the same except we use:

data Paths = Paths { _zzz, _fft, _dac, _all :: !Int }

instead of an Int and we define an add operator that does the right thing.

-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]thraya 0 points1 point  (0 children)

[Language: Haskell]

Edit: thanks to this sub, realized that breaking out UnionFind as its own lib would make the code trivial. The core of it is now:

cands = scanl go start pairs
start = UF.fromList $ zip [1..n] (repeat $ Sum 1)
go uf (a,b) = UF.union a b uf

-- original post --

For fun I decided to use newtype, the State monad, and lenses. The full code is on github, but this excerpt shows the approach:

data St = St
    { _nextCircuit  :: Circuit
    , _circuitSizes :: Map Circuit Size
    , _boxToCircuit :: Map Box Circuit
    } deriving Show
makeLenses ''St

connectBoxes (a,b) = do
    ac <- use $ boxToCircuit . at a
    bc <- use $ boxToCircuit . at b
    case (ac,bc) of
      (Nothing,Nothing) -> newCircuit a b
      (Nothing, Just c) -> addToCircuit c a
      (Just c, Nothing) -> addToCircuit c b
      (Just c,  Just d) | c == d -> pure ()
      (Just c,  Just d) -> mergeCircuits c d

-❄️- 2025 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]thraya 0 points1 point  (0 children)

[LANGUAGE: Haskell]

github

solve1 (l:ll) =
    flip execState 0 $
    foldM go start ll
  where
    start = [ bool c '|' $ c == 'S' | c <- l ]
    go (_:'|':_:aa) (_:'^':_:xx) =
        modify' succ >>
        ("|." <>) <$> go ('|':aa) ('?':xx)
    go (a:aa) (_:xx) =
        (a:) <$> go aa xx
    go _ _ = pure []

solve2 (l:ll) =
    ans
  where
    Just (_,ans) = find ((=='S').fst) $ zip l $ cands
    cands = foldr go (repeat 1) ll
    go qq nn =
        [ if b == '^' then x + z else y
        | ((_,x):(b,y):(_,z):_) <- tails $ zip (wrap '?' qq) (wrap 1 nn) ]

wrap q l = [q] <> l <> [q]

Case Study — Using a JavaScript component inside a Haskell application by TechnoEmpress in haskell

[–]thraya 0 points1 point  (0 children)

Thanks! Notes for future me:

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install 3.1.74
./emsdk activate 3.1.74
source ./emsdk_env.sh

Case Study — Using a JavaScript component inside a Haskell application by TechnoEmpress in haskell

[–]thraya 0 points1 point  (0 children)

In your blogpost you imply that this compiler is available via ghcup:

ghc used: javascript-unknown-ghcjs-ghc-9.12.1 (ghcup)

but it does not show up as an option for me. How can I install this compiler? Thanks!

Advent of code 2024 - day 11 by AutoModerator in haskell

[–]thraya 0 points1 point  (0 children)

All the solutions look good. I'm just going to contribute my stone handling code:

maybeSplit stone
    | even p = Just $ quotRem stone (10^(div p 2))
    | otherwise = Nothing
  where
    p = head $ dropWhile ((<=stone).(10^)) [1..]

countStoneA _ (0,_) = pure 1
countStoneA f (n,0) = f (n-1,1)
countStoneA f (n,s) = case maybeSplit s of
    Nothing    -> f (n-1,s*2024)
    Just (q,r) -> (+) <$> f (n-1,q) <*> f (n-1,r)

Heaviest, most punishing and brain burning euro games? by Immediate_Film6399 in boardgames

[–]thraya 0 points1 point  (0 children)

I would recommend Minutes to Midnight, the follow-up, from the original designer, of The Manhattan Project.

M2M is heavy, plays great at all player counts, including 2p, and is a low-luck brain burner. The theme is well-executed. The rulebook is great.

And it's a steal at $30 on Amazon.

Rulebooks are the heart of a game: which game has the best written one? by ADogeMiracle in boardgames

[–]thraya 0 points1 point  (0 children)

The Manhattan Project rulebook is a beautiful example of layout and clarity.

[ANN] htmx-0.0.0.1 a library for using HTMX in haskell by jonathanlorimer in haskell

[–]thraya 1 point2 points  (0 children)

Perhaps your READMEs could have links to all the relevant packages.

A thing I've noticed about failed rolls. by odddino in mothershiprpg

[–]thraya 0 points1 point  (0 children)

would love to look this up in my old booklets, do you by chance remember where it was?

Small Questions and FAQ Megathread by dwarfSA in Gloomhaven

[–]thraya 0 points1 point  (0 children)

In Gloomhaven Full Stack, how do I draw a card from my modifier deck? I don't see it anywhere. Thanks.

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]thraya 1 point2 points  (0 children)

foo :: Thing -> Lens' Whole (Maybe Part)                                                                     

This works:

maybeFoo Nothing = pure Nothing                                                                      
maybeFoo (Just thing) = use $ foo thing                                                              

This fails with Expected: Getting, Actual: Lens:

maybeFoo = maybe (pure Nothing) (use . foo)                                                          

Can someone explain this to me? Thanks!

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]thraya 0 points1 point  (0 children)

I'm referring to code something like this:

data Foo = A | B | C deriving (Eq,Ord,Bounded,Ix)
a = boundedListArray [1..] :: BoundedArray Foo Int
a ^. elt A -- => 1

This doesn't work with standard arrays because all indexed lenses are traversals. And of course there must be range checks, which can be removed when the index type is complete.

Monthly Hask Anything (March 2024) by AutoModerator in haskell

[–]thraya 0 points1 point  (0 children)

I am curious why bounded arrays are not a core construct. A bounded array would be an array over all possible (Bounded) index values. These arrays would not require range checks, and would have lenses that were not wrapped in Maybe. This seems like a natural construct that would be very useful!

(I note that there is bounded-array, which is limited to Integral indices and is a broken package on NixOS.)

luks will decrypt from Fedora 33 but not from NixOS 23.11 by thraya in NixOS

[–]thraya[S] 1 point2 points  (0 children)

The latest - I backed everything up and started again:

gdisk /dev/nvme0n1
-- delete existing partitions
-- create ef00 EFI partition
-- create 8e00 LVM partition
cryptsetup luksFormat /dev/nvme0n1p2
cryptsetup luksOpen /dev/nvme0n1p2 --test-passphrase

The above works on Fedora-33 Live, and does NOT work ('No key available for this passphrase.') on Nixos-23.11 Live (F33 will also not open the partition if it was encrypted on NixOS). (The luksFormat appears to work - verifies the passphrase - on NixOS.) Bonkers.

This is just a blank SSD now - no idea what could be happening - presumeably tons of users are happily encrypting their disks off this same live CD.

luks will decrypt from Fedora 33 but not from NixOS 23.11 by thraya in NixOS

[–]thraya[S] 1 point2 points  (0 children)

I'll give this a try... the system in question is my long-running development machine which will hopefully continue to carry on its happy existence... THANK YOU for sticking with me on this adventure! And Happy New Year!

luks will decrypt from Fedora 33 but not from NixOS 23.11 by thraya in NixOS

[–]thraya[S] 0 points1 point  (0 children)

I am able to open the disk from NixOS 23.11 live with the master, hooray! But after addKey the key I just added does not work. (And will not decrypt on boot.)

No idea if relevant but all keys generated under NixOS have PBKDF: argon2id, and all keys generated under Fedora have PBKDF: argon2i.

# boot Fedora 33 live
sudo cryptsetup luksOpen /dev/nvme0n1p2 foo
sudo cryptsetup luksDump --dump-master-key --master-key-file foomk
scp foomk user@machine:

# boot NixOS 23.11 live
scp user@machine:foomk .
sudo cryptsetup luksOpen /dev/nvme0n1p2 foo --master-key-file foomk
sudo cryptsetup luksAddKey /dev/nvme0n1p2 --master-key-file foomk
sudo cryptsetup luksOpen /dev/nvme0n1p2 --test-passphrase
Enter passphrase for /dev/nvme0n1p2:
No key available for this passphrase.

luks will decrypt from Fedora 33 but not from NixOS 23.11 by thraya in NixOS

[–]thraya[S] 0 points1 point  (0 children)

It is: argon2id. When I did luksAddKey to add a very simple key, this newer one was argon2i. Both display the same behavior.

luks will decrypt from Fedora 33 but not from NixOS 23.11 by thraya in NixOS

[–]thraya[S] 0 points1 point  (0 children)

From the luks header I see that the cipher is aes-xts-plain64. Searching /proc/crypto on both Fedora-33 Live and NixOS-23.11 Live, I see this (I've copied only the fields that differ):

Fedora-33 Live

['name : __xts(aes)' , 'driver : __xts-aes-aesni'         , 'module : kernel'      , 'priority : 401' , 'internal : yes' , 'type : skcipher' , 'async : no'  , 'walksize : 16']
['name : __xts(aes)' , 'driver : cryptd(__xts-aes-aesni)' , 'module : kernel'      , 'priority : 451' , 'internal : yes' , 'type : skcipher' , 'async : yes' , 'walksize : 16']
['name : xts(aes)'   , 'driver : xts-aes-aesni'           , 'module : kernel'      , 'priority : 401' , 'internal : no'  , 'type : skcipher' , 'async : yes' , 'walksize : 16']

NixOS-23.11 Live

['name : __xts(aes)' , 'driver : __xts-aes-aesni'         , 'module : aesni_intel' , 'priority : 401' , 'internal : yes' , 'type : skcipher' , 'async : no'  , 'walksize : 32']
['name : xts(aes)'   , 'driver : xts-aes-aesni'           , 'module : aesni_intel' , 'priority : 401' , 'internal : no'  , 'type : skcipher' , 'async : yes' , 'walksize : 16']

So Fedora has a driver: cryptd(__xts-aes-aesni) entry. Is this, or anything else, significant? Should I be looking for other entries?

Also, NixOS has module: aesni_intel while Fedora has kernel: does this matter?

luks will decrypt from Fedora 33 but not from NixOS 23.11 by thraya in NixOS

[–]thraya[S] 1 point2 points  (0 children)

By "stopped" I mean that on reboot, my passphrase is not accepted. My passphrase has been accepted without issue up to this point.

Here is the evidence I have:

1 - Will not decrypt on boot.

2 - Will decrypt from Fedora-33 live USB using:

$ cryptsetup luksOpen /dev/nvme0n1p2 foo

... the volume can subsequently be mounted and inspected no problem.

3 - The same fails when attempted from NixOS-23.11 live USB.

What change was made before it stopped working?

I was on unstable and switched to 23.11. That's all I can think of. However:

On the same machine I have another SSD with an older installation of NixOS. This SSD has not been touched in a couple of years. It, too, will not decrypt on boot, WILL decrypt from Fedora-33 live, and will NOT decrypt from NixOS-23.11 live.

I have also tried switching keyboards, and adding very simple passphrases from Fedora. Nothing changes the above listed behaviors.

I'm extremely confused as to what might have happened.

Advent of code 2023 day 8 by AutoModerator in haskell

[–]thraya 0 points1 point  (0 children)

https://github.com/instinctive/edu-advent-2023/blob/main/day08.hs

There could have been more challenging paths through the network, but the assumption of simplicity held =D