This is impressive. I really want to be able to use two different lists as arguments.
(i.21) * postable >:i.10 Would meet the domain for subtraction in Grade 2. However your function has great potential as a way to eliminate results that are beyond the scope of a function. Nice! Linda -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of robert therriault Sent: Monday, January 5, 2015 4:01 PM To: [email protected] Subject: Re: [Jprogramming] During lulls in the games can you simplify this code? Here is what I came up with: pt=:((#~ (j.~ -.)) }:@;@:((# # 0 > {.)&.>)@:(<;.2)@(1 ,~ +/@(1 _1 * ' _' =/ ])))"1 sr=:#"1~ -.@}:@;@:((] = #)&.>)@:(<;.1)@(*./@(' ' =/ ' ' ,. ])) postable=: 1 : (':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.) sr pt ":x,y u/x')~ * postable i: 5 ┌──┬─────────────────────────────┐ │* │ 0 1 2 3 4 5│ ├──┼─────────────────────────────┤ │_5│25 20 15 10 5 0 │ │_4│20 16 12 8 4 0 │ │_3│15 12 9 6 3 0 │ │_2│10 8 6 4 2 0 │ │_1│ 5 4 3 2 1 0 │ │ 0│ 0 0 0 0 0 0 0 0 0 0 0│ │ 1│ 0 1 2 3 4 5│ │ 2│ 0 2 4 6 8 10│ │ 3│ 0 3 6 9 12 15│ │ 4│ 0 4 8 12 16 20│ │ 5│ 0 5 10 15 20 25│ └──┴─────────────────────────────┘ * postable _1 3 4 _3 2 ┌──┬───────────┐ │* │ 3 4 2│ ├──┼───────────┤ │_1│1 3 │ │ 3│ 9 12 6│ │ 4│ 12 16 8│ │_3│3 9 │ │ 2│ 6 8 4│ └──┴───────────┘ I find it a bit bizarre not having the negative values across the top, but the formatting get silly with removing spaces and negative numbers. This second version is a bit closer but still has the formatting issues with the top axis. postable2=: 1 : (':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.) (":x),sr pt ":y u/x')~ * postable2 i:5 ┌──┬─────────────────────────────┐ │* │_5 _4 _3 _2 _1 0 1 2 3 4 5 │ ├──┼─────────────────────────────┤ │_5│25 20 15 10 5 0 │ │_4│20 16 12 8 4 0 │ │_3│15 12 9 6 3 0 │ │_2│10 8 6 4 2 0 │ │_1│ 5 4 3 2 1 0 │ │ 0│ 0 0 0 0 0 0 0 0 0 0 0│ │ 1│ 0 1 2 3 4 5│ │ 2│ 0 2 4 6 8 10│ │ 3│ 0 3 6 9 12 15│ │ 4│ 0 4 8 12 16 20│ │ 5│ 0 5 10 15 20 25│ └──┴─────────────────────────────┘ * postable2 _1 3 4 _3 2 ┌──┬───────────┐ │* │_1 3 4 _3 2│ ├──┼───────────┤ │_1│1 3 │ │ 3│ 9 12 6│ │ 4│ 12 16 8│ │_3│3 9 │ │ 2│ 6 8 4│ └──┴───────────┘ Anyway enough time on that. I did like the (#~ (j.~ -.)) in pt and the (] = #) in sr was fun as well. The whole thing felt pretty brute force though. Cheers, bob On Jan 4, 2015, at 8:53 PM, Raul Miller <[email protected]> wrote: > postable=:adverb define > : > neg=. ~.(#~ 0&>),x u/ y > clean=: rplc&(,(;' '"0)&":&>neg)"1 L:0 clean x u table y > ) > > * postable~ i: 4 > ┌──┬─────────────────────────────┐ > │* │ 0 1 2 3 4│ > ├──┼─────────────────────────────┤ > │_4│ 16 12 8 4 0 │ > │_3│ 12 9 6 3 0 │ > │_2│ 8 6 4 2 0 │ > │_1│ 4 3 2 1 0 │ > │ 0│ 0 0 0 0 0 0 0 0 0│ > │ 1│ 0 1 2 3 4│ > │ 2│ 0 2 4 6 8│ > │ 3│ 0 3 6 9 12│ > │ 4│ 0 4 8 12 16│ > └──┴─────────────────────────────┘ > > I still feel like this is overkill, but maybe this is an acceptable > "leave the negative part blank" implementation? > > That said, if you don't like the extra spaces, you could so something > like Pascal's "first force all the values to the same value" > technique. I have been avoiding that because going that route means > you can't really use the 'table' adverb, but if you don't mind > re-implementing table that approach lets you be fussier about some of the > spacing possibilities. > > Thanks, > > -- > Raul > > On Sun, Jan 4, 2015 at 9:33 PM, robert therriault > <[email protected]> > wrote: > >> No, I was thinking something more positive than that :) >> >> Something that would take an array with negatives >> >> 3 6 4 >> 12 _2 10 >> _3 0 _4 >> >> and remove them completely to display this >> >> 3 6 4 >> 12 10 >> 0 >> >> Still haven't done it though. >> >> Cheers, bob >> >> On Jan 4, 2015, at 1:24 PM, Raul Miller <[email protected]> wrote: >> >>> Like this? >>> >>> negatives=:adverb define >>> : >>> ~.(#~ 0&>),x u/ y >>> ) >>> >>> (1+i.20) -negatives 1+i.10 >>> _1 _2 _3 _4 _5 _6 _7 _8 _9 >>> >>> Seems like overkill, for this task, since the the point of this >>> exercise is, I expect, building the groundwork for introducing negative >>> numbers. >>> >>> -- >>> Raul >>> >>> On Sun, Jan 4, 2015 at 2:54 PM, robert therriault >>> <[email protected] >>> >>> wrote: >>> >>>> Linda, >>>> >>>> What are these games you speak of? (just kidding, Go 'Hawks - oh >>>> yeah that's next week) >>>> >>>> After a long and circuitous route that I won't go into, and with >>>> the benefit of Raul and Pascal's responses, I came up with this: >>>> >>>> postable=:1 : (':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)(#~ >>>> -.@(+./\@(''_''=])))"1@":x,y u/x')~ >>>> (i.21)- postable i.11 >>>> ┌──┬─────────────────────────────────┐ >>>> │- │ 0 1 2 3 4 5 6 7 8 9 10│ >>>> ├──┼─────────────────────────────────┤ >>>> │ 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 │ >>>> │10│10 9 8 7 6 5 4 3 2 1 0│ >>>> │11│11 10 9 8 7 6 5 4 3 2 1│ >>>> │12│12 11 10 9 8 7 6 5 4 3 2│ >>>> │13│13 12 11 10 9 8 7 6 5 4 3│ >>>> │14│14 13 12 11 10 9 8 7 6 5 4│ >>>> │15│15 14 13 12 11 10 9 8 7 6 5│ >>>> │16│16 15 14 13 12 11 10 9 8 7 6│ >>>> │17│17 16 15 14 13 12 11 10 9 8 7│ >>>> │18│18 17 16 15 14 13 12 11 10 9 8│ >>>> │19│19 18 17 16 15 14 13 12 11 10 9│ >>>> │20│20 19 18 17 16 15 14 13 12 11 10│ >>>> └──┴─────────────────────────────────┘ >>>> table >>>> 1 : (':'; '(((#~LF-.@e.])5!:5<''u'');,.y),.({.;}.)":x,y u/x')~ >>>> (i.21)- table i.11 >>>> ┌──┬─────────────────────────────────┐ >>>> │- │ 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 0 _1 _2 _3 _4 _5 _6 >>>> _7 _8 _9│ │ 2│ 2 1 0 _1 _2 _3 _4 _5 _6 _7 _8│ │ 3│ 3 2 1 0 >>>> _1 _2 _3 _4 _5 _6 _7│ │ 4│ 4 3 2 1 0 _1 _2 _3 _4 _5 _6│ │ 5│ >>>> 5 4 3 2 1 0 _1 _2 _3 _4 _5│ │ 6│ 6 5 4 3 2 1 0 _1 _2 _3 >>>> _4│ │ 7│ 7 6 5 4 3 2 1 0 _1 _2 _3│ │ 8│ 8 7 6 5 4 3 2 >>>> 1 0 _1 _2│ │ 9│ 9 8 7 6 5 4 3 2 1 0 _1│ >>>> │10│10 9 8 7 6 5 4 3 2 1 0│ >>>> │11│11 10 9 8 7 6 5 4 3 2 1│ >>>> │12│12 11 10 9 8 7 6 5 4 3 2│ >>>> │13│13 12 11 10 9 8 7 6 5 4 3│ >>>> │14│14 13 12 11 10 9 8 7 6 5 4│ >>>> │15│15 14 13 12 11 10 9 8 7 6 5│ >>>> │16│16 15 14 13 12 11 10 9 8 7 6│ >>>> │17│17 16 15 14 13 12 11 10 9 8 7│ >>>> │18│18 17 16 15 14 13 12 11 10 9 8│ >>>> │19│19 18 17 16 15 14 13 12 11 10 9│ >>>> │20│20 19 18 17 16 15 14 13 12 11 10│ >>>> └──┴─────────────────────────────────┘ >>>> >>>> postable differs from table in one significant way. After the >>>> results of the table have been formatted, it uses (#~ >>>> -.@(+./\@(''_''=])))"1 to >> clean >>>> them (double quotes needed around '_' because it is sitting inside >>>> of an adverb declaration string). What this fragment does is to >>>> look for instances of '_' in each line and then replaces the rest >>>> of the line >> with >>>> blanks. This works as long as the negative values are contiguous - >>>> I am still looking at the general case of cherry picking negative >>>> values >> where >>>> ever they exist. If I get a way to do that I'll post, although my >>>> guess >> is >>>> that others will probably solve it first. >>>> >>>> Cheers, bob >>>> >>>> >>>> On Jan 4, 2015, at 10:10 AM, 'Pascal Jasmin' via Programming < >>>> [email protected]> wrote: >>>> >>>>> 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 >>>> >>>> ------------------------------------------------------------------- >>>> --- For information about J forums see >>>> http://www.jsoftware.com/forums.htm >>>> >>> -------------------------------------------------------------------- >>> -- For information about J forums see >>> http://www.jsoftware.com/forums.htm >> >> --------------------------------------------------------------------- >> - For information about J forums see >> http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
