You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB
Julia

using Base
using DataStructures
found = Dict{Int, Array{Int64}}()
function count_nz(seq)
return length([i for i in seq if i > 0])
end
for i1 in 0:32
for i2 in i1:32
for i3 in i2:32
for i4 in i3:32
s = i1 ^ 2 + i2 ^ 2 + i3 ^ 2 + i4 ^ 2
if s <= 1000
seq = [ i1, i2, i3, i4 ]
# if !haskey(found, s)
# found[s] = seq
# end
if haskey(found, s)
s_prev = found[s]
if count_nz(seq) < count_nz(s_prev)
found[s] = seq
end
else
found[s] = seq
end
end
end
end
end
end
found = sort(found)
delete!(found, 0)
# for i = 1:1000
# if haskey(found, i)
# print("x")
# else
# print("_")
# end
# end
for (sum, seq) in found
println("$(join(["$(i)^2" for i in seq if i > 0], " + ")) = $(sum)")
end
# println(length([k for (k, v) in found if length([i for i in v if i != 0]) == 4]))