···
import simplifile as file
-
InputEntry(direction: Direction, turn: Int)
RotationState(number: Int, zeroes: Int)
···
-
let #(direction, turn) = case l {
-
"R" <> turn -> #(Right, turn)
-
"L" <> turn -> #(Left, turn)
_ -> panic as "bad input"
-
InputEntry(direction, turn |> int.parse |> result.unwrap(0))
|> list.fold(RotationState(50, 0), fn(acc, v) {
···
|> list.fold(RotationState(50, 0), fn(acc, v) {
-
// took too long to remember that abs isn't this im so fucking stupid
-
let new_number = int.modulo(raw_new_number, 100) |> result.unwrap(0)
-
// dumbest fuck in the world??? theres gotta be a mathy way of doing this
-
let times_it_went_zero =
-
list.range(acc.number, raw_new_number)
-
|> list.fold(0, fn(acc2, i) {
-
0 if i != acc.number -> acc2 + 1
RotationState(new_number, acc.zeroes + times_it_went_zero)
···
import simplifile as file
RotationState(number: Int, zeroes: Int)
···
+
"R" <> turn -> turn |> int.parse |> result.unwrap(0)
+
"L" <> turn -> 0 - { turn |> int.parse |> result.unwrap(0) }
_ -> panic as "bad input"
|> list.fold(RotationState(50, 0), fn(acc, v) {
+
int.modulo(acc.number + v, 100)
+
RotationState(new_number, case new_number {
···
|> list.fold(RotationState(50, 0), fn(acc, v) {
+
let raw_new_number = acc.number + v
+
let new_number = int.modulo(raw_new_number, 100) |> result.unwrap(0)
+
let times_it_went_zero = {
+
let value = int.absolute_value(raw_new_number / 100)
+
case acc.number != 0, raw_new_number > 0 {
+
True, False -> value + 1
RotationState(new_number, acc.zeroes + times_it_went_zero)