This commit is contained in:
nazrin 2024-12-08 21:13:18 +00:00
parent 82272c9761
commit 98276d0854

24
7.jl Normal file
View file

@ -0,0 +1,24 @@
const equations::Vector{Vector{Int}} = [ map(x -> parse(Int, x), split(line, Regex("[:\\s]+"))) for line in readlines("input/7") ]
partOne, partTwo = 0, 0
concat(a::Number, b::Number) = a * 10^ndigits(b) + b
for (target,nums) in Iterators.peel.(equations)
nums = collect(nums)
function testCase(funcs::Tuple, p = 1, sum = 0)::Bool
if p > length(nums)
return (sum == target)
end
return any(testCase(funcs, p+1, fn(sum, nums[p])) for fn in funcs)
end
if testCase((+, *))
global partOne += target
end
if testCase((+, *, concat))
global partTwo += target
end
end
@show partOne, partTwo