#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.