From 11c881603c875b220762f8276dbd3fedc8b5fcb1 Mon Sep 17 00:00:00 2001 From: Alexander Seiler Date: Mon, 4 Dec 2023 19:46:28 +0100 Subject: [PATCH] [Day 4] Simplify --- src/day04.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/day04.jl b/src/day04.jl index aa9686e..30cc592 100644 --- a/src/day04.jl +++ b/src/day04.jl @@ -24,10 +24,7 @@ eval_points(nwins::Int) = nwins > 0 ? 2^(nwins - 1) : 0 function part2(winning_numbers::Vector{Vector{Int}}, my_numbers::Vector{Vector{Int}}) ncards = ones(Int, length(winning_numbers)) for (i, (w, m)) ∈ enumerate(zip(winning_numbers, my_numbers)) - ncommon = length(intersect(w, m)) - for k = i+1:i+ncommon - ncards[k] += ncards[i] - end + ncards[i+1:i+length(intersect(w, m))] .+= ncards[i] end return ncards |> sum end