#!/usr/bin/env setl
--
-- Project Euler problem 32 in SETL
--
-- Problem 32
-- """
-- We shall say that an n-digit number is pandigital if it makes use of
-- all the digits 1 to n exactly once; for example, the 5-digit number,
-- 15234, is 1 through 5 pandigital.
--
-- The product 7254 is unusual, as the identity, 39 × 186 = 7254,
-- containing multiplicand, multiplier, and product is 1 through 9
-- pandigital.
--
-- Find the sum of all products whose multiplicand/multiplier/product
-- identity can be written as a 1 through 9 pandigital.
-- HINT: Some products can be obtained in more than one way so be sure
-- to only include it once in your sum.
-- """
--
-- This SETL program was created by Hakan Kjellerstrand (hakank@bonetmail.com)
-- Also see my SETL page: http://www.hakank.org/setl/
--
problem32();
--
-- A very straightforward approach
proc problem32;
sum := 0;
prodhash := {};
for a in [2..98] loop
for b in [a+1..9876] loop
prod := a*b;
ll := str(a) + str(b) + str(prod);
if #ll = 9 and "0" notin ll then
hash := {val(i) : i in str(ll)};
if #hash = 9 and prodhash(prod)=om then
print("a:",a, "b:",b, "prod:", prod, "ll:", ll);
sum +:= prod;
prodhash(prod) := 1;
end if;
end if;
end loop;
end loop;
print(sum);
end proc;