aboutsummaryrefslogtreecommitdiff
path: root/aoc2017-gleam/src/aoc_2017/day_17.gleam
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2017-gleam/src/aoc_2017/day_17.gleam
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'aoc2017-gleam/src/aoc_2017/day_17.gleam')
-rw-r--r--aoc2017-gleam/src/aoc_2017/day_17.gleam55
1 files changed, 0 insertions, 55 deletions
diff --git a/aoc2017-gleam/src/aoc_2017/day_17.gleam b/aoc2017-gleam/src/aoc_2017/day_17.gleam
deleted file mode 100644
index 5904cab..0000000
--- a/aoc2017-gleam/src/aoc_2017/day_17.gleam
+++ /dev/null
@@ -1,55 +0,0 @@
-import gleam/int
-import gleam/list
-import glearray
-
-pub fn parse(input: String) {
- let assert Ok(n) = int.parse(input)
- n
-}
-
-pub fn pt_1(input: Int) {
- let assert [_, result] =
- next_spin([0], 0, 1, input)
- |> list.drop_while(fn(x) { x != 2017 })
- |> list.take(2)
-
- result
-}
-
-fn next_spin(list: List(Int), position: Int, cycle: Int, step: Int) {
- case cycle {
- 2018 -> list
- _ -> {
- let next_position = { position + step } % cycle + 1
- next_spin(
- insert_at(list, next_position, cycle),
- next_position,
- cycle + 1,
- step,
- )
- }
- }
-}
-
-fn insert_at(xs: List(a), at index: Int, insert new: a) {
- let #(left, right) = list.split(xs, index)
- list.concat([left, [new], right])
-}
-
-pub fn pt_2(input: Int) {
- next_spin_tracking_zero(0, 0, 1, input)
-}
-
-fn next_spin_tracking_zero(acc: Int, position: Int, cycle: Int, step: Int) {
- case cycle {
- 50_000_001 -> acc
- _ -> {
- let next_position = { position + step } % cycle + 1
- let next_acc = case next_position {
- 1 -> cycle
- _ -> acc
- }
- next_spin_tracking_zero(next_acc, next_position, cycle + 1, step)
- }
- }
-}