diff --git a/7.jl b/7.jl new file mode 100644 index 0000000..ad76aa5 --- /dev/null +++ b/7.jl @@ -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 +