In [2]:
using Random
Random.seed!(42)
"Andi Kerstin Chris Caro Jana" |> split |> shuffle |> x -> join(x," → ")
Out[2]:
"Andi → Chris → Caro → Kerstin → Jana"
In [3]:
using DelimitedFiles
[ Info: Precompiling DelimitedFiles [8bb1440f-4735-579b-a4ab-409b98df4dab]
In [40]:
rules=readdlm("input", '|')[1:1176,:]
Out[40]:
1176×2 Matrix{Any}:
57 24
64 37
64 45
19 47
19 45
19 95
98 57
98 37
98 34
98 87
96 87
96 74
96 37
⋮
22 62
22 97
93 55
93 75
93 47
93 48
44 78
44 27
44 99
81 54
81 19
87 64
In [39]:
data=readdlm("input", ',')[1177:end,:]
Out[39]:
223×23 Matrix{Any}:
13 19 52 14 65 96 62 98 … "" "" "" "" "" ""
26 11 93 84 95 45 63 89 "" "" "" "" "" ""
97 57 95 26 73 34 81 91 "" "" "" "" "" ""
74 91 42 62 87 27 53 98 26 34 "" "" "" ""
87 55 94 65 91 98 44 14 "" "" "" "" "" ""
26 95 84 93 68 48 35 76 … 69 65 14 52 13 22
67 91 62 92 64 37 19 26 "" "" "" "" "" ""
95 38 94 89 69 13 44 "" "" "" "" "" "" ""
76 47 38 11 94 24 89 55 98 73 81 87 "" ""
19 97 92 64 57 74 37 63 38 11 "" "" "" ""
74 62 37 67 92 38 34 57 … "" "" "" "" "" ""
65 42 58 73 97 92 53 54 "" "" "" "" "" ""
87 91 58 53 99 62 19 97 "" "" "" "" "" ""
⋮ ⋮ ⋱ ⋮
73 89 13 44 14 47 76 75 94 81 96 98 "" ""
84 93 48 76 45 47 38 11 22 44 "" "" "" ""
97 54 87 19 91 75 69 99 "" "" "" "" "" ""
24 69 87 78 55 13 58 22 "" "" "" "" "" ""
62 19 74 27 95 84 38 "" … "" "" "" "" "" ""
58 99 62 54 97 92 64 57 48 76 "" "" "" ""
14 13 22 87 42 58 53 62 "" "" "" "" "" ""
48 97 26 38 84 34 27 63 45 68 "" "" "" ""
27 69 75 76 12 95 47 68 14 34 24 48 "" ""
87 52 55 14 13 47 94 24 … 98 73 75 22 12 44
52 13 73 87 91 54 19 97 "" "" "" "" "" ""
34 67 27 95 84 93 48 45 "" "" "" "" "" ""
In [46]:
data2 = Vector{Vector{Int64}}(undef, 223)
for i in 1:223
data2[i] = data[i, typeof.(data[i, :]) .== Int64]
end
data = data2
Out[46]:
223-element Vector{Vector{Int64}}:
[13, 19, 52, 14, 65, 96, 62, 98, 58, 73, 97, 92, 91, 87, 44, 54, 42]
[26, 11, 93, 84, 95, 45, 63, 89, 27, 65, 55]
[97, 57, 95, 26, 73, 34, 81, 91, 54, 64, 74]
[74, 91, 42, 62, 87, 27, 53, 98, 81, 92, 97, 99, 54, 63, 57, 67, 96, 26, 34]
[87, 55, 94, 65, 91, 98, 44, 14, 69, 78, 75, 47, 45, 89, 81]
[26, 95, 84, 93, 68, 48, 35, 76, 47, 38 … 89, 55, 12, 75, 69, 65, 14, 52, 13, 22]
[67, 91, 62, 92, 64, 37, 19, 26, 58, 81, 54, 96, 98]
[95, 38, 94, 89, 69, 13, 44]
[76, 47, 38, 11, 94, 24, 89, 55, 12, 75 … 65, 14, 13, 22, 78, 96, 98, 73, 81, 87]
[19, 97, 92, 64, 57, 74, 37, 63, 67, 27, 26, 95, 84, 93, 68, 48, 45, 38, 11]
[74, 62, 37, 67, 92, 38, 34, 57, 93]
[65, 42, 58, 73, 97, 92, 53, 54, 87, 57, 22, 98, 78, 81, 52, 96, 14]
[87, 91, 58, 53, 99, 62, 19, 97, 64, 74, 37, 63, 34, 67, 95, 93, 68]
⋮
[73, 89, 13, 44, 14, 47, 76, 75, 65, 45 … 52, 24, 69, 78, 35, 11, 94, 81, 96, 98]
[84, 93, 48, 76, 45, 47, 38, 11, 94, 24, 89, 55, 12, 69, 65, 14, 13, 22, 44]
[97, 54, 87, 19, 91, 75, 69, 99, 52, 96, 12, 13, 73, 62, 65]
[24, 69, 87, 78, 55, 13, 58, 22, 11, 96, 12, 65, 52, 89, 38]
[62, 19, 74, 27, 95, 84, 38]
[58, 99, 62, 54, 97, 92, 64, 57, 74, 63, 34, 67, 27, 95, 84, 93, 68, 48, 76]
[14, 13, 22, 87, 42, 58, 53, 62, 54, 97, 92, 57, 74]
[48, 97, 26, 38, 84, 34, 27, 63, 94, 95, 57, 93, 76, 35, 64, 37, 19, 45, 68]
[27, 69, 75, 76, 12, 95, 47, 68, 67, 45 … 55, 38, 35, 93, 94, 84, 14, 34, 24, 48]
[87, 52, 55, 14, 13, 47, 94, 24, 69, 65 … 45, 38, 89, 81, 98, 73, 75, 22, 12, 44]
[52, 13, 73, 87, 91, 54, 19, 97, 37]
[34, 67, 27, 95, 84, 93, 48, 45, 38, 11, 94, 12, 75, 65, 14]
In [60]:
filtered = Vector{Vector{Int64}}()
for list in data
passed = true
for row in 1:size(rules)[1]
if !(rules[row,1] in list && rules[row,2] in list)
continue
end
pos1 = findfirst(list .== rules[row, 1])
pos2 = findfirst(list .== rules[row, 2])
if pos1 > pos2
passed = false
break
end
end
if passed
push!(filtered, list)
end
end
In [74]:
count = 0
for list in filtered
count += list[Int(length(list)/2 +0.5)]
end
count
Out[74]:
6505
In [0]: