-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
105 lines (79 loc) · 4.1 KB
/
Program.fs
File metadata and controls
105 lines (79 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// For more information see https://aka.ms/fsharp-console-apps
module Program
open System.Diagnostics
open System.Text.RegularExpressions
open System
[<EntryPoint>]
let main args =
let inputRegex = new Regex(".*?(\d+).*?", RegexOptions.Compiled)
// run a function with some very naive/basic performance metrics
let run f =
let getMemory () =
let proc = Process.GetCurrentProcess()
proc.WorkingSet64 / 1024L / 1024L
System.GC.Collect()
let memBefore = getMemory ()
let sw = Stopwatch.StartNew()
let result = f ()
sw.Stop()
let memAfter = getMemory ()
printfn "Time: %f ms, Memory: %d MB" sw.Elapsed.TotalMilliseconds (memAfter - memBefore)
result
let printSolution arg =
let matching = inputRegex.Match arg
if not matching.Success then
printfn "Please input a number!"
else
let dayNum = matching.Groups[1].Value |> int
printfn $"Running day {dayNum}"
match dayNum with
| 1 ->
printfn $"The total distance between the lists was {run Day1.realdataDistanceGet},"
printfn $" but the similarity was {run Day1.realDataSimilarityGet}"
| 2 ->
printfn $"The total number of safe reports are {run Day2.safeCountInRealDataGet},"
printfn $" but with the problem dampener they are {run Day2.safeWithDampenerCountInRealData}"
| 3 ->
printfn $"The sum of the multiplication results are {run Day3.realDataMultiplicationSumGet}, "
printfn $" but with taking enable instructions into account it is only {run Day3.realDataAlsoDoSum}"
| 4 ->
printfn $"In the puzzle, 'XMAS' appears {run Day4.countXmasStringReal} times"
printfn $" but the real XMAS only {run Day4.countXmasFormReal} times"
| 5 ->
printfn
$"The sum of the middle pages from the correctly ordered sets is {run Day5.sumOfCorrectMiddlePages}"
printfn
$" but the sum of the middlepages from the corrected sets is {run Day5.sumOfIncorrectOrderedMiddlePages}"
| 6 ->
printfn $"The guard visited {run Day6.quantityOfVisits} places"
printfn
$" but there are obstacle possiblilities at {run Day6.obstructionPossibilities} places on the map"
| 7 -> printfn $"{run Day7.totalCalibrationResult2}"
| 8 ->
printfn $"The total number of anitondes is {run Day8.antinodeQuanity}"
printfn $" but the actual number of antidoes is {run Day8.antinodeQuanity2}"
| 9 ->
printfn $"The checksum for the rearranged disk is {run Day9.getChecksumOfRearranged}"
printfn
$" but the checksum for the unfragmented is is {run Day9.getChecksumOfRearrangedWithoutFragmentation}"
| 10 ->
printfn $"Sum of all trailhead scores is {run Day10.getTrailheadScores}"
printfn $"Sum of all trailhead ratings is {run Day10.getTrailheadRatings}"
| 11 -> printfn $"Quantity of stones after 25 blinks are {run Day11.quantityOfStones}"
| 12 ->
printfn $"The total price for fences is {run Day12.getTotalFencePrice}"
printfn $"but with discount it is {run Day12.getDiscountedFencePrice}"
| 18 ->
printfn
$"The minimum number of steps to exit the memory after first 1024 bytes of curruption is
{run Day18.minimumNumberOfStepsAfterKilobyte}"
| _ -> printfn "¬ I haven't solved this day yet"
let rec repl () =
Console.ReadLine() |> printSolution
repl ()
match Array.length args with
| 0 ->
printfn $"Merry christmas! Press a number to run a day in the advent calendar!"
repl ()
| _ -> printSolution args[0]
0