On Mon, Apr 5, 2010 at 12:17 PM, Ian Gorse <[email protected]> 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...@digits
prd=:*/"1...@digits
sel=: #~   ] = sum + 100 * prd

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

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to