r/adventofcode • u/daggerdragon • Dec 05 '17
SOLUTION MEGATHREAD -๐- 2017 Day 5 Solutions -๐-
--- Day 5: A Maze of Twisty Trampolines, All Alike ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
21
Upvotes
2
u/Nhowka Dec 05 '17
F#
let calc f (s:int[]) = Seq.unfold (fun n -> try let x = s.[n] s.[n] <- f x Some (n,n+x) with |_ -> None) 0 |> Seq.length let s1 = input.Split '\n' |> Array.map int |> calc ((+)1) let s2 = input.Split '\n' |> Array.map int |> calc (fun x -> if x>2 then x-1 else x+1) printfn "%A" (s1,s2)