From f7b0d5c650d095bcb8f88c5f7e288d6fe5671df4 Mon Sep 17 00:00:00 2001 From: "J.J" Date: Mon, 4 Dec 2023 01:05:19 -0500 Subject: day 4 complete --- aoc2023/src/day4/solve.gleam | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'aoc2023') 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)) { -- cgit v1.2.3