aboutsummaryrefslogtreecommitdiff
path: root/aoc2023
diff options
context:
space:
mode:
authorJ.J <thechairman@thechairman.info>2023-12-01 17:58:13 -0500
committerJ.J <thechairman@thechairman.info>2023-12-01 17:58:13 -0500
commitf648264a1a91f93f1643163339d52968f1c7bec9 (patch)
treedc6f771818b0b8fca3c54d82834115d689e79e79 /aoc2023
parenta75aa83cefb27b7684afb8f3e74f4dc199f0dcff (diff)
downloadgleam_aoc-f648264a1a91f93f1643163339d52968f1c7bec9.tar.gz
gleam_aoc-f648264a1a91f93f1643163339d52968f1c7bec9.zip
day 1 improvements
Diffstat (limited to 'aoc2023')
-rw-r--r--aoc2023/adglent_cheatsheet.md3
-rw-r--r--aoc2023/src/day1/solve.gleam9
2 files changed, 6 insertions, 6 deletions
diff --git a/aoc2023/adglent_cheatsheet.md b/aoc2023/adglent_cheatsheet.md
new file mode 100644
index 0000000..4061e1b
--- /dev/null
+++ b/aoc2023/adglent_cheatsheet.md
@@ -0,0 +1,3 @@
+Set up a solution: `gleam run -m adglent/day <n>`
+Check against examples: `gleam test -- --modules=day<n>/day<n>_test`
+Get final answer: `gleam run -m day<n>/solve <p>` \ No newline at end of file
diff --git a/aoc2023/src/day1/solve.gleam b/aoc2023/src/day1/solve.gleam
index b9a6588..29322ce 100644
--- a/aoc2023/src/day1/solve.gleam
+++ b/aoc2023/src/day1/solve.gleam
@@ -3,7 +3,6 @@ import gleam/io
import gleam/list
import gleam/string
import gleam/regex.{type Match, Match}
-import gleam/result
import gleam/int
fn parse_digits(input: String) {
@@ -11,21 +10,19 @@ fn parse_digits(input: String) {
input
|> string.split("\n")
- |> list.map(fn(s) {
+ |> 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)
-
- int.parse(first <> last)
+ let assert Ok(i) = int.parse(first <> last)
+ acc + i
})
}
pub fn part1(input: String) {
input
|> parse_digits
- |> result.values
- |> int.sum
|> string.inspect
}