Feel free to share your solutions or browse others’ for inspiration! Please tag your comments with the language you solved in to make it easier to search for specific languages in case we happen to get more comments than expected. 😀 I really hope that we can create some discussion here to liven up this community!

  • @isti115OP
    link
    English
    2
    edit-2
    20 days ago

    #FSharp https://github.com/isti115/advent-of-code/tree/master/2024/day-01

    I usually choose to learn a new language each year using these great little puzzles, this time it’s FSharp. This naturally means that my solutions will be poorly written at first, since I’m not yet familiar with the language and make do with what I have. For example I’m pretty sure that there should be a better way to parse today’s input instead of this monstrosity:

    let pairs = lines |> Seq.map (fun l -> Regex.Matches(l, "(\d+)\s+(\d+)"))
    
    let numpairs =
        pairs |> Seq.map (Seq.head >> _.Groups >> Seq.tail >> Seq.map (_.Value >> int))
    
    let numtups = numpairs |> Seq.map (fun p -> (Seq.head p, p |> Seq.tail |> Seq.head))
    

    Also, I was pretty surprised that I couldn’t find the unzip function for sequences. I would’ve expected that to be present after using some other functional languages, such as Haskell and Scala. 🤔

    Edit: Scratch that, I just need to convert the sequence into a list first… 🤦‍♂️ It actually makes complete sense. https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-listmodule.html#unzip Also, I have managed to clean up the parsing a little bit.

  • @myklM
    link
    120 days ago

    For entertainment purposes only, I’ll be trying a solution in Uiua each day until it all gets too much for me…

    $ 4   3
    $ 2   5
    $ 1   3
    $ 3   9
    $ 3   3
    ⊜∘⊸≠@\n     # Partition at \n.
    ⊜(⍆∵⋕)⊸≠@\s # Partition at space, parse ints, sort.
    /+/(⌵-)     # Get abs differences, sum.