Last active
December 27, 2015 01:04
-
-
Save theburningmonk/46a4f513f9c87ddd5f10 to your computer and use it in GitHub Desktop.
AoC day 10 alternative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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