On Fri, Jan 7, 2011 at 7:28 AM, Justin Paston-Cooper
<[email protected]> wrote:
> Dear All,
>
> I've been trying to do the problem written at
> http://projecteuler.net/index.php?section=problems&id=5 . The problem
> is to find the smallest positive number divisible by all of the
> numbers from 1 to 20. My solution is as follows:
>
> $:@>:^:(+./@:(0&~:@((1 + i. 20)&|))) 1
>
> On the page, it says that the smallest number divisible by all of the
> numbers up to 10 is 2520, which my solution rightly finds when one
> substitutes the 20 for 10. When running it with 20, I get a stack
> error. Could anyone tell me how to get around this with my current
> solution? How about some smarter solutions?

Since this is projecteuler, I am going to try to stay away
from showing you how to solve the problem, and will
instead focus on techniques for characterizing your
current code.

If I replace $: with $:@([smoutput) I see that you
are passing to the function a sequence of numbers,
2 through 2520.

But instead of passing all of them to your function,
you are passing them in one by one.

But, J allows you to pass in a sequence of numbers,
and operate on all of them, and then you can
further manipulate that result.

... but that would be just a brute force approach and
does not really deal with how I would solve this
problem.  So, as a further hint: you do not need to
deal with any numbers larger than 20, other than
your final answer, when solving this problem.

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

Reply via email to