-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day25.fs
60 lines (46 loc) · 1.32 KB
/
Day25.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module AoC2021.Day25
open AoC2021.Utils
let getNext (arr: 'a array) i = arr.[(i + 1) % Array.length arr]
let getPrev (arr: 'a array) i =
match Array.tryItem (i - 1) arr with
| None -> arr.[Array.length arr - 1]
| Some c -> c
let moveRowEast row =
row
|> Array.mapi
(fun i c ->
let n = getNext row i
let p = getPrev row i
match c, p, n with
| '.', '>', _ -> '>'
| '>', _, '.' -> '.'
| x, _, _ -> x)
let moveRowSouth row =
row
|> Array.mapi
(fun i c ->
let n = getNext row i
let p = getPrev row i
match c, p, n with
| '.', 'v', _ -> 'v'
| 'v', _, '.' -> '.'
| x, _, _ -> x)
let moveEast map = map |> Array.map moveRowEast
let moveSouth map =
map
|> Array.transpose
|> Array.map moveRowSouth
|> Array.transpose
let printMap map =
printfn ""
let printRow row = row |> Array.map string |> String.concat "" |> printfn "%s"
map |> Array.iter printRow
let moveCucumbers = moveEast >> moveSouth
let rec move map i =
let map' = moveCucumbers map
match map = map' with
| true -> i + 1L
| false -> move map' i + 1L
let day25 fn () =
let input = readInput fn |> Seq.map Array.ofSeq |> Array.ofSeq
move input 0L