/*
Euler #6 in Picat.
Problem 6
"""
The sum of the squares of the first ten natural numbers is,
1^(2) + 2^(2) + ... + 10^(2) = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^(2) = 55^(2) = 3025
Hence the difference between the sum of the squares of the first ten
natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one
hundred natural numbers and the square of the sum.
"""
This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
main => time(go).
go => euler6.
euler6 =>
writeln(sum(1..100)**2 - sum([I**2:I in 1..100])).
euler6b =>
List1 = [], List2 = [],
foreach(I in 1..100)
List1 := [I**2|List1],
List2 := [I|List2]
end,
Diff = sum(List2)**2 - sum(List1),
writeln(Diff).
pow2(N) = N**2.
euler6c =>
writeln(sum(1..100)**2 - sum(map(pow2,1..100))).
euler6d =>
e6d(S),
println(S).
e6d(Sum) =>
e6d(1,0,0,Sum).
e6d(N,S,T,Sum) ?=>
N > 100,
Sum = T**2 - S.
e6d(N,S,T,Sum) =>
S2 = S + N**2,
T2 = T + N,
e6d(N+1,S2,T2,Sum).