In one of my old APL files I came across this example of the parallel between English and APL/J with respect to unparenthesised expressions. Here it is, in case you haven't seen it before.

The following problem was clipped from the newspaper (probably the Globe and Mail).

------------------------------------------ FUN WITH FIGURES by J.A.H.Hunter "When Helen is one year older than Sally was when Helen was half as old as Sally was when Helen was a third as old as Sally is now, Sally will be twice as old as Helen will be when Sally is twice as old as Helen is now.

One of them is in her teens, and of course we have taken ages in complete years.

How old do you make them?"
------------------------------------------
The sentence has the structure: (L,R) where (translating):
L = (-H)+1+S+(-H)+1r2*S+(-H)+1r3*S
R = (-S)+2*H+(-S)+2*H
and the comma implies that L=R.

The point is that the "right-to-left" rule in APL/J allows simple translation from the unparenthesized English.

===========================
Solutions of the problem are given by the zeros of the following function:

f =: 4 : 0 "0 0
H =. x [  S =. y
((-H)+1+S+(-H)+1r2*S+(-H)+1r3*S) -  (-S)+2*H+(-S)+2*H
)

Solution:
  I =: i.100

  100 100 #: I.  ,0 = I f/ I
10 18
38 69

The first row gives the solution if one of the girls is in her teens:
Helen is 10, Sally is 18.



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

Reply via email to