-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoC2015_04.jl
59 lines (47 loc) · 1020 Bytes
/
AoC2015_04.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env julia
#
include("aoc_main.jl")
if abspath(PROGRAM_FILE) == @__FILE__
include("aocd.jl")
using .Aocd
end
module AoC2015_04
include("aoc.jl")
using MD5
function checkZeroes(digest, zeroes)
chars = zeroes ÷ 2 + zeroes % 2
cnt = 0
for j ∈ 1:chars
ch::UInt8 = digest[j][1]
if (ch & 0xF0) == 0
cnt += 1
if (ch & 0x0F) == 0
cnt += 1
continue
end
end
break
end
return cnt == zeroes
end
function solve(input, zeroes)
i = 1
while true
checkZeroes(md5(input * string(i)), zeroes) && return i
i += 1
end
end
function part1(input)
return solve(input[1], 5)
end
function part2(input)
return solve(input[1], 6)
end
TEST1 = @aoc_splitlines("abcdef")
TEST2 = @aoc_splitlines("pqrstuv")
function samples()
@assert part1(TEST1) == 609_043
@assert part1(TEST2) == 1_048_970
end
end # module AoC2015_04
aoc_main(@__FILE__, ARGS, 2015, 4)