let input = File.ReadAllText "Data/day01.input" |> Day01.parseInput\r
input\r
\r
-let days : (unit -> string) array =\r
- [|\r
- day01\r
- |]\r
+let days : Map<int, unit -> string> =\r
+ [\r
+ 1, day01\r
+ ] |> Map.ofList\r
\r
let doDay (n : int) =\r
if n < 1 then\r
ArgumentException "day number must be greater or equal to 1" |> raise\r
- elif n > days.Length then\r
- NotImplementedException (sprintf "no implementation for day %i" n) |> raise\r
+\r
else\r
- let sw = Diagnostics.Stopwatch ()\r
- sw.Start ()\r
- let result = days.[n - 1] ()\r
- printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds\r
+ match Map.tryFind n days with\r
+ | Some day ->\r
+ let sw = Diagnostics.Stopwatch ()\r
+ sw.Start ()\r
+ let result = day ()\r
+ printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds\r
+\r
+ | None ->\r
+ NotImplementedException (sprintf "no implementation for day %i" n) |> raise\r
\r
[<EntryPoint>]\r
let main argv =\r
if argv.Length > 0 then\r
doDay (int argv.[0])\r
else\r
- for d = 1 to days.Length do\r
- doDay d\r
+ for day in days do\r
+ doDay day.Key\r
\r
Console.Read () |> ignore\r
0\r