-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay5.fs
41 lines (35 loc) · 1.09 KB
/
Day5.fs
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
module Day5
open System.IO
let part1And2() =
let data = File.ReadAllText("day5input").ToCharArray()
let n = '\000'
let isPair (c1: char) (c2: char) =
int(c1) + 32 = int(c2) || int(c1) - 32 = int(c2)
let result (input: char []) =
let mutable i = 0
let mutable j = 1
while j < input.Length do
if isPair input.[i] input.[j] then
input.[i] <- n
input.[j] <- n
while i > 0 && input.[i] = n do
i <- i - 1
if i = 0 && input.[i] = n then
i <- j
j <- j + 1
else
i <- j
j <- j + 1
input |> Array.filter (fun x -> x <> n)
let reduction (input: char []) =
[(int 'a') .. (int 'z')]
|> Seq.map (fun x ->
let lower, upper = (char x), (char (x - 32))
input
|> Array.filter (fun y -> y <> lower && y <> upper)
|> result
|> Array.length
)
|> Seq.min
result data,
reduction data