From 7213ca083d121bb9e6876d2ddb4b25ee09d954bb Mon Sep 17 00:00:00 2001 From: "J.J" Date: Sun, 17 Dec 2023 20:33:33 -0500 Subject: running updated gleam formatter --- aoc2023/src/day15/solve.gleam | 14 +++++++------- aoc2023/src/day17/solve.gleam | 24 ++++++++++++++++++++++++ aoc2023/src/day2/solve.gleam | 7 ++++--- aoc2023/src/day5/solve.gleam | 23 ++++++++++++++--------- aoc2023/src/utilities/array2d.gleam | 6 ++++++ 5 files changed, 55 insertions(+), 19 deletions(-) (limited to 'aoc2023') diff --git a/aoc2023/src/day15/solve.gleam b/aoc2023/src/day15/solve.gleam index 2d863b5..a7d250c 100644 --- a/aoc2023/src/day15/solve.gleam +++ b/aoc2023/src/day15/solve.gleam @@ -12,13 +12,13 @@ fn split(input: String) -> List(String) { } fn hash_algorithm(str: String) -> Int { - str - |> string.to_utf_codepoints() - |> list.map(string.utf_codepoint_to_int) - |> list.fold(0, fn(acc, c) { - let assert Ok(acc) = int.modulo({ acc + c } * 17, 256) - acc - }) + let codepoints = + str + |> string.to_utf_codepoints() + |> list.map(string.utf_codepoint_to_int) + use acc, c <- list.fold(codepoints, 0) + let assert Ok(acc) = int.modulo({ acc + c } * 17, 256) + acc } pub fn part1(input: String) -> String { diff --git a/aoc2023/src/day17/solve.gleam b/aoc2023/src/day17/solve.gleam index 5289ce9..3ed632c 100644 --- a/aoc2023/src/day17/solve.gleam +++ b/aoc2023/src/day17/solve.gleam @@ -1,5 +1,29 @@ import adglent.{First, Second} import gleam/io +import utilities/array2d.{type Posn, Posn} + +type Direction { + North + South + East + West +} + +fn turn_dirs(dir: Direction) { + case dir { + North | South -> [East, West] + East | West -> [North, South] + } +} + +fn delta(dir: Direction) { + case dir { + North -> Posn(-1, 0) + South -> Posn(1, 0) + East -> Posn(0, 1) + West -> Posn(0, -1) + } +} pub fn part1(input: String) { todo as "Implement solution to part 1" diff --git a/aoc2023/src/day2/solve.gleam b/aoc2023/src/day2/solve.gleam index 608955f..38e62d7 100644 --- a/aoc2023/src/day2/solve.gleam +++ b/aoc2023/src/day2/solve.gleam @@ -45,9 +45,10 @@ 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/day5/solve.gleam b/aoc2023/src/day5/solve.gleam index 7c05310..58e2ae0 100644 --- a/aoc2023/src/day5/solve.gleam +++ b/aoc2023/src/day5/solve.gleam @@ -132,17 +132,22 @@ 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/array2d.gleam b/aoc2023/src/utilities/array2d.gleam index d7d05f8..83ec8ae 100644 --- a/aoc2023/src/utilities/array2d.gleam +++ b/aoc2023/src/utilities/array2d.gleam @@ -9,6 +9,12 @@ pub type Posn { pub type Array2D(a) = Dict(Posn, a) +pub fn add_posns(p1: Posn, p2: Posn) -> Posn { + case p1, p2 { + Posn(r1, c1), Posn(r2, c2) -> Posn(r1 + r2, c1 + c2) + } +} + pub fn to_2d_array(xss: List(List(a))) -> Array2D(a) { { use r, row <- list.index_map(xss) -- cgit v1.2.3 From 9f0d9e4de0e6a69b9770b227f669af75667b8c90 Mon Sep 17 00:00:00 2001 From: "J.J" Date: Sun, 17 Dec 2023 20:34:12 -0500 Subject: running updated gleam format --- aoc2023/test/day15/day15_test.gleam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'aoc2023') diff --git a/aoc2023/test/day15/day15_test.gleam b/aoc2023/test/day15/day15_test.gleam index 83fadef..0ecaecc 100644 --- a/aoc2023/test/day15/day15_test.gleam +++ b/aoc2023/test/day15/day15_test.gleam @@ -22,7 +22,7 @@ const part1_examples: List(Example(Problem1AnswerType)) = [ ///const part2_examples: List(Example(Problem2AnswerType)) = [Example("some input", "")] /// ``` const part2_examples: List(Example(Problem2AnswerType)) = [ - Example("rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7", "145"), + Example("rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7", "145"), ] pub fn part1_test() { -- cgit v1.2.3