diff options
author | J.J <thechairman@thechairman.info> | 2024-05-30 21:47:13 -0400 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2024-05-30 21:47:13 -0400 |
commit | fe088aa5778dcdbaab4dd8d4a7395a91c444b45c (patch) | |
tree | f7cd8214ff7db84fce7101908bec2dd7d9ac4a9a /aoc2023 | |
parent | 87e9ab25ff70e215b537939a4bc23ab101f41dbe (diff) | |
download | gleam_aoc-fe088aa5778dcdbaab4dd8d4a7395a91c444b45c.tar.gz gleam_aoc-fe088aa5778dcdbaab4dd8d4a7395a91c444b45c.zip |
gleam 2019
Diffstat (limited to 'aoc2023')
-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 | ||||
-rw-r--r-- | aoc2023/test/day17/day17_test.gleam | 25 | ||||
-rw-r--r-- | aoc2023/test/day20/day20_test.gleam | 19 | ||||
-rw-r--r-- | aoc2023/test/day21/day21_test.gleam | 38 |
12 files changed, 54 insertions, 130 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), ) } diff --git a/aoc2023/test/day17/day17_test.gleam b/aoc2023/test/day17/day17_test.gleam index c1ebd22..2ce48e2 100644 --- a/aoc2023/test/day17/day17_test.gleam +++ b/aoc2023/test/day17/day17_test.gleam @@ -6,8 +6,8 @@ import day17/solve type Problem1AnswerType = String -type Problem2AnswerType = - String +// type Problem2AnswerType = +// String /// Add examples for part 1 here: /// ```gleam @@ -32,12 +32,12 @@ const part1_examples: List(Example(Problem1AnswerType)) = [ ), ] +// /// ``` +// const part2_examples: List(Example(Problem2AnswerType)) = [] + /// Add examples for part 2 here: /// ```gleam ///const part2_examples: List(Example(Problem2AnswerType)) = [Example("some input", "")] -/// ``` -const part2_examples: List(Example(Problem2AnswerType)) = [] - pub fn part1_test() { part1_examples |> should.not_equal([]) @@ -45,11 +45,10 @@ pub fn part1_test() { solve.part1(example.input) |> should.equal(example.answer) } - -pub fn part2_test() { - part2_examples - |> should.not_equal([]) - use example <- list.map(part2_examples) - solve.part2(example.input) - |> should.equal(example.answer) -} +// pub fn part2_test() { +// part2_examples +// |> should.not_equal([]) +// use example <- list.map(part2_examples) +// solve.part2(example.input) +// |> should.equal(example.answer) +// } diff --git a/aoc2023/test/day20/day20_test.gleam b/aoc2023/test/day20/day20_test.gleam index 92e8afb..9b79b05 100644 --- a/aoc2023/test/day20/day20_test.gleam +++ b/aoc2023/test/day20/day20_test.gleam @@ -33,12 +33,12 @@ output -> ", ), ] +// const part2_examples: List(Example(Problem2AnswerType)) = [] + /// Add examples for part 2 here: /// ```gleam ///const part2_examples: List(Example(Problem2AnswerType)) = [Example("some input", "")] /// ``` -const part2_examples: List(Example(Problem2AnswerType)) = [] - pub fn part1_test() { part1_examples |> should.not_equal([]) @@ -46,11 +46,10 @@ pub fn part1_test() { solve.part1(example.input) |> should.equal(example.answer) } - -pub fn part2_test() { - part2_examples - |> should.not_equal([]) - use example <- list.map(part2_examples) - solve.part2(example.input) - |> should.equal(example.answer) -} +// pub fn part2_test() { +// part2_examples +// |> should.not_equal([]) +// use example <- list.map(part2_examples) +// solve.part2(example.input) +// |> should.equal(example.answer) +// } diff --git a/aoc2023/test/day21/day21_test.gleam b/aoc2023/test/day21/day21_test.gleam deleted file mode 100644 index 5f46808..0000000 --- a/aoc2023/test/day21/day21_test.gleam +++ /dev/null @@ -1,38 +0,0 @@ -import gleam/list -import showtime/tests/should -import adglent.{type Example, Example} -import day21/solve - -type Problem1AnswerType = - String - -type Problem2AnswerType = - String - -/// Add examples for part 1 here: -/// ```gleam -///const part1_examples: List(Example(Problem1AnswerType)) = [Example("some input", "")] -/// ``` -const part1_examples: List(Example(Problem1AnswerType)) = [] - -/// Add examples for part 2 here: -/// ```gleam -///const part2_examples: List(Example(Problem2AnswerType)) = [Example("some input", "")] -/// ``` -const part2_examples: List(Example(Problem2AnswerType)) = [] - -pub fn part1_test() { - part1_examples - |> should.not_equal([]) - use example <- list.map(part1_examples) - solve.part1(example.input) - |> should.equal(example.answer) -} - -pub fn part2_test() { - part2_examples - |> should.not_equal([]) - use example <- list.map(part2_examples) - solve.part2(example.input) - |> should.equal(example.answer) -} |