-
Notifications
You must be signed in to change notification settings - Fork 7
/
4.jl
58 lines (53 loc) · 1.24 KB
/
4.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
bingos = []
scores = []
deleteBingos = []
function removeValue(val)
for bingo in bingos
for i in eachindex(bingo)
if bingo[i] == val
bingo[i] = 0
end
end
end
end
function checkComplete(num)
rows = [0 0 0 0 0]
cols = [0 0 0 0 0]
for (i, bingo) in enumerate(bingos)
if any(x -> x == 0, [sum(bingo, dims=1)..., sum(bingo, dims=2)...])
s = sum(bingo) - sum((x -> x != 0).(bingo))
push!(scores, s * (num - 1))
push!(deleteBingos, i)
end
end
return -1
end
function main()
toInt(x) = parse(Int, x)
lines = readlines()
drawn = toInt.(split(lines[1], ",")) .+ 1
y = 1
for line in lines[2:end]
ints = toInt.(split(line)) .+ 1
if line == ""
push!(bingos, zeros(Int, (5, 5)))
y = 1
continue
end
for i in eachindex(ints)
bingos[end][y, i] = ints[i]
end
y += 1
end
for num in drawn
removeValue(num)
checkComplete(num)
for i in reverse(deleteBingos)
deleteat!(bingos, i)
end
empty!(deleteBingos)
end
println(scores[1])
println(scores[end])
end
main()