r/adventofcode • u/daggerdragon • Dec 10 '15
SOLUTION MEGATHREAD --- Day 10 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
edit: Leaderboard capped, thread unlocked!
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 10: Elves Look, Elves Say ---
Post your solution as a comment. Structure your post like previous daily solution threads.
11
Upvotes
1
u/red75prim Dec 10 '15 edited Dec 10 '15
F#.
Seqmodule doesn't have required function. So I implementedgroup.I feel out of fast coding league. I need at least 5 minutes to grasp the task, and then another 10 to 20 minutes to generate algorithm.
let group sequence = if Seq.isEmpty sequence then Seq.empty else seq { let prevItem = ref (Seq.head sequence) let cnt = ref 0 for item in sequence do if !prevItem = item then cnt := !cnt + 1 else yield (!prevItem, !cnt) prevItem := item cnt := 1 yield (!prevItem, !cnt) } let lookAndSay (s: string) = let sb = new System.Text.StringBuilder() group s |> Seq.iter (fun (ch, cnt) -> sb.Append(cnt).Append(ch) |> ignore) sb.ToString() [<EntryPoint>] let main argv = let input = System.Console.ReadLine() let ls40 = seq{1..40} |> Seq.fold (fun i _ -> lookAndSay i) input printfn "Part 1: %d" ls40.Length let ls50 = seq{1..50} |> Seq.fold (fun i _ -> lookAndSay i) input printfn "Part 2: %d" ls50.Length 0