diff options
Diffstat (limited to 'aoc2023/src')
-rw-r--r-- | aoc2023/src/day1/solve.gleam | 29 | ||||
-rw-r--r-- | aoc2023/src/day12/solve.gleam | 5 | ||||
-rw-r--r-- | aoc2023/src/day13/solve.gleam | 5 | ||||
-rw-r--r-- | aoc2023/src/day14/solve.gleam | 3 | ||||
-rw-r--r-- | aoc2023/src/day2/solve.gleam | 7 | ||||
-rw-r--r-- | aoc2023/src/day21/.gitignore | 1 | ||||
-rw-r--r-- | aoc2023/src/day21/solve.gleam | 25 | ||||
-rw-r--r-- | aoc2023/src/day5/solve.gleam | 23 | ||||
-rw-r--r-- | aoc2023/src/utilities/prioqueue.gleam | 4 |
9 files changed, 33 insertions, 69 deletions
diff --git a/aoc2023/src/day1/solve.gleam b/aoc2023/src/day1/solve.gleam index ed14bde..37a19d2 100644 --- a/aoc2023/src/day1/solve.gleam +++ b/aoc2023/src/day1/solve.gleam @@ -10,17 +10,14 @@ pub fn part1(input: String) { input |> string.split("\n") - |> list.fold( - 0, - fn(acc, s) { - let matches = regex.scan(s, with: re) + |> list.fold(0, fn(acc, s) { + let matches = regex.scan(s, with: re) - let assert Ok(Match(content: first, ..)) = list.first(matches) - let assert Ok(Match(content: last, ..)) = list.last(matches) - let assert Ok(i) = int.parse(first <> last) - acc + i - }, - ) + let assert Ok(Match(content: first, ..)) = list.first(matches) + let assert Ok(Match(content: last, ..)) = list.last(matches) + let assert Ok(i) = int.parse(first <> last) + acc + i + }) |> string.inspect } @@ -37,14 +34,10 @@ const substitutions = [ ] pub fn part2(input: String) { - list.fold( - over: substitutions, - from: input, - with: fn(acc, sub) { - let #(from, to) = sub - string.replace(in: acc, each: from, with: to) - }, - ) + list.fold(over: substitutions, from: input, with: fn(acc, sub) { + let #(from, to) = sub + string.replace(in: acc, each: from, with: to) + }) |> part1 } diff --git a/aoc2023/src/day12/solve.gleam b/aoc2023/src/day12/solve.gleam index 06c7098..893b83c 100644 --- a/aoc2023/src/day12/solve.gleam +++ b/aoc2023/src/day12/solve.gleam @@ -41,9 +41,8 @@ fn do_count( case template, groups, left, gap { "", [], 0, _ -> 1 "?" <> t_rest, [g, ..g_rest], 0, False -> - do_count(t_rest, g_rest, g - 1, g == 1, cache) + { - do_count(t_rest, groups, 0, False, cache) - } + do_count(t_rest, g_rest, g - 1, g == 1, cache) + + do_count(t_rest, groups, 0, False, cache) "?" <> t_rest, [], 0, False | "?" <> t_rest, _, 0, True | "." <> t_rest, _, 0, _ -> do_count(t_rest, groups, 0, False, cache) diff --git a/aoc2023/src/day13/solve.gleam b/aoc2023/src/day13/solve.gleam index 2b3fca2..6f9b9a0 100644 --- a/aoc2023/src/day13/solve.gleam +++ b/aoc2023/src/day13/solve.gleam @@ -43,10 +43,11 @@ fn get_symmetry_type(xss: List(List(String)), errors: Int) { fn summarize_notes(symmetries: List(SymmetryType)) { use acc, note <- list.fold(symmetries, 0) - case note { + acc + + case note { Horizontal(n) -> 100 * n Vertical(n) -> n - } + acc + } } fn solve(input: String, errors: Int) { diff --git a/aoc2023/src/day14/solve.gleam b/aoc2023/src/day14/solve.gleam index 1ad1a18..ecc5361 100644 --- a/aoc2023/src/day14/solve.gleam +++ b/aoc2023/src/day14/solve.gleam @@ -23,7 +23,8 @@ fn roll_boulders(strs: List(String)) { fn score(matrix) { use acc, col <- list.fold(matrix, 0) - acc + { + acc + + { use col_acc, char, n <- list.index_fold(list.reverse(col), 0) case char { "O" -> col_acc + n + 1 diff --git a/aoc2023/src/day2/solve.gleam b/aoc2023/src/day2/solve.gleam index 38e62d7..608955f 100644 --- a/aoc2023/src/day2/solve.gleam +++ b/aoc2023/src/day2/solve.gleam @@ -45,10 +45,9 @@ pub fn part2(input: String) { green: int.max(green, acc.green), ) } - |> list.fold( - from: 0, - with: fn(acc, g: Game) { acc + g.red * g.blue * g.green }, - ) + |> list.fold(from: 0, with: fn(acc, g: Game) { + acc + g.red * g.blue * g.green + }) } pub fn main() { diff --git a/aoc2023/src/day21/.gitignore b/aoc2023/src/day21/.gitignore deleted file mode 100644 index ae40cea..0000000 --- a/aoc2023/src/day21/.gitignore +++ /dev/null @@ -1 +0,0 @@ -input.txt
\ No newline at end of file diff --git a/aoc2023/src/day21/solve.gleam b/aoc2023/src/day21/solve.gleam deleted file mode 100644 index 4d5c246..0000000 --- a/aoc2023/src/day21/solve.gleam +++ /dev/null @@ -1,25 +0,0 @@ -import adglent.{First, Second} -import gleam/io - -pub fn part1(input: String) { - todo as "Implement solution to part 1" -} - -pub fn part2(input: String) { - todo as "Implement solution to part 2" -} - -pub fn main() { - let assert Ok(part) = adglent.get_part() - let assert Ok(input) = adglent.get_input("21") - case part { - First -> - part1(input) - |> adglent.inspect - |> io.println - Second -> - part2(input) - |> adglent.inspect - |> io.println - } -} diff --git a/aoc2023/src/day5/solve.gleam b/aoc2023/src/day5/solve.gleam index 58e2ae0..7c05310 100644 --- a/aoc2023/src/day5/solve.gleam +++ b/aoc2023/src/day5/solve.gleam @@ -132,22 +132,17 @@ fn do_remap_range(r: SeedRange, mapper: Mapper, acc: List(SeedRange)) { ] // range overlaps end but not start -> left side transformed, right side moves to next mapping [m, ..ms] if r.start >= m.start && r.end > m.end -> - do_remap_range( - SRange(m.end + 1, r.end), - ms, - [transform_range(SRange(r.start, m.end), m), ..acc], - ) + do_remap_range(SRange(m.end + 1, r.end), ms, [ + transform_range(SRange(r.start, m.end), m), + ..acc + ]) // mapping is fully inside range -> left not transformed, middle transformed, right to next [m, ..ms] -> - do_remap_range( - SRange(m.end + 1, r.end), - ms, - [ - SRange(r.start, m.start - 1), - transform_range(SRange(m.start, m.end), m), - ..acc - ], - ) + do_remap_range(SRange(m.end + 1, r.end), ms, [ + SRange(r.start, m.start - 1), + transform_range(SRange(m.start, m.end), m), + ..acc + ]) } } diff --git a/aoc2023/src/utilities/prioqueue.gleam b/aoc2023/src/utilities/prioqueue.gleam index 640748b..abf21b9 100644 --- a/aoc2023/src/utilities/prioqueue.gleam +++ b/aoc2023/src/utilities/prioqueue.gleam @@ -42,7 +42,9 @@ pub fn insert( queue.refs |> dict.insert(value, ref) - PriorityQueue(refs: refs, queue: insert_(#(value, ref), priority, queue.queue), + PriorityQueue( + refs: refs, + queue: insert_(#(value, ref), priority, queue.queue), ) } |