diff options
author | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-10-09 11:36:55 -0400 |
commit | 8777ff071f7bb37631baa7b6717ad29961e50911 (patch) | |
tree | 6d59c4ed58e454b960339c3d1151f0a879e8d7cb /aoc2023-gleam/src/day1/solve.gleam | |
parent | 6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff) | |
download | gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip |
sorting by language
Diffstat (limited to 'aoc2023-gleam/src/day1/solve.gleam')
-rw-r--r-- | aoc2023-gleam/src/day1/solve.gleam | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/aoc2023-gleam/src/day1/solve.gleam b/aoc2023-gleam/src/day1/solve.gleam deleted file mode 100644 index 37a19d2..0000000 --- a/aoc2023-gleam/src/day1/solve.gleam +++ /dev/null @@ -1,57 +0,0 @@ -import adglent.{First, Second} -import gleam/io -import gleam/list -import gleam/string -import gleam/regex.{type Match, Match} -import gleam/int - -pub fn part1(input: String) { - let assert Ok(re) = regex.from_string("[1-9]") - - input - |> string.split("\n") - |> 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 - }) - |> string.inspect -} - -const substitutions = [ - #("one", "o1e"), - #("two", "t2o"), - #("three", "t3e"), - #("four", "4"), - #("five", "5e"), - #("six", "6"), - #("seven", "7n"), - #("eight", "e8t"), - #("nine", "n9e"), -] - -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) - }) - |> part1 -} - -pub fn main() { - let assert Ok(part) = adglent.get_part() - let assert Ok(input) = adglent.get_input("1") - case part { - First -> - part1(input) - |> adglent.inspect - |> io.println - Second -> - part2(input) - |> adglent.inspect - |> io.println - } -} |