The following shows one way J does loops

http://www.jsoftware.com/docs/help701/dictionary/cfor.htm

I found this by going to

http://www.jsoftware.com/docs/help701/dictionary/vocabul.htm

and clicking on Controls, then paging using the >> in upper left corner.

--Kip Murray

Sent from my iPad


On May 24, 2013, at 11:28 AM, Robert Herman <[email protected]> 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