Day 7
This commit is contained in:
parent
82272c9761
commit
98276d0854
1 changed files with 24 additions and 0 deletions
24
7.jl
Normal file
24
7.jl
Normal 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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue