+43
day1/day1.gleam
+43
day1/day1.gleam
···
1
+
import gleam/bit_array
2
+
import gleam/int
3
+
import gleam/list
4
+
import gleam/result
5
+
import gleam/string
6
+
import simplifile
7
+
8
+
pub fn main() {
9
+
let assert Ok(raw_input) = simplifile.read("src/day1/test.txt")
10
+
11
+
let input =
12
+
raw_input
13
+
|> string.trim
14
+
|> string.split("\n")
15
+
16
+
input
17
+
|> list.fold(#(50, 0), fn(acc, x) {
18
+
case x {
19
+
"L" <> n -> {
20
+
do_the_thing(n, acc, fn(a, b) { a - b })
21
+
}
22
+
"R" <> n -> {
23
+
do_the_thing(n, acc, fn(a, b) { a + b })
24
+
}
25
+
_ -> panic as "what the helly"
26
+
}
27
+
})
28
+
|> echo as "Part 1"
29
+
}
30
+
31
+
fn do_the_thing(
32
+
amount: String,
33
+
state: #(Int, Int),
34
+
operation: fn(Int, Int) -> Int,
35
+
) -> #(Int, Int) {
36
+
let assert Ok(n) = int.parse(amount)
37
+
let assert Ok(num) = operation(state.0, n) |> int.modulo(100)
38
+
let password = case num {
39
+
0 -> state.1 + 1
40
+
_ -> state.1
41
+
}
42
+
#(num, password)
43
+
}