···
import simplifile as file
13
-
pub type InputEntry {
14
-
InputEntry(direction: Direction, turn: Int)
RotationState(number: Int, zeroes: Int)
···
29
-
let #(direction, turn) = case l {
30
-
"R" <> turn -> #(Right, turn)
31
-
"L" <> turn -> #(Left, turn)
21
+
"R" <> turn -> turn |> int.parse |> result.unwrap(0)
22
+
"L" <> turn -> 0 - { turn |> int.parse |> result.unwrap(0) }
_ -> panic as "bad input"
34
-
InputEntry(direction, turn |> int.parse |> result.unwrap(0))
|> list.fold(RotationState(50, 0), fn(acc, v) {
43
-
+ case v.direction {
31
+
int.modulo(acc.number + v, 100)
33
+
RotationState(new_number, case new_number {
···
|> list.fold(RotationState(50, 0), fn(acc, v) {
67
-
let raw_new_number =
69
-
+ case v.direction {
45
+
let raw_new_number = acc.number + v
46
+
let new_number = int.modulo(raw_new_number, 100) |> result.unwrap(0)
47
+
let times_it_went_zero = {
48
+
let value = int.absolute_value(raw_new_number / 100)
49
+
case acc.number != 0, raw_new_number > 0 {
50
+
True, False -> value + 1
73
-
// took too long to remember that abs isn't this im so fucking stupid
74
-
let new_number = int.modulo(raw_new_number, 100) |> result.unwrap(0)
75
-
// dumbest fuck in the world??? theres gotta be a mathy way of doing this
76
-
let times_it_went_zero =
77
-
list.range(acc.number, raw_new_number)
78
-
|> list.fold(0, fn(acc2, i) {
80
-
0 if i != acc.number -> acc2 + 1
RotationState(new_number, acc.zeroes + times_it_went_zero)