[Jprogramming] Product and Sum problem (from PE forum)

Raul Miller rauldmiller at gmail.com
Tue Apr 6 00:50:29 HKT 2010


On Mon, Apr 5, 2010 at 12:17 PM, Ian Gorse <unigee at gmail.com> wrote:
> Over at the Project Euler forum a ivan_adrian_k posted a fairly simple question
>
> "Find the only 4-digit integer which the product of its digits is
> equal to the first two digits of the number, and the sum of its digits
> is equal to the last two digits of the number"
>
> He then goes on to say..
> "If you can answer it correctly, can you find all the 5-digit integers
> which has similar property, the product of its digits is equal to the
> first three digits of the number, and the sum of its digits is equal
> to the last two digits of the number?"

Here is how I might tackle that one:

digits=: 10#.inv]
sum=:+/"1 at digits
prd=:*/"1 at digits
sel=: #~   ] = sum + 100 * prd

   sel 1e3}.i.1e4 NB. four digit numbers
   sel 1e4}.i.1e5 NB. five digit numbers

-- 
Raul


More information about the Programming mailing list