Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #24895 > unrolled thread

Bijective basechanger

Started byjonas.thornvall@gmail.com
First post2014-06-17 06:42 -0700
Last post2014-07-22 12:16 -0700
Articles 20 on this page of 60 — 6 participants

Back to article view | Back to comp.lang.javascript


Contents

  Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 06:42 -0700
    Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-17 12:08 -0700
      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 13:23 -0700
        Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 13:24 -0700
        Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-17 13:54 -0700
          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 14:07 -0700
            Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 14:15 -0700
              Re: Bijective basechanger John Harris <niam@jghnorth.org.uk.invalid> - 2014-06-23 17:23 +0100
          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 14:23 -0700
          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-17 14:41 -0700
            Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-17 20:28 -0700
              Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 13:04 -0700
                Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-18 16:30 -0700
                  Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 17:45 -0700
                    Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 17:49 -0700
                    Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-19 11:21 -0700
                      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-19 14:44 -0700
                        Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-19 14:48 -0700
                      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-19 14:55 -0700
                        Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-19 19:59 -0700
                          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-21 09:25 -0700
                          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-21 11:15 -0700
                  Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 18:05 -0700
                    Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 18:19 -0700
                      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 18:25 -0700
                    Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-18 18:46 -0700
              Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-23 16:00 -0700
                Re: Bijective basechanger "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-23 17:51 -0700
    Re: Bijective basechanger John Harris <niam@jghnorth.org.uk.invalid> - 2014-06-23 17:18 +0100
      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-23 11:27 -0700
    Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-23 15:29 -0700
      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 03:26 -0700
        Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 03:28 -0700
        Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 04:24 -0700
          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 05:36 -0700
          Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-24 13:05 -0700
            Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 14:13 -0700
              Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-25 05:36 -0700
              Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-25 12:45 -0700
                Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-25 13:15 -0700
                  Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-01 02:39 -0700
                    Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-07-03 07:33 -0700
                      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-03 09:54 -0700
                      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-04 02:14 -0700
                        Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-07-05 12:12 -0700
                          Re: Bijective basechanger "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-05 22:19 +0200
                            Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-07-05 13:50 -0700
                          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-06 11:11 -0700
                            Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-06 14:59 -0700
                              Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-06 15:00 -0700
                              Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-06 15:02 -0700
                          Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-16 23:31 -0700
                      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-07-04 02:28 -0700
                        Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-07-05 12:14 -0700
            Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-25 22:38 -0700
      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 03:32 -0700
      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 03:44 -0700
      Re: Bijective basechanger jonas.thornvall@gmail.com - 2014-06-24 11:10 -0700
        Re: Bijective basechanger Scott Sauyet <scott.sauyet@gmail.com> - 2014-06-24 11:45 -0700
    Re: Bijective basechanger "Chris M. Thomasson" <no@spam.invalid> - 2014-07-22 12:16 -0700

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#24957

Fromjonas.thornvall@gmail.com
Date2014-06-21 09:25 -0700
Message-ID<832e6f25-66a4-45e9-856a-b8a58b42f02b@googlegroups.com>
In reply to#24951
Den fredagen den 20:e juni 2014 kl. 04:59:18 UTC+2 skrev Michael Haufe (TNO):
> On Thursday, June 19, 2014 4:55:20 PM UTC-5, jonas.t...@gmail.com wrote:
> 
> 
> 
> > And your bijective/zeroless HEX encoding only have 15 unique numerals.
> 
> 
> 
> You're correct. The alphabet for base k should be of magnitude k

I've decided to go for a topdown approach starting with the biggest, i think i am pretty close just have to solve the case for the last two digits.

Since computer really do not handle alfabeth as numbers i decided to go for a commaseparated decimal tuple approach not pairs because base can be bigger then 99 ;D

But it is easy convert the max val to an alfanumeric, but i really have no idea how higher bases then sixteen really expressed? Should one use alphanumeric upto base 16, or go upto z for higer bases?

I know base 64 have been used widely but how is it expressed?

[toc] | [prev] | [next] | [standalone]


#24958

Fromjonas.thornvall@gmail.com
Date2014-06-21 11:15 -0700
Message-ID<e4e7d1c9-8303-42d4-8299-705913097af2@googlegroups.com>
In reply to#24951
Den fredagen den 20:e juni 2014 kl. 04:59:18 UTC+2 skrev Michael Haufe (TNO):
> On Thursday, June 19, 2014 4:55:20 PM UTC-5, jonas.t...@gmail.com wrote:
> 
> 
> 
> > And your bijective/zeroless HEX encoding only have 15 unique numerals.
> 
> 
> 
> You're correct. The alphabet for base k should be of magnitude k

The numbersystem seem to lead to nested cases with while and if loops like ir eally do not like to program, i am almost there but i do not like what i see.

Looking at the mumbers it seem we can break them down, breaking lose the numbers with following zeros?

10097000123401

100,9,700,123,40,1

9A,9,69A,123,3A,1

9A969A1233A1

Is that correct?

[toc] | [prev] | [next] | [standalone]


#24939

Fromjonas.thornvall@gmail.com
Date2014-06-18 18:05 -0700
Message-ID<b32df68c-6409-4cee-a8f0-4ba4ce910f9e@googlegroups.com>
In reply to#24932
Den torsdagen den 19:e juni 2014 kl. 01:37:24 UTC+2 skrev Stefan Ram:
> "Michael Haufe (TNO)" <tno@thenewobjective.com> writes:
> 
> >On Wednesday, June 18, 2014 3:04:08 PM UTC-5, jonas.t...@gmail.com wrote:
> 
> >>Isn't it just A8AA1A134; convert each (non-leading) 0 into
> 
> >>an A and subtract one from the number to its left, iterating
> 
> >>if necessary? 
> 
> >>Simple and elegant.
> 
> >It makes an assumption about the base used which makes me
> 
> >skeptical of its applicability beyond this specific case. 
> 
> 
> 
>   The observation of the person you quote could possibly be
> 
>   correct. But nothing is �simple and elegant� unless it has
> 
>   actually become manifest as JavaScript source code that can
> 
>   be executed under a common modern implementation and pass
> 
>   some tests. (If the solution is really so �simple�, then
> 
>   writing this should be simple!) Here are some test cases:
> 
> 
> 
> 1 A
> 
> 26 Z
> 
> 27 AA
> 
> 99 CU
> 
> 100 CV
> 
> 101 CW
> 
> 701 ZY
> 
> 702 ZZ
> 
> 703 AAA
> 
> 704 AAB
> 
> 99997 EQXA
> 
> 99998 EQXB

Stefan would you please use the hex notation like my example, so that 10 equals A, 11 equal B and so on.

Is that base 26? 
ZZ=26*26+26=702

As an extended hex
10=A
11=B
12=C
13=D
14=E
15=F
16=G
17=H
18=I
19=J
20=K
21=L
22=M
23=N
24=O
25=P
26=Q

Or coma separated digit pairs work also good.

[toc] | [prev] | [next] | [standalone]


#24940

Fromjonas.thornvall@gmail.com
Date2014-06-18 18:19 -0700
Message-ID<5c01b6fc-07d5-42ff-b451-af1d01768161@googlegroups.com>
In reply to#24939
Den torsdagen den 19:e juni 2014 kl. 03:05:28 UTC+2 skrev jonas.t...@gmail.com:
> Den torsdagen den 19:e juni 2014 kl. 01:37:24 UTC+2 skrev Stefan Ram:
> 
> > "Michael Haufe (TNO)" <tno@thenewobjective.com> writes:
> 
> > 
> 
> > >On Wednesday, June 18, 2014 3:04:08 PM UTC-5, jonas.t...@gmail.com wrote:
> 
> > 
> 
> > >>Isn't it just A8AA1A134; convert each (non-leading) 0 into
> 
> > 
> 
> > >>an A and subtract one from the number to its left, iterating
> 
> > 
> 
> > >>if necessary? 
> 
> > 
> 
> > >>Simple and elegant.
> 
> > 
> 
> > >It makes an assumption about the base used which makes me
> 
> > 
> 
> > >skeptical of its applicability beyond this specific case. 
> 
> > 
> 
> > 
> 
> > 
> 
> >   The observation of the person you quote could possibly be
> 
> > 
> 
> >   correct. But nothing is �simple and elegant� unless it has
> 
> > 
> 
> >   actually become manifest as JavaScript source code that can
> 
> > 
> 
> >   be executed under a common modern implementation and pass
> 
> > 
> 
> >   some tests. (If the solution is really so �simple�, then
> 
> > 
> 
> >   writing this should be simple!) Here are some test cases:
> 
> > 
> 
> > 
> 
> > 
> 
> > 1 A
> 
> > 
> 
> > 26 Z
> 
> > 
> 
> > 27 AA
> 
> > 
> 
> > 99 CU
> 
> > 
> 
> > 100 CV
> 
> > 
> 
> > 101 CW
> 
> > 
> 
> > 701 ZY
> 
> > 
> 
> > 702 ZZ
> 
> > 
> 
> > 703 AAA
> 
> > 
> 
> > 704 AAB
> 
> > 
> 
> > 99997 EQXA
> 
> > 
> 
> > 99998 EQXB
> 
> 
> 
> Stefan would you please use the hex notation like my example, so that 10 equals A, 11 equal B and so on.
> 
> 
> 
> Is that base 26? 
> 
> ZZ=26*26+26=702
> 
> 
> 
> As an extended hex
> 
> 10=A
> 
> 11=B
> 
> 12=C
> 
> 13=D
> 
> 14=E
> 
> 15=F
> 
> 16=G
> 
> 17=H
> 
> 18=I
> 
> 19=J
> 
> 20=K
> 
> 21=L
> 
> 22=M
> 
> 23=N
> 
> 24=O
> 
> 25=P
> 
> 26=Q
> 
> 
> 
> Or coma separated digit pairs work also good.
Just to be a bit annoying not about JavaScript but about our casual experience and notion of numbers i want to say there is NOT a single 0 in 
10,100,1000,10 000... 
And so on numbers are really sets of elements that we can arrange geometrically. 

A^1, A^2, A^3, A^4 and there is not a single zero in sight. 

[toc] | [prev] | [next] | [standalone]


#24941

Fromjonas.thornvall@gmail.com
Date2014-06-18 18:25 -0700
Message-ID<178ea025-ac87-4aec-a3f1-5d76104c99e7@googlegroups.com>
In reply to#24940
Den torsdagen den 19:e juni 2014 kl. 03:19:54 UTC+2 skrev jonas.t...@gmail.com:
> Den torsdagen den 19:e juni 2014 kl. 03:05:28 UTC+2 skrev jonas.t...@gmail.com:
> 
> > Den torsdagen den 19:e juni 2014 kl. 01:37:24 UTC+2 skrev Stefan Ram:
> 
> > 
> 
> > > "Michael Haufe (TNO)" <tno@thenewobjective.com> writes:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >On Wednesday, June 18, 2014 3:04:08 PM UTC-5, jonas.t...@gmail.com wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>Isn't it just A8AA1A134; convert each (non-leading) 0 into
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>an A and subtract one from the number to its left, iterating
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>if necessary? 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >>Simple and elegant.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >It makes an assumption about the base used which makes me
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >skeptical of its applicability beyond this specific case. 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   The observation of the person you quote could possibly be
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   correct. But nothing is �simple and elegant� unless it has
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   actually become manifest as JavaScript source code that can
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   be executed under a common modern implementation and pass
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   some tests. (If the solution is really so �simple�, then
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   writing this should be simple!) Here are some test cases:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 1 A
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 26 Z
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 27 AA
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 99 CU
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 100 CV
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 101 CW
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 701 ZY
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 702 ZZ
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 703 AAA
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 704 AAB
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 99997 EQXA
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 99998 EQXB
> 
> > 
> 
> > 
> 
> > 
> 
> > Stefan would you please use the hex notation like my example, so that 10 equals A, 11 equal B and so on.
> 
> > 
> 
> > 
> 
> > 
> 
> > Is that base 26? 
> 
> > 
> 
> > ZZ=26*26+26=702
> 
> > 
> 
> > 
> 
> > 
> 
> > As an extended hex
> 
> > 
> 
> > 10=A
> 
> > 
> 
> > 11=B
> 
> > 
> 
> > 12=C
> 
> > 
> 
> > 13=D
> 
> > 
> 
> > 14=E
> 
> > 
> 
> > 15=F
> 
> > 
> 
> > 16=G
> 
> > 
> 
> > 17=H
> 
> > 
> 
> > 18=I
> 
> > 
> 
> > 19=J
> 
> > 
> 
> > 20=K
> 
> > 
> 
> > 21=L
> 
> > 
> 
> > 22=M
> 
> > 
> 
> > 23=N
> 
> > 
> 
> > 24=O
> 
> > 
> 
> > 25=P
> 
> > 
> 
> > 26=Q
> 
> > 
> 
> > 
> 
> > 
> 
> > Or coma separated digit pairs work also good.
> 
> Just to be a bit annoying not about JavaScript but about our casual experience and notion of numbers i want to say there is NOT a single 0 in 
> 
> 10,100,1000,10 000... 
> 
> And so on numbers are really sets of elements that we can arrange geometrically. 
> 
> 
> 
> A^1, A^2, A^3, A^4 and there is not a single zero in sight.

Getting the pebbles arranged into A^4 seem a bit hard though ;D

[toc] | [prev] | [next] | [standalone]


#24942

Fromjonas.thornvall@gmail.com
Date2014-06-18 18:46 -0700
Message-ID<1b051f7a-8ec8-4aff-819e-6af2433d5ae3@googlegroups.com>
In reply to#24939
Den torsdagen den 19:e juni 2014 kl. 03:05:28 UTC+2 skrev jonas.t...@gmail.com:
> Den torsdagen den 19:e juni 2014 kl. 01:37:24 UTC+2 skrev Stefan Ram:
> 
> > "Michael Haufe (TNO)" <tno@thenewobjective.com> writes:
> 
> > 
> 
> > >On Wednesday, June 18, 2014 3:04:08 PM UTC-5, jonas.t...@gmail.com wrote:
> 
> > 
> 
> > >>Isn't it just A8AA1A134; convert each (non-leading) 0 into
> 
> > 
> 
> > >>an A and subtract one from the number to its left, iterating
> 
> > 
> 
> > >>if necessary? 
> 
> > 
> 
> > >>Simple and elegant.
> 
> > 
> 
> > >It makes an assumption about the base used which makes me
> 
> > 
> 
> > >skeptical of its applicability beyond this specific case. 
> 
> > 
> 
> > 
> 
> > 
> 
> >   The observation of the person you quote could possibly be
> 
> > 
> 
> >   correct. But nothing is �simple and elegant� unless it has
> 
> > 
> 
> >   actually become manifest as JavaScript source code that can
> 
> > 
> 
> >   be executed under a common modern implementation and pass
> 
> > 
> 
> >   some tests. (If the solution is really so �simple�, then
> 
> > 
> 
> >   writing this should be simple!) Here are some test cases:
> 
> > 
> 
> > 
> 
> > 
> 
> > 1 A
> 
> > 
> 
> > 26 Z
> 
> > 
> 
> > 27 AA
> 
> > 
> 
> > 99 CU
> 
> > 
> 
> > 100 CV
> 
> > 
> 
> > 101 CW
> 
> > 
> 
> > 701 ZY
> 
> > 
> 
> > 702 ZZ
> 
> > 
> 
> > 703 AAA
> 
> > 
> 
> > 704 AAB
> 
> > 
> 
> > 99997 EQXA
> 
> > 
> 
> > 99998 EQXB
> 
> 
> 
> Stefan would you please use the hex notation like my example, so that 10 equals A, 11 equal B and so on.
> 
> 
> 
> Is that base 26? 
> 
> ZZ=26*26+26=702
> 
> 
> 
> As an extended hex
> 
> 10=A
> 
> 11=B
> 
> 12=C
> 
> 13=D
> 
> 14=E
> 
> 15=F
> 
> 16=G
> 
> 17=H
> 
> 18=I
> 
> 19=J
> 
> 20=K
> 
> 21=L
> 
> 22=M
> 
> 23=N
> 
> 24=O
> 
> 25=P
> 
> 26=Q
> 
> 
> 
> Or coma separated digit pairs work also good.

Since my generic basechanger for any size of base do use commaseparated digits, maybe it is better keep it that way rather then mess with inventing extended numberal digit sets.

http://web.comhem.se/jonasth/nyan.html

[toc] | [prev] | [next] | [standalone]


#24982

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2014-06-23 16:00 -0700
Message-ID<f11f678e-3986-4351-8729-6494a78248b1@googlegroups.com>
In reply to#24906
On Wednesday, June 18, 2014 12:50:32 AM UTC-5, Stefan Ram wrote:
> "Michael Haufe (TNO)" writes:
> >A cursory Google search yielded the following which could be
> >a decent starting point to create a JavaScript implementation:
> 
>   Based on the code by �r.e.s.�(?):
> 
> "use strict";
> const global = this;
> 
> function word( number, digit )
> { const base = digit.length;
>   let result = '';
>   while( number )
>   { const q = global.Math.ceil( number / base ) - 1;
>     const a = number - q * base;
>     result = digit[ a - 1 ]+ result;
>     number = q; }
>   return result; }
> 
> function number( number, digit )
> { const base = digit.length;
>   let n = 0;
>   let q = 0;
>   for( let i = number.length - 1; i >= 0; --i )
>   { const p = digit.indexOf( number.charAt( i ))+ 1;
>     n = n + p*( global.Math.pow( base, q ));
>     q = q + 1; }
>   return n; }
> 
> for( let n = 0; n < 16; ++n )
> { const w = word( n, '123' );
>   const u = number( w, '123' );
>   document.writeln( n, ' ', w, ' ', u ); }

"To iterate is human, to recurse divine. -- L. Peter Deutsch"

(untested)

function toWord(n,alpha){
    var base = alpha.length

    function _toWord(n,result){
        var q = Math.ceil(n / base) - 1,
            a = n - q * base
        return !n ? result : _toWord(q, alpha[a - 1] + result)
    }
    
    return _toWord(n,"")
}

function toNum(strNum,alpha){
    var base = alpha.length
    
    function _toNum(i,n,q){
        var p = alpha.indexOf(strNum.charAt(i)) + 1;
        return i >= 0 ? _toNum(i-1,n+p*Math.pow(base,q),q+1) : n
    }

    return _toNum(strNum.length - 1,0,0)
}


Building the string backwards and then reversing the final result is no doubt much more efficient, but meh... too lazy at the moment.

[toc] | [prev] | [next] | [standalone]


#24984

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2014-06-23 17:51 -0700
Message-ID<ba4abece-3223-4962-b0cd-c540a8dc1bf0@googlegroups.com>
In reply to#24982
On Monday, June 23, 2014 7:10:48 PM UTC-5, Stefan Ram wrote:
>   You have written �function toWord�, and then
>   �function _toWord� for the inner function. 
> 
>   But you could have used the same name for the
>   inner function:

[...]

Indeed. It is a habit of mine in JS to aid reasoning.

>   Here is a nice way to calculate the factorial of 5 in JavaScript:

[...]

> |< var f = function( x ){ return function( g ){ return g( g ); }
> |    ( function( g ){ return x( function( y ){ return( g( g ))( y ); }); }); };
> |
> |  console.log( f( function( a ){ return function( n )
> |    { if( n < 2 ) return 1; else return n * a( n - 1 ); }})( 5 ));
> |
> |> undefined
> |  120

Even more esoteric:

https://gist.github.com/mlhaufe/5992628

[toc] | [prev] | [next] | [standalone]


#24972

FromJohn Harris <niam@jghnorth.org.uk.invalid>
Date2014-06-23 17:18 +0100
Message-ID<fokgq9t1vli9fn3js2rfnhel0nhvhkpjrb@4ax.com>
In reply to#24895
On Tue, 17 Jun 2014 06:42:28 -0700 (PDT), jonas.thornvall@gmail.com
wrote:

What is a base changer, and why wouldn't it be bijective ?
  <-- Your answer should have been here.

>10=A 
  <snip>

  John

[toc] | [prev] | [next] | [standalone]


#24980

Fromjonas.thornvall@gmail.com
Date2014-06-23 11:27 -0700
Message-ID<35a823f5-7780-4a7f-a456-71a76b912e07@googlegroups.com>
In reply to#24972
Den måndagen den 23:e juni 2014 kl. 18:18:24 UTC+2 skrev John Harris:
> On Tue, 17 Jun 2014 06:42:28 -0700 (PDT), jonas.thornvall@gmail.com
> 
> wrote:
> 
> 
> 
> What is a base changer, and why wouldn't it be bijective ?
> 
>   <-- Your answer should have been here.
> 
> 
> 
> >10=A 
> 
>   <snip>
> 
> 
> 
>   John

http://web.comhem.se/jonasth/nyan.html

[toc] | [prev] | [next] | [standalone]


#24981

FromScott Sauyet <scott.sauyet@gmail.com>
Date2014-06-23 15:29 -0700
Message-ID<b1668508-01ca-4844-8eb1-9d430f45fe05@googlegroups.com>
In reply to#24895
jonas.thornvall@gmail.com wrote:
> 10=A
> 100=9A
> 1000=99A
> ...
> 2000=199A
> 2001=19A1
> 2010=19AA
> 2014=1A14
>
> 1091020134=????????? Brainteaser
>
> A generic basechanger for anybase is rather easy to accomplish, but i am
> a bit stumped where to start with doing conversion into bijective bases,
> i was thinking counting up the base multiples upto the number to
> convert, and bone it out from there saving the differences. But i just
> can't recall howto do it.
>
> Is there an easy obvious way todo this?

Is this the sort of thing you're looking for?

    var zeroless = function(str) {return str.split("").reverse().map(
    (function() {
      var borrow = false;
      return function(ch, idx, arr) {
        ch = + ch;
        if (borrow) (ch = (ch == 0) ? 9: ch - 1);
        if (ch == 0 && idx == arr.length - 1) {return '';}
        borrow = (ch == 0 || ch == 9);
        return (ch == 0) ? 'A' : ch;
      };
    }())).reverse().join("");};

    zeroless("100"); //=> "9A"
    zeroless("2010"); //=> "19AA", etc.

You could easily extend it to an arbitrary base (up to 35, I suppose),
by adding a `base` parameter and replacing the 9's with `(base - 1)`
and the `'A'` with `(base).toString(base + 1).toUpperCase()`.

And by the way, this reports:

    zeroless("1091020134") //=> "A8AA1A134"

Is there some point to this, or is it just a puzzle?

  -- Scott

[toc] | [prev] | [next] | [standalone]


#24995

Fromjonas.thornvall@gmail.com
Date2014-06-24 03:26 -0700
Message-ID<dc68de25-f3f0-4e1a-8ea8-34420ca67321@googlegroups.com>
In reply to#24981
Den tisdagen den 24:e juni 2014 kl. 00:29:57 UTC+2 skrev Scott Sauyet:
> jonas.thornvall@gmail.com wrote:
> 
> > 10=A
> 
> > 100=9A
> 
> > 1000=99A
> 
> > ...
> 
> > 2000=199A
> 
> > 2001=19A1
> 
> > 2010=19AA
> 
> > 2014=1A14
> 
> >
> 
> > 1091020134=????????? Brainteaser
> 
> >
> 
> > A generic basechanger for anybase is rather easy to accomplish, but i am
> 
> > a bit stumped where to start with doing conversion into bijective bases,
> 
> > i was thinking counting up the base multiples upto the number to
> 
> > convert, and bone it out from there saving the differences. But i just
> 
> > can't recall howto do it.
> 
> >
> 
> > Is there an easy obvious way todo this?
> 
> 
> 
> Is this the sort of thing you're looking for?
> 
> 
> 
>     var zeroless = function(str) {return str.split("").reverse().map(
> 
>     (function() {
> 
>       var borrow = false;
> 
>       return function(ch, idx, arr) {
> 
>         ch = + ch;
> 
>         if (borrow) (ch = (ch == 0) ? 9: ch - 1);
> 
>         if (ch == 0 && idx == arr.length - 1) {return '';}
> 
>         borrow = (ch == 0 || ch == 9);
> 
>         return (ch == 0) ? 'A' : ch;
> 
>       };
> 
>     }())).reverse().join("");};
> 
> 
> 
>     zeroless("100"); //=> "9A"
> 
>     zeroless("2010"); //=> "19AA", etc.
> 
> 
> 
> You could easily extend it to an arbitrary base (up to 35, I suppose),
> 
> by adding a `base` parameter and replacing the 9's with `(base - 1)`
> 
> and the `'A'` with `(base).toString(base + 1).toUpperCase()`.
> 
> 
> 
> And by the way, this reports:
> 
> 
> 
>     zeroless("1091020134") //=> "A8AA1A134"
> 
> 
> 
> Is there some point to this, or is it just a puzzle?
> 
> 
> 
>   -- Scott

Did you try convert it back?

I Think there is something wrong with your program reoccuring A can not happen.
Break it down 10,9,10,20,134=A,9,A,1A,134
 

[toc] | [prev] | [next] | [standalone]


#24996

Fromjonas.thornvall@gmail.com
Date2014-06-24 03:28 -0700
Message-ID<3dd455f7-8bb9-403f-9446-cde4ddd2b1ce@googlegroups.com>
In reply to#24995
Den tisdagen den 24:e juni 2014 kl. 12:26:47 UTC+2 skrev jonas.t...@gmail.com:
> Den tisdagen den 24:e juni 2014 kl. 00:29:57 UTC+2 skrev Scott Sauyet:
> 
> > jonas.thornvall@gmail.com wrote:
> 
> > 
> 
> > > 10=A
> 
> > 
> 
> > > 100=9A
> 
> > 
> 
> > > 1000=99A
> 
> > 
> 
> > > ...
> 
> > 
> 
> > > 2000=199A
> 
> > 
> 
> > > 2001=19A1
> 
> > 
> 
> > > 2010=19AA
> 
> > 
> 
> > > 2014=1A14
> 
> > 
> 
> > >
> 
> > 
> 
> > > 1091020134=????????? Brainteaser
> 
> > 
> 
> > >
> 
> > 
> 
> > > A generic basechanger for anybase is rather easy to accomplish, but i am
> 
> > 
> 
> > > a bit stumped where to start with doing conversion into bijective bases,
> 
> > 
> 
> > > i was thinking counting up the base multiples upto the number to
> 
> > 
> 
> > > convert, and bone it out from there saving the differences. But i just
> 
> > 
> 
> > > can't recall howto do it.
> 
> > 
> 
> > >
> 
> > 
> 
> > > Is there an easy obvious way todo this?
> 
> > 
> 
> > 
> 
> > 
> 
> > Is this the sort of thing you're looking for?
> 
> > 
> 
> > 
> 
> > 
> 
> >     var zeroless = function(str) {return str.split("").reverse().map(
> 
> > 
> 
> >     (function() {
> 
> > 
> 
> >       var borrow = false;
> 
> > 
> 
> >       return function(ch, idx, arr) {
> 
> > 
> 
> >         ch = + ch;
> 
> > 
> 
> >         if (borrow) (ch = (ch == 0) ? 9: ch - 1);
> 
> > 
> 
> >         if (ch == 0 && idx == arr.length - 1) {return '';}
> 
> > 
> 
> >         borrow = (ch == 0 || ch == 9);
> 
> > 
> 
> >         return (ch == 0) ? 'A' : ch;
> 
> > 
> 
> >       };
> 
> > 
> 
> >     }())).reverse().join("");};
> 
> > 
> 
> > 
> 
> > 
> 
> >     zeroless("100"); //=> "9A"
> 
> > 
> 
> >     zeroless("2010"); //=> "19AA", etc.
> 
> > 
> 
> > 
> 
> > 
> 
> > You could easily extend it to an arbitrary base (up to 35, I suppose),
> 
> > 
> 
> > by adding a `base` parameter and replacing the 9's with `(base - 1)`
> 
> > 
> 
> > and the `'A'` with `(base).toString(base + 1).toUpperCase()`.
> 
> > 
> 
> > 
> 
> > 
> 
> > And by the way, this reports:
> 
> > 
> 
> > 
> 
> > 
> 
> >     zeroless("1091020134") //=> "A8AA1A134"
> 
> > 
> 
> > 
> 
> > 
> 
> > Is there some point to this, or is it just a puzzle?
> 
> > 
> 
> > 
> 
> > 
> 
> >   -- Scott
> 
> 
> 
> Did you try convert it back?
> 
> 
> 
> I Think there is something wrong with your program reoccuring A can not happen.
> 
> Break it down 10,9,10,20,134=A,9,A,1A,134

Well it can happen in cases like 110 AA

[toc] | [prev] | [next] | [standalone]


#25001

Fromjonas.thornvall@gmail.com
Date2014-06-24 04:24 -0700
Message-ID<2937e7fa-12b0-41a0-ae5a-a28efa28f8d6@googlegroups.com>
In reply to#24995
Den tisdagen den 24:e juni 2014 kl. 12:26:47 UTC+2 skrev jonas.t...@gmail.com:
> Den tisdagen den 24:e juni 2014 kl. 00:29:57 UTC+2 skrev Scott Sauyet:
> 
> > jonas.thornvall@gmail.com wrote:
> 
> > 
> 
> > > 10=A
> 
> > 
> 
> > > 100=9A
> 
> > 
> 
> > > 1000=99A
> 
> > 
> 
> > > ...
> 
> > 
> 
> > > 2000=199A
> 
> > 
> 
> > > 2001=19A1
> 
> > 
> 
> > > 2010=19AA
> 
> > 
> 
> > > 2014=1A14
> 
> > 
> 
> > >
> 
> > 
> 
> > > 1091020134=????????? Brainteaser
> 
> > 
> 
> > >
> 
> > 
> 
> > > A generic basechanger for anybase is rather easy to accomplish, but i am
> 
> > 
> 
> > > a bit stumped where to start with doing conversion into bijective bases,
> 
> > 
> 
> > > i was thinking counting up the base multiples upto the number to
> 
> > 
> 
> > > convert, and bone it out from there saving the differences. But i just
> 
> > 
> 
> > > can't recall howto do it.
> 
> > 
> 
> > >
> 
> > 
> 
> > > Is there an easy obvious way todo this?
> 
> > 
> 
> > 
> 
> > 
> 
> > Is this the sort of thing you're looking for?
> 
> > 
> 
> > 
> 
> > 
> 
> >     var zeroless = function(str) {return str.split("").reverse().map(
> 
> > 
> 
> >     (function() {
> 
> > 
> 
> >       var borrow = false;
> 
> > 
> 
> >       return function(ch, idx, arr) {
> 
> > 
> 
> >         ch = + ch;
> 
> > 
> 
> >         if (borrow) (ch = (ch == 0) ? 9: ch - 1);
> 
> > 
> 
> >         if (ch == 0 && idx == arr.length - 1) {return '';}
> 
> > 
> 
> >         borrow = (ch == 0 || ch == 9);
> 
> > 
> 
> >         return (ch == 0) ? 'A' : ch;
> 
> > 
> 
> >       };
> 
> > 
> 
> >     }())).reverse().join("");};
> 
> > 
> 
> > 
> 
> > 
> 
> >     zeroless("100"); //=> "9A"
> 
> > 
> 
> >     zeroless("2010"); //=> "19AA", etc.
> 
> > 
> 
> > 
> 
> > 
> 
> > You could easily extend it to an arbitrary base (up to 35, I suppose),
> 
> > 
> 
> > by adding a `base` parameter and replacing the 9's with `(base - 1)`
> 
> > 
> 
> > and the `'A'` with `(base).toString(base + 1).toUpperCase()`.
> 
> > 
> 
> > 
> 
> > 
> 
> > And by the way, this reports:
> 
> > 
> 
> > 
> 
> > 
> 
> >     zeroless("1091020134") //=> "A8AA1A134"
> 
> > 
> 
> > 
> 
> > 
> 
> > Is there some point to this, or is it just a puzzle?
> 
> > 
> 
> > 
> 
> > 
> 
> >   -- Scott
> 
> 
> 
> Did you try convert it back?
> 
> 
> 
> I Think there is something wrong with your program reoccuring A can not happen.
> 
> Break it down 10,9,10,20,134=A,9,A,1A,134
It seem like i use two different encoding schemes / read outs, but are both consistent and without collsions?
  

Enc1.  2010=19AA positional

Enc2.  2010=1AA grouped

[toc] | [prev] | [next] | [standalone]


#25002

Fromjonas.thornvall@gmail.com
Date2014-06-24 05:36 -0700
Message-ID<be1289be-acff-48a8-80b9-a5bc9ba94fd6@googlegroups.com>
In reply to#25001
Den tisdagen den 24:e juni 2014 kl. 13:24:53 UTC+2 skrev jonas.t...@gmail.com:
> Den tisdagen den 24:e juni 2014 kl. 12:26:47 UTC+2 skrev jonas.t...@gmail.com:
> 
> > Den tisdagen den 24:e juni 2014 kl. 00:29:57 UTC+2 skrev Scott Sauyet:
> 
> > 
> 
> > > jonas.thornvall@gmail.com wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 10=A
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 100=9A
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 1000=99A
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > ...
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 2000=199A
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 2001=19A1
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 2010=19AA
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 2014=1A14
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > 1091020134=????????? Brainteaser
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > A generic basechanger for anybase is rather easy to accomplish, but i am
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > a bit stumped where to start with doing conversion into bijective bases,
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > i was thinking counting up the base multiples upto the number to
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > convert, and bone it out from there saving the differences. But i just
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > can't recall howto do it.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > Is there an easy obvious way todo this?
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Is this the sort of thing you're looking for?
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > >     var zeroless = function(str) {return str.split("").reverse().map(
> 
> > 
> 
> > > 
> 
> > 
> 
> > >     (function() {
> 
> > 
> 
> > > 
> 
> > 
> 
> > >       var borrow = false;
> 
> > 
> 
> > > 
> 
> > 
> 
> > >       return function(ch, idx, arr) {
> 
> > 
> 
> > > 
> 
> > 
> 
> > >         ch = + ch;
> 
> > 
> 
> > > 
> 
> > 
> 
> > >         if (borrow) (ch = (ch == 0) ? 9: ch - 1);
> 
> > 
> 
> > > 
> 
> > 
> 
> > >         if (ch == 0 && idx == arr.length - 1) {return '';}
> 
> > 
> 
> > > 
> 
> > 
> 
> > >         borrow = (ch == 0 || ch == 9);
> 
> > 
> 
> > > 
> 
> > 
> 
> > >         return (ch == 0) ? 'A' : ch;
> 
> > 
> 
> > > 
> 
> > 
> 
> > >       };
> 
> > 
> 
> > > 
> 
> > 
> 
> > >     }())).reverse().join("");};
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > >     zeroless("100"); //=> "9A"
> 
> > 
> 
> > > 
> 
> > 
> 
> > >     zeroless("2010"); //=> "19AA", etc.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > You could easily extend it to an arbitrary base (up to 35, I suppose),
> 
> > 
> 
> > > 
> 
> > 
> 
> > > by adding a `base` parameter and replacing the 9's with `(base - 1)`
> 
> > 
> 
> > > 
> 
> > 
> 
> > > and the `'A'` with `(base).toString(base + 1).toUpperCase()`.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > And by the way, this reports:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > >     zeroless("1091020134") //=> "A8AA1A134"
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Is there some point to this, or is it just a puzzle?
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > >   -- Scott
> 
> > 
> 
> > 
> 
> > 
> 
> > Did you try convert it back?
> 
> > 
> 
> > 
> 
> > 
> 
> > I Think there is something wrong with your program reoccuring A can not happen.
> 
> > 
> 
> > Break it down 10,9,10,20,134=A,9,A,1A,134
> 
> It seem like i use two different encoding schemes / read outs, but are both consistent and without collsions?
> 
>   
> 
> 
> 
> Enc1.  2010=19AA positional
> 
> 
> 
> Enc2.  2010=1AA grouped

That enc 1 is fit for doing arithmetic seem quite clear but what about enc 2?

[toc] | [prev] | [next] | [standalone]


#25010

FromScott Sauyet <scott.sauyet@gmail.com>
Date2014-06-24 13:05 -0700
Message-ID<e2df08be-246e-47c8-bbf8-1ca57d8f431b@googlegroups.com>
In reply to#25001
jonas.thornvall@gmail.com wrote: 

> It seem like i use two different encoding schemes / read outs, but
> are both consistent and without collsions?
> 
> Enc1.  2010=19AA positional
> 
> Enc2.  2010=1AA grouped

I don't understand that second one.  But obviously 210 => 1AA by the
encoding used elsewhere.

  -- Scott

[toc] | [prev] | [next] | [standalone]


#25012

Fromjonas.thornvall@gmail.com
Date2014-06-24 14:13 -0700
Message-ID<fc06a57e-0cc1-45f3-a814-08cf43bc0960@googlegroups.com>
In reply to#25010
Den tisdagen den 24:e juni 2014 kl. 22:05:12 UTC+2 skrev Scott Sauyet:
> jonas.thornvall@gmail.com wrote: 
> 
> 
> 
> > It seem like i use two different encoding schemes / read outs, but
> 
> > are both consistent and without collsions?
> 
> > 
> 
> > Enc1.  2010=19AA positional
> 
> > 
> 
> > Enc2.  2010=1AA grouped
> 
> 
> 
> I don't understand that second one.  But obviously 210 => 1AA by the
> 
> encoding used elsewhere.
> 
> 
> 
>   -- Scott

My own code is much more layman pettifull and base cased rather then borrowing, but i noticed when looping at printout your code failed for some cases wiht 9's i am not sure why.

119
2009
2019
2029

and so on. I will try to understand your code and see if i can fix it.
Thanks for the help. 

[toc] | [prev] | [next] | [standalone]


#25020

Fromjonas.thornvall@gmail.com
Date2014-06-25 05:36 -0700
Message-ID<3e85f482-d92c-4b68-a008-68037d9b688f@googlegroups.com>
In reply to#25012
Den tisdagen den 24:e juni 2014 kl. 23:13:10 UTC+2 skrev jonas.t...@gmail.com:
> Den tisdagen den 24:e juni 2014 kl. 22:05:12 UTC+2 skrev Scott Sauyet:
> 
> > jonas.thornvall@gmail.com wrote: 
> 
> > 
> 
> > 
> 
> > 
> 
> > > It seem like i use two different encoding schemes / read outs, but
> 
> > 
> 
> > > are both consistent and without collsions?
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Enc1.  2010=19AA positional
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Enc2.  2010=1AA grouped
> 
> > 
> 
> > 
> 
> > 
> 
> > I don't understand that second one.  But obviously 210 => 1AA by the
> 
> > 
> 
> > encoding used elsewhere.
> 
> > 
> 
> > 
> 
> > 
> 
> >   -- Scott
> 
> 
> 
> My own code is much more layman pettifull and base cased rather then borrowing, but i noticed when looping at printout your code failed for some cases wiht 9's i am not sure why.
> 
> 
> 
> 119
> 
> 2009
> 
> 2019
> 
> 2029
> 
> 
> 
> and so on. I will try to understand your code and see if i can fix it.
> 
> Thanks for the help.

Here comes my first stab at it, i did find it very hard to wrap my head around the problem. I used commaseparated instead of alphabet to express higher bases.

I only used Visual expection so there could be alot of faulths, missed cases.
I will program a decoder tomorrow and check if it really correct.

function enc()
{

   out = "";
   var digits = ("" + number).split("").reverse();
   length = digits.length;
 
 

 while (counter < length) {
             if (digits[counter]==0){
                          out = bas + ","+ out ;
                          counter++;
                         // document.write(digits[counter],"X=",out,"<BR>");
                          while (digits[counter]==0){
                                 out = (bas-1)+ ","+out;
                                 counter++;
                                 //  document.write(counter,"A=",out,"<BR>");
                          }
                          if (digits[counter]>1){ 
                                      out=(digits[counter]-1)+ ","+out;
                                      counter++;
                                      //  document.write(counter,"B=",out,"<BR>");
                          } 
                          else { 
                                    //fix here       
                                    counter++;
                                    if(digits[counter]>1){out=bas+","+out; out=digits[counter]-1+","+out;counter++;}
                                    //digits[counter+1]=digits[counter]-1; 
                                    else if(digits[counter]==1){
                                         while(digits[counter]==1){
                                            out=bas+","+out; 
                                            //  document.write(digits[counter],"C=",out,"<BR>");
                                            counter++;
                                            
                                         }
                                         //  document.write("leave C");
                                     }
                                    
                                                 
                          }
            
                } else    
                          while (digits[counter]>0){
                                    
                                      out=(digits[counter])+","+out;
                                      counter++;
                                     //  document.write(counter,"D=",out,"<BR>");
                          }
                      
                              
   
    }

  document.write(number," Out=",out,"<BR>");
}

number=1;
while (number<11000){
counter=0;
out = "";
enc();
number++;
}
</script>

[toc] | [prev] | [next] | [standalone]


#25026

FromScott Sauyet <scott.sauyet@gmail.com>
Date2014-06-25 12:45 -0700
Message-ID<de2372d0-0c2a-4ef5-b1b4-547ff7a154a1@googlegroups.com>
In reply to#25012
jonas.thornvall@gmail.com wrote: 

> My own code is much more layman pettifull and base cased rather then
> borrowing, but i noticed when looping at printout your code failed for 
> some cases wiht 9's i am not sure why.
> 
> 119
> 2009
> 2019
> 2029
> 
> and so on. I will try to understand your code and see if i can fix it.
> Thanks for the help.

Code that works is by no means pitiful compared to code that doesn't!

And I can see why that bug is there, but not a quick way to fix it.  It 
probably warrants a better approach.  If I find time, I will see if I can
come up with one.

  -- Scott

[toc] | [prev] | [next] | [standalone]


#25027

FromScott Sauyet <scott.sauyet@gmail.com>
Date2014-06-25 13:15 -0700
Message-ID<ce1ff707-717d-43d6-b2b5-70fa7e8c560d@googlegroups.com>
In reply to#25026
Scott Sauyet wrote:

> And I can see why that bug is there, but not a quick way to fix it.  It 
> probably warrants a better approach.  If I find time, I will see if I can
> come up with one.

This might work better:

    var zeroless = function(str) {
        if (!str || str === "0") {return "";}
        var lastChar = str.slice(-1);
        var beginning = str.slice(0, -1);
        return lastChar === "0" ? 
               zeroless("" + (beginning - 1)) + "A" :
               zeroless(beginning) + lastChar;
    };           

It is certainly much cleaner and more elegant.

It would not be hard to extend to other bases.

Does it capture all your test cases?

  -- Scott

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web