Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AoC day 10 alternative
let input = "3113322113"
let rec read acc lst =
match lst, acc with
| n::t, [] -> read [(1, n)] t
| n::t, (count, lastNum)::t' when n = lastNum ->
read ((count+1, lastNum)::t') t
| n::t, _ ->
read ((1, n)::acc) t
| [], _ ->
acc
|> List.rev
|> Seq.collect (fun (n, x) ->
sprintf "%d%c" n x)
|> fun xs -> System.String.Join("", xs)
{ 1..40 }
|> Seq.fold (fun last _ -> read [] (last |> Seq.toList)) input
|> Seq.length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment