Your verb find works well with #: and i. for example (2 find 5) #: i. 5 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0
How well does it work with hcla and i. ? with hcla and i: ? On 12/10/2011 2:16 PM, Linda Alvord wrote: > > find=: 13 :'(+/(y>x^i.21))#x' > find > [ #~ [: +/ ]> (i.20) ^~ [ > 2 find 10000 > 2 2 2 2 2 2 2 2 2 2 2 2 2 2 > $2 find 10000 > 14 > $3 find 10000 > 3 3 3 3 3 3 3 3 3 > $3 find 10000 > 9 > 4 find 10000 > 4 4 4 4 4 4 4 > $4 find 10000 > 7 > 4^7 > 16384 > 3^9 > 19683 > > 2^20 > 1.04858e6 > > This should handle cases up to one million. The left argument is the base > and the right is the maximum number you need convert to the given base. > All bets are off if you have something like 24 60 60 for minutes to days 24 > 60 60 . > > > If I were creating a contest and I could get this far I would include the > concept because I could cobble together an answer. Another day I may do the > same exercise a totally different way. Usually it tends to encourage even > better ways for accomplishing the task. I tend to stay away from remembering > useful code and try to approach the problem anew. I have the luxury of not > having my living dependent upon never having the code break or have it have > some unintended consequences. > > Linda > > > -----Original Message----- > From: programming-boun...@jsoftware.com > [mailto:programming-boun...@jsoftware.com] On Behalf Of Kip Murray > Sent: Saturday, December 10, 2011 10:07 AM > To: Programming forum > Subject: Re: [Jprogramming] How #: should have been designed > > Linda, you may want to look up two's-compliment arithmetic, see > > http://en.wikipedia.org/wiki/Two's_complement > > Your idea in hcla is nice. Can you figure out a way to calculate the > number of 2's required for the left argument? For example you would > need four 2's for > > (2 2 2 2 hcla i: 5) -: hc i: 5 > 1 > > On 12/10/2011 3:56 AM, Linda Alvord wrote: >> Kip, Is this what you are looking for: >> >> >> hcla=: 13 :'x#:y' >> ]d=:2 2 2 hcla i:2 >> 1 1 0 >> 1 1 1 >> 0 0 0 >> 0 0 1 >> 0 1 0 >> >> hcinvla=:hcla^:_1 hcla >> hcinvla d >> |length error: hcinvla >> | hcinvla d >> >> hcla >> #: >> hcinvJ=:#:^:_1 >> hcinvJ >> #:^:_1 >> >> hcinvJ d >> 6 7 0 1 2 >> >> hcinvla >> #. >> hcinvla=: 13 :'#.y' >> hcinvla d >> 6 7 0 1 2 >> >> Raul's new improved answer hc doesn't appear to deal with the negative >> values. My inverse does the best it can with the data it gets. >> >> My code is mostly from the dictionary. I'm not sure what would be the best >> way to deal with negative binary numbers. Maybe I'll remember something >> about that a little later. >> >> Linda >> >> >> -----Original Message----- >> From: programming-boun...@jsoftware.com >> [mailto:programming-boun...@jsoftware.com] On Behalf Of Kip Murray >> Sent: Saturday, December 10, 2011 1:02 AM >> To: Programming forum >> Subject: Re: [Jprogramming] How #: should have been designed >> >> Now we need an inverse for Raul's improved #: ("hash colon") >> >> hc NB. Raul's improved #: >> {.@#:@(,: (2 * |)) >> >> hc i: 2 >> 1 1 0 >> 1 1 1 >> 0 0 0 >> 0 0 1 >> 0 1 0 >> >> hcinv NB. improvement sought >> 2&#.`(2&#.@}. - 2 ^<:@#)@.{."1 >> >> hcinv hc i: 2 >> _2 _1 0 1 2 >> >> On 12/8/2011 2:41 PM, Raul Miller wrote: >> ... >> But this would work just as well, as a model: >> >> {.@#:@(,: 2 * |)i:2 >> 1 1 0 >> 1 1 1 >> 0 0 0 >> 0 0 1 >> 0 1 0 >> ---------------------------------------------------------------------- >> 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