Hi Rob,

As a hint, I would think about creating all the triples in an array and then 
count the rows. I think (but have not jumped in to do a solution) that J has 
some tools that allow you to create the rows without needing loops.

Hope this helps.

Cheers, bob

On 2013-05-24, at 9:28 AM, Robert Herman wrote:

> I was helping my son with his maths homework, and I thought it would be a
> great chance to utilize J. Here is the problem: Given three sides, x, y and
> z, where x<y<z and a perimeter of 57, with z < 1/2 of the perimeter, how
> many triangles can you make that fit that criteria. Somebody created a perl
> script with nested loops:
> 
> for $x (1..57/2) {
> for $y ($x+1..57/2) {
> for $z ($y+1..57/2) {
> if ($x + $y + $z eq 57) {
> ++$count;
> print "$count: $x $y $z\n";
> }}}}
> print "Total: $count";
> 
> 
> I thought I could start to do it this way in J:
> 
> x =. i..26
> y =. >:x
> z =. >:y
> 
> NB. Here's where I get stuck in trying to do a nested loop in J
> +/" x y z      NB. just to see if I could get it to sum each column
> 
> I am stuck in the world of imperative programming and loops. I'm not
> looking for the solution, but just a hint in which direction to take it.
> I'm still fascinated with J, and hope to grasp array programming. Thank you.
> 
> Rob
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to