-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path068 Magic 5-gon ring.jl
More file actions
50 lines (41 loc) · 930 Bytes
/
068 Magic 5-gon ring.jl
File metadata and controls
50 lines (41 loc) · 930 Bytes
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
#!/usr/bin/julia
# Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 03 May 2017
# https://github.com/trizen
# https://projecteuler.net/problem=68
# Runtime: 1.532s
using Combinatorics
function isOK(d)
if (
d[1] < d[4] &&
d[1] < d[6] &&
d[1] < d[8] &&
d[1] < d[10]
)
i = d[1] + d[2] + d[3]
j = d[4] + d[3] + d[5]
k = d[6] + d[5] + d[7]
l = d[8] + d[7] + d[9]
m = d[10] + d[9] + d[2]
i == j && i == k &&
i == l && i == m
else
false
end
end
function makeStr(d)
string(d[1],d[2],d[3],d[4],d[3],d[5],d[6],d[5],d[7],d[8],d[7],d[9],d[10],d[9],d[2])
end
function p_68()
max = ""
nums = [i for i = 1:10]
for j in 1:factorial(length(nums))
perm = nthperm(nums, j)
if isOK(perm)
max = maximum([max, makeStr(perm)])
end
end
return max
end
println(p_68())