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