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 | |
parent | 87e9ab25ff70e215b537939a4bc23ab101f41dbe (diff) | |
download | gleam_aoc-fe088aa5778dcdbaab4dd8d4a7395a91c444b45c.tar.gz gleam_aoc-fe088aa5778dcdbaab4dd8d4a7395a91c444b45c.zip |
gleam 2019
-rw-r--r-- | .gitignore | 1 | ||||
m--------- | adglent | 0 | ||||
-rw-r--r-- | aoc2019-gleam/.github/workflows/test.yml | 23 | ||||
-rw-r--r-- | aoc2019-gleam/.gitignore | 6 | ||||
-rw-r--r-- | aoc2019-gleam/README.md | 25 | ||||
-rw-r--r-- | aoc2019-gleam/gleam.toml | 21 | ||||
-rw-r--r-- | aoc2019-gleam/manifest.toml | 34 | ||||
-rw-r--r-- | aoc2019-gleam/src/aoc2019_gleam.gleam | 5 | ||||
-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 |
20 files changed, 169 insertions, 130 deletions
@@ -5,3 +5,4 @@ compiled/* input .clj-kondo/* .lsp/* +adglent/* diff --git a/adglent b/adglent new file mode 160000 +Subproject 7cb051cf2f588582ee32861a84aa46e5d4dc979 diff --git a/aoc2019-gleam/.github/workflows/test.yml b/aoc2019-gleam/.github/workflows/test.yml new file mode 100644 index 0000000..dd5e246 --- /dev/null +++ b/aoc2019-gleam/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: test + +on: + push: + branches: + - master + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: "26.0.2" + gleam-version: "1.2.0" + rebar3-version: "3" + # elixir-version: "1.15.4" + - run: gleam deps download + - run: gleam test + - run: gleam format --check src test diff --git a/aoc2019-gleam/.gitignore b/aoc2019-gleam/.gitignore new file mode 100644 index 0000000..a98602e --- /dev/null +++ b/aoc2019-gleam/.gitignore @@ -0,0 +1,6 @@ +*.beam +*.ez +/build +erl_crash.dump + +aoc.toml
\ No newline at end of file diff --git a/aoc2019-gleam/README.md b/aoc2019-gleam/README.md new file mode 100644 index 0000000..bbf8121 --- /dev/null +++ b/aoc2019-gleam/README.md @@ -0,0 +1,25 @@ +# aoc2019_gleam + +[](https://hex.pm/packages/aoc2019_gleam) +[](https://hexdocs.pm/aoc2019_gleam/) + +```sh +gleam add aoc2019_gleam +``` +```gleam +import aoc2019_gleam + +pub fn main() { + // TODO: An example of the project in use +} +``` + +Further documentation can be found at <https://hexdocs.pm/aoc2019_gleam>. + +## Development + +```sh +gleam run # Run the project +gleam test # Run the tests +gleam shell # Run an Erlang shell +``` diff --git a/aoc2019-gleam/gleam.toml b/aoc2019-gleam/gleam.toml new file mode 100644 index 0000000..36967f2 --- /dev/null +++ b/aoc2019-gleam/gleam.toml @@ -0,0 +1,21 @@ +name = "aoc2019_gleam" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_stdlib = ">= 0.36.0 and < 2.0.0" +startest = ">= 0.2.0 and < 1.0.0" + +[dev-dependencies] +gleeunit = ">= 1.0.0 and < 2.0.0" +adglent = { path = "../adglent"} diff --git a/aoc2019-gleam/manifest.toml b/aoc2019-gleam/manifest.toml new file mode 100644 index 0000000..af970a1 --- /dev/null +++ b/aoc2019-gleam/manifest.toml @@ -0,0 +1,34 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "adglent", version = "1.2.0", build_tools = ["gleam"], requirements = ["gap", "gleam_community_ansi", "gleam_erlang", "gleam_http", "gleam_httpc", "gleam_otp", "gleam_stdlib", "glint", "simplifile", "snag", "tom"], source = "local", path = "../adglent" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "birl", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "B1FA529E7BE3FF12CADF32814AB8EC7294E74CEDEE8CC734505707B929A98985" }, + { name = "exception", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "exception", source = "hex", outer_checksum = "F5580D584F16A20B7FCDCABF9E9BE9A2C1F6AC4F9176FA6DD0B63E3B20D450AA" }, + { name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" }, + { name = "gap", version = "1.1.3", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_stdlib"], otp_app = "gap", source = "hex", outer_checksum = "6EF5E3B523FDFBC317E9EA28D5163EE04744A97C007106F90207569789612291" }, + { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" }, + { name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" }, + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "gleam_http", version = "3.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8C07DF9DF8CC7F054C650839A51C30A7D3C26482AC241C899C1CEA86B22DBE51" }, + { name = "gleam_httpc", version = "2.2.0", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "CF76C71002DEECF6DC5D9CA83D962728FAE166B57926BE442D827004D3C7DF1B" }, + { name = "gleam_javascript", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "14D5B7E1A70681E0776BF0A0357F575B822167960C844D3D3FA114D3A75F05A8" }, + { name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" }, + { name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" }, + { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, + { name = "glint", version = "0.18.1", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "5FB54D7732B4105E4AF4D89A7EE6D5E8CF33DA13A3575D0C6ECE470B97958454" }, + { name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" }, + { name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" }, + { name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" }, + { name = "startest", version = "0.2.0", build_tools = ["gleam"], requirements = ["argv", "birl", "exception", "gleam_community_ansi", "gleam_erlang", "gleam_javascript", "gleam_stdlib", "glint", "simplifile", "tom"], otp_app = "startest", source = "hex", outer_checksum = "89F8575C91696D1713075F0B850A54160A32580A7CF415E045A0EEAD498AA30D" }, + { name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" }, + { name = "tom", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0831C73E45405A2153091226BF98FB485ED16376988602CC01A5FD086B82D577" }, +] + +[requirements] +adglent = { path = "../adglent" } +gleam_stdlib = { version = ">= 0.36.0 and < 2.0.0" } +gleeunit = { version = ">= 1.0.0 and < 2.0.0" } +startest = { version = ">= 0.2.0 and < 1.0.0"} diff --git a/aoc2019-gleam/src/aoc2019_gleam.gleam b/aoc2019-gleam/src/aoc2019_gleam.gleam new file mode 100644 index 0000000..3ab0f4c --- /dev/null +++ b/aoc2019-gleam/src/aoc2019_gleam.gleam @@ -0,0 +1,5 @@ +import gleam/io + +pub fn main() { + io.println("Hello from aoc2019_gleam!") +} 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) -} |