[Jprogramming] How to box every item
Henry Rich
HenryHRich at nc.rr.com
Thu Oct 3 11:39:27 UTC 2013
or
powerB =: 1 : 0
:
for_i. |. x do. y =. i u y end.
y
)
Untested.
Henry Rich
On 10/3/2013 7:33 AM, Pascal Jasmin wrote:
> Thank you Brian and Dan,
>
> I present a new verb powerupdate (pow) to help with boxscan:
>
> pow =: 1 : (':'; 'u boxscan (<"_1 x), < y')
> pow2=: boxscan(@:(<"_1@:[ , <@:])) NB. tacit version is slower, but allows jibberish interactions with \ et al.
> boxscan =: &.>/(>@:) NB. interacts with \ meaningfully.
>
> pow is a rewrite of this, which may be clearer:
>
> powerA =: 1 : 0
> :
> c =. y
> while. 0<#x do. c =. ({: x) u c
> x =. }: x end.
> c
> )
>
> pow helps rearrange the x and y terms for use with boxscan so that it can be used more naturally to update 'y'
>
> 1 2 3 + pow 0 10
> 6 16
>
> 1 2 3 4 + pow 1 2 3 + pow 0 10
>
> 16 26
>
> 1 2 3 + pow 0 10 is equivalent to:
>
>
> 1 + 2 + 3 + 0 10
>
> On another note, I think my original boxitems has some use:
>
> boxitems =: (<"0)`(<"1)@.(1<#@$)
>
> though the following is writtable using both versions
>
> boxAsRows =: <"_1 L:1 ^:(1 >. <:@#@$)
>
>
> boxAsRows 2 2 2 $ (;~"0 i.8)
> ┌─────────────────────────────┬─────────────────────────────┐
> │┌─────────────┬─────────────┐│┌─────────────┬─────────────┐│
> ││┌─────┬─────┐│┌─────┬─────┐│││┌─────┬─────┐│┌─────┬─────┐││
> │││┌─┬─┐│┌─┬─┐│││┌─┬─┐│┌─┬─┐│││││┌─┬─┐│┌─┬─┐│││┌─┬─┐│┌─┬─┐│││
> ││││0│0│││1│1│││││2│2│││3│3│││││││4│4│││5│5│││││6│6│││7│7││││
> │││└─┴─┘│└─┴─┘│││└─┴─┘│└─┴─┘│││││└─┴─┘│└─┴─┘│││└─┴─┘│└─┴─┘│││
> ││└─────┴─────┘│└─────┴─────┘│││└─────┴─────┘│└─────┴─────┘││
> │└─────────────┴─────────────┘│└─────────────┴─────────────┘│
> └─────────────────────────────┴─────────────────────────────┘
>
> which seems to fit how I like to consume data more than:
>
> <"_1 ] 2 2 2 $ (;~"0 i.8)
> ┌─────┬─────┐
> │┌─┬─┐│┌─┬─┐│
> ││0│0│││4│4││
> │├─┼─┤│├─┼─┤│
> ││1│1│││5│5││
> │└─┴─┘│└─┴─┘│
> │ │ │
> │┌─┬─┐│┌─┬─┐│
> ││2│2│││6│6││
> │├─┼─┤│├─┼─┤│
> ││3│3│││7│7││
> │└─┴─┘│└─┴─┘│
> └─────┴─────┘
>
>
>
>
> ----- Original Message -----
> From: Dan Bron <j at bron.us>
> To: programming at jsoftware.com
> Cc:
> Sent: Wednesday, October 2, 2013 6:12:55 PM
> Subject: Re: [Jprogramming] How to box every item
>
> Pascal Jasmin wrote:
>> If I do not know the shape of items in advance,
>> how would I box each item?
>
> Solution:
>
> boxItems =: < items
>
> boxItems (;~"0 i.5)
>
> +-----+-----+-----+-----+-----+
> |+-+-+|+-+-+|+-+-+|+-+-+|+-+-+|
> ||0|0|||1|1|||2|2|||3|3|||4|4||
> |+-+-+|+-+-+|+-+-+|+-+-+|+-+-+|
> +-----+-----+-----+-----+-----+
>
> The utility "items" is defined in the standard library. You could satisfy your curiosity by just checking out its definition. But can you figure out what it is without peeking? Hint: it's very simple; in fact, it is defined in only two words.
>
> Bigger hint: http://www.jsoftware.com/jwiki/Essays/A%20Fine%20Line
>
> -Dan
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list