elegance to me is having a one line version so as to avoid running multiple
lines in order.
the first chart is easy
+ table i.11
the basis for the second one is also pretty easy
- table i.10
though you want to clean it of negative values
([: _:^:(0 > ])"0 -/~) i.10
0 _ _ _ _ _ _ _ _ _
1 0 _ _ _ _ _ _ _ _
2 1 0 _ _ _ _ _ _ _
3 2 1 0 _ _ _ _ _ _
4 3 2 1 0 _ _ _ _ _
5 4 3 2 1 0 _ _ _ _
6 5 4 3 2 1 0 _ _ _
7 6 5 4 3 2 1 0 _ _
8 7 6 5 4 3 2 1 0 _
9 8 7 6 5 4 3 2 1 0
to get the formatting, this is actually a small change to the table adverb,
though looks scary
table2 =: 1 : ('(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":y, u y';':';
'(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":x,y u x')
([: _:^:(0 > ])"0 -/~) table2 i.10
┌────────────────────┬───────────────────┐
│[: _:^:(0 > ])"0 -/~│0 1 2 3 4 5 6 7 8 9│
├────────────────────┼───────────────────┤
│0 │0 _ _ _ _ _ _ _ _ _│
│1 │1 0 _ _ _ _ _ _ _ _│
│2 │2 1 0 _ _ _ _ _ _ _│
│3 │3 2 1 0 _ _ _ _ _ _│
│4 │4 3 2 1 0 _ _ _ _ _│
│5 │5 4 3 2 1 0 _ _ _ _│
│6 │6 5 4 3 2 1 0 _ _ _│
│7 │7 6 5 4 3 2 1 0 _ _│
│8 │8 7 6 5 4 3 2 1 0 _│
│9 │9 8 7 6 5 4 3 2 1 0│
└────────────────────┴───────────────────┘
can be called dyadically too:
(i.10) ([: _:^:(0 > ])"0 -/~) table2 4 + i.10
________________________________
From: Linda Alvord <[email protected]>
To: [email protected]
Sent: Sunday, January 4, 2015 11:34 AM
Subject: [Jprogramming] During lulls in the games can you simplify this code?
In the beginning of J TECH Grade 3, I am summarizing the facts that students
should have learned in Grade 2 at the outset.
Addition and Subtraction are a pair of inverse functions. Students learned
addition facts for numbers 0 to 10. The sums range from 0 to 20.
Thus the inverse must include the numbers from 0 - 20 divided by 1 to 10.
You can't divide by 0. Students haven't met negative numbers.
So here's the charts I want. Do you know any ways I could do this more
simply or elegantly?
A=:":((i.20)>:/i.10)*(i.20)-/i.10
B=:(|._3*i.10),10$0
C=:B|.!.' '"0 1 A
D=:(-B)|.!.' '"0 1 C
TOP=: (<' - '),<}.,' ' ,"1":,.>:i.10
BOT=:(<,.>:i.20),<D
]PLUS=:+table i.11
---T--------------------------------┐
│+ │ 0 1 2 3 4 5 6 7 8 9 10│
+--+--------------------------------+
│ 0│ 0 1 2 3 4 5 6 7 8 9 10│
│ 1│ 1 2 3 4 5 6 7 8 9 10 11│
│ 2│ 2 3 4 5 6 7 8 9 10 11 12│
│ 3│ 3 4 5 6 7 8 9 10 11 12 13│
│ 4│ 4 5 6 7 8 9 10 11 12 13 14│
│ 5│ 5 6 7 8 9 10 11 12 13 14 15│
│ 6│ 6 7 8 9 10 11 12 13 14 15 16│
│ 7│ 7 8 9 10 11 12 13 14 15 16 17│
│ 8│ 8 9 10 11 12 13 14 15 16 17 18│
│ 9│ 9 10 11 12 13 14 15 16 17 18 19│
│10│10 11 12 13 14 15 16 17 18 19 20│
L--+---------------------------------
]MINUS=:TOP,:BOT
----T-----------------------------┐
│ - │ 1 2 3 4 5 6 7 8 9 10│
+---+-----------------------------+
│ 1 │ 0 │
│ 2 │ 1 0 │
│ 3 │ 2 1 0 │
│ 4 │ 3 2 1 0 │
│ 5 │ 4 3 2 1 0 │
│ 6 │ 5 4 3 2 1 0 │
│ 7 │ 6 5 4 3 2 1 0 │
│ 8 │ 7 6 5 4 3 2 1 0 │
│ 9 │ 8 7 6 5 4 3 2 1 0 │
│10 │ 9 8 7 6 5 4 3 2 1 0│
│11 │10 9 8 7 6 5 4 3 2 1│
│12 │11 10 9 8 7 6 5 4 3 2│
│13 │12 11 10 9 8 7 6 5 4 3│
│14 │13 12 11 10 9 8 7 6 5 4│
│15 │14 13 12 11 10 9 8 7 6 5│
│16 │15 14 13 12 11 10 9 8 7 6│
│17 │16 15 14 13 12 11 10 9 8 7│
│18 │17 16 15 14 13 12 11 10 9 8│
│19 │18 17 16 15 14 13 12 11 10 9│
│20 │19 18 17 16 15 14 13 12 11 10│
L---+------------------------------
Thanks in advance.
Linda
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm