Nice Raul, thank you.

Your toVint is 10x faster than mine.

my less pretty fromVint

fromVbyte=: [: +/&> (255 &>) (<;.2) ]

The neat part of the challenge is seeing how dyadic ;. is frequently an elegant 
alternative to "I might need a loop for this"

Your use of #: to make records (rows) is quite cool too.

I also didn't know that u&, could combine operations on rows into a list.


----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc: 
Sent: Monday, December 29, 2014 12:44 PM
Subject: Re: [Jprogramming] variable integer coding (challenge)

Here's a faster version of toVint, for at least some right arguments:

toVint2=: [: (({."1 ,. 1:) #&, 255 ,. {:"1) 0 255 #: ]

Here's an implementation of fromVint:

fromVint=: 255&~: +/;.2 ]

Thanks,

-- 
Raul



On Mon, Dec 29, 2014 at 12:12 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> A common design decision is how large to make a field.  For many numbers, we 
> think that a byte will be large enough to hold practical values, but one day 
> we will find out that it is not.  This is essentially the Y2k problem, or 
> year 2032 issue.
>
> A simple variable integer coding (tied to byte ranges)
>
> toVint =: [: ; (255&| ,~ 255 #~ <.@%&255) each
>
>   toVint 566 44
> 255 255 56 44
>
> It now takes 3 bytes to store 566, and one byte to store 44.
>
> the challenge is to write fromVint such that
>
>
> 566 44 -: fromVint 255 255 56 44
>
> as an extra challenge, is there a way to write toVint or fromVint such that 
> it is faster than using intermediate boxing?
> ----------------------------------------------------------------------
> 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

Reply via email to