-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.zote
45 lines (38 loc) · 853 Bytes
/
2.zote
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
include!("stdlib");
fn at(coll, at) -> coll[at];
fn draws(line) -> {
(game, sets) := line >> split(":");
game = game[5:] >> int;
sets = sets >> split(";");
rounds := [];
for set in sets {
color_count := [0, 0, 0];
for draw in set >> split(",") {
(count, color) := draw >> split(" ");
ind := match color {
"red" -> 0,
"green" -> 1,
"blue" -> 2,
};
color_count[ind] += int(count);
}
color_count >> push(rounds);
}
[game, rounds]
}
read("input")
>> split("\n")
>> map(draws)
>> \draws -> {
// Part 1
draws
>> filter(\(_, rounds) -> rounds >> all(\>> enumerate >> all(\(enum, count) -> count - enum <= 12)))
>> map(head)
>> sum
>> print;
// Part 2
draws
>> map(\(_, rounds) -> [0,1,2] >> map(\ind -> rounds >> map(\>> at(ind)) >> maximum) >> prod)
>> sum
>> print;
};