aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ.J <thechairman@thechairman.info>2023-12-04 01:05:19 -0500
committerJ.J <thechairman@thechairman.info>2023-12-04 01:05:19 -0500
commitf7b0d5c650d095bcb8f88c5f7e288d6fe5671df4 (patch)
treecc29eeff6f74e69eeea3c98396aba9f517a5c10d
parent039df9d6e00dc5a4c8d5b66b28dc216d6ee0a2f5 (diff)
downloadgleam_aoc-f7b0d5c650d095bcb8f88c5f7e288d6fe5671df4.tar.gz
gleam_aoc-f7b0d5c650d095bcb8f88c5f7e288d6fe5671df4.zip
day 4 complete
-rw-r--r--aoc2023/src/day4/solve.gleam33
1 files changed, 11 insertions, 22 deletions
diff --git a/aoc2023/src/day4/solve.gleam b/aoc2023/src/day4/solve.gleam
index 98b4d82..eab700b 100644
--- a/aoc2023/src/day4/solve.gleam
+++ b/aoc2023/src/day4/solve.gleam
@@ -41,31 +41,20 @@ fn win_points(n) {
}
fn count_wins(card: Card) {
- list.fold(
- card.has,
- 0,
- fn(acc, c) {
- case list.contains(card.winning, c) {
- True -> acc + 1
- False -> acc
- }
- },
- )
+ use acc, c <- list.fold(card.has, 0)
+ case list.contains(card.winning, c) {
+ True -> acc + 1
+ False -> acc
+ }
}
pub fn part1(input: String) {
- input
- |> string.split("\n")
- |> list.fold(
- 0,
- fn(acc, c) {
- c
- |> parse_card
- |> count_wins
- |> win_points
- |> int.add(acc)
- },
- )
+ use acc, c <- list.fold(string.split(input, "\n"), 0)
+ c
+ |> parse_card
+ |> count_wins
+ |> win_points
+ |> int.add(acc)
}
fn win_more_cards(cards: List(String), card_count: dict.Dict(Int, Int)) {