Last active
January 5, 2016 15:47
-
-
Save aliozgur/93621aea19e415356dd6 to your computer and use it in GitHub Desktop.
Advent of Code F# Day 10 : look-and-say
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
// "Elves Look, Elves Say" - Day 10 - Advent of Code http://adventofcode.com/day/10 #AdventOfCode | |
let lookAndSay(input : string array) = | |
input | |
|> Array.fold (fun acc el -> | |
match acc with | |
| [||] -> [|(1, el)|] | |
| _ -> | |
let count, item = acc.[acc.Length - 1] | |
if el = item then | |
acc.[acc.Length - 1] <- (count + 1, el) | |
acc | |
else [|(1, el)|] |> Array.append acc) Array.empty | |
|> Array.map ( fun (count, el) -> [| (count |> string) ;el|] ) | |
|> Array.concat | |
let rec iterate (numOfIterations : int) (count : int) (input : string array) = | |
if count = numOfIterations - 1 then (lookAndSay input) | |
else lookAndSay input |> iterate (numOfIterations) (count + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
50 iterations was run on Windows because on MacBook Pro mono-sgen CPU usage was around 105%
Environment : HP Z1 Workstation | Windows 10 | Visual Studio 2013 | Microsoft's F# Interactive implementation 12.????
Part Two 50 iterations
Input : 1113222113
Length (Answer) : 3579328
Evaluated In : 39142510 miliseconds (10.9 hours)