[Jprogramming] #: antibase
David Lambert
b49p23tivg at stny.rr.com
Mon Jan 27 08:10:31 UTC 2014
NB. Oh! j implements antibase as
NB. "insert divmod" from right to left.
COINS =: 2 5r2 2 5
Dyad =: [: :
divmod =: foo =: <.@:%~ , |
antibaseJ =: }.@:(((divmod {.) , }.@:])/@:,)"1 0 Dyad
COINS antibaseJ 38
1 1r2 1 3
NB. I had envisioned a left-to-right algorithm
antibaseDWL =: finish@:work@:prepare"1 0 Dyad
moddiv =: | , <.@:%~
prepare =: (,~ (1 , |.@:(*/\.)@:}.))~
work =: ((moddiv {.@:]) , }.@:])/
finish =: |.@:}.
COINS prepare 38
1 5 10 25 38
work 1 5 10 25 38
0 3 0 1 1
finish 0 3 0 1 1
1 1 0 3
COINS antibaseDWL 38
1 1 0 3
> Date: Sat, 25 Jan 2014 21:53:28 -0800
> From: Nollaig MacKenzie<nollaig at amhuinnsuidhe.net>
> To:programming at jsoftware.com
> Subject: Re: [Jprogramming] #: antibase
> Message-ID:<14.026.21208.608936.tQQfz.1101 at amhuinnsuidhe.net>
> Content-Type: text/plain; charset=us-ascii
>
>
> On 2014.01.25 20:33:55, you,
> the extraordinary David Lambert, spake thus:
>
>> > NB. convert 38 cents to pennies, nickels, dimes, quarters.
>> >
>> > 38 #:~ COINS =: |. 1 5 2 5r2 2
>> >1 1r2 1 3 0
>> >
>> > NB. why do I get a half dime and a nickel?
>> >
>> > COINS #. 1 1 0 3 0
>> >38
>> >
> foo=. ((<.@:(%~)),|)
> C=. 2 5r2 2 5
>
>
> 5 foo 38
> 7 3
> 2 foo 7
> 3 1
> 5r2 foo 3
> 1 1r2
> 2 foo 1
> 0 1
>
> and the result of C #: 38 (tracing upward) is 1 1r2 1 3
>
> C#.1 1r2 1 3
> 38
>
>
> -- Nollaig MacKenzie http://www.yorku.ca/nollaig
More information about the Programming
mailing list