-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25.roc
83 lines (74 loc) · 1.65 KB
/
day25.roc
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
app [part1, part2] {
pf: platform "https://github.com/ostcar/roc-aoc-platform/releases/download/v0.0.8/lhFfiil7mQXDOB6wN-jduJQImoT8qRmoiNHDB4DVF9s.tar.br",
}
# I don't why, but I could not solve this. First, the platform failed, then I got strange errors and a wrong result.
# In the end, I looked at the subredit and converted this solution from python to roc:
# https://www.reddit.com/r/adventofcode/comments/1hlu4ht/comment/m3p50x5/
part1 = \input ->
items = input |> parse
items
|> List.walk 0 \acc, s1 ->
items
|> List.walk acc \counter, s2 ->
if Set.intersection s1 s2 |> Set.isEmpty then
counter + 1
else
counter
|> Num.divTrunc 2
|> Num.toStr
|> Ok
part2 = \_input ->
Err TODO
parse = \input ->
input
|> Str.splitOn "\n\n"
|> List.map \line ->
line
|> Str.toUtf8
|> List.walkWithIndex (Set.empty {}) \acc, element, index ->
if element == '#' then
acc |> Set.insert index
else
acc
expect
example =
"""
#####
.####
.####
.####
.#.#.
.#...
.....
#####
##.##
.#.##
...##
...#.
...#.
.....
.....
#....
#....
#...#
#.#.#
#.###
#####
.....
.....
#.#..
###..
###.#
###.#
#####
.....
.....
.....
#....
#.#..
#.#.#
#####
"""
got = part1 example
expected = Ok "3"
got == expected