#!/usr/bin/env setl
--
-- Project Euler problem 34 in SETL
--
--
-- Problem 34
-- """
-- 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
--
-- Find the sum of all numbers which are equal to the sum of the
-- factorial of their digits.
--
-- Note: as 1! = 1 and 2! = 2 are not sums they are not included.
-- """
--
-- This SETL program was created by Hakan Kjellerstrand (hakank@bonetmail.com)
-- Also see my SETL page: http://www.hakank.org/setl/
--
problem34();
proc problem34;
nprint("Problem 34: ");
res:=0;
for n in [10..100000] loop
v := [factorial(val(i)) : i in str(n)];
if n = +/v then
res +:= n;
end if;
end loop;
print(res);
end proc;
proc factorial(n);
if n = 0 then
return 1;
else
return */[ i : i in [1..n]];
end if;
end proc;