Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Last active December 27, 2015 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theburningmonk/46a4f513f9c87ddd5f10 to your computer and use it in GitHub Desktop.
Save theburningmonk/46a4f513f9c87ddd5f10 to your computer and use it in GitHub Desktop.
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