• Discussion
  • [CODE GOLF] Challenge #4 - Number to English

Varrience Ah, sorry - capping at "nine hundred ninety-nine billion nine hundred ninety-nine thousand nine hundred ninety-nine," or 999,999,999,999.
Also, looks like @[WUT] Adam came back on the forum for his birthday lol

    what-the-dog-doin A. It doesn't work
    B. number to English, not English to number lol

    And it has to go in the console.

    Ravage I think you meant nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred and ninety-nine

    Also happy late birthday @[WUT] Adam

    Yo happy birthday adam

    Letti42 Surprised anyone actually came up with a solution - should I run this for 2 or 3 days more? In fact, do you want to have me keep on making Code Golf challenges?

      Ravage well mine took a little time and it's super ugly haven't counted yet this challenge is an astronomical leap from the previous challenges considering this requires parsing knowledge while keeping the process as small as possible

      Additionally does this also have to count 0 within the given range? @Letti42's current solution produces no output when fed 0 or "zero" oversights like these make it harder to present a given solution
      not only that but feeding certain inputs produces the incorrect padding used with the pattern for instance 6000443
      produces "thousand" when there is no presence of thousands within the number now you understand the troubleshooting hell I've been through is just the tip of the iceburg

      Also are we allowed to have rough formatting AKA extra spaces or the "hundred and six" in our answers? or does that also need to be corrected?

      If were being lenient on what i asked for i can reveal my answer was piling up a list to this point so it wouldn't be a bunch of ping pong

        Varrience the range is 1-999,999,999,999; no need to do 0.
        All other things need to be clean: correct padding, no rough formatting.
        But you still didn't answer the question: should we keep on doing these?

          Ravage well it should be fine, just expect a longer time to answer when you give prompts like these

          Varrience oh well actually now that you point it out i see that it can actually make it shorter, hold on

            Letti42 shorter? your still missing the "and" propagation when the output is >100 & < 10 if anything your solution should be getting longer from what i pointed out

              Varrience you're not supposed to use "and", formally its only used for decimals, eg: 1234: "one thousand two hundred thirty-four" vs 1234.5 is "one thousand two hundred thirty-four AND 5 tenths"

                ok well its updated now @ 478 characters

                Letti42 so we don't need and in our solution then?

                Ravage This does not apply to 100s or more: 106 = one hundred and six.

                ^^ is what i was refering to if we are not using this syntax let us know @Ravage

                  Varrience Bruh, of course that's what we're using... You need "and" when there is no 10s between the 1s and a greater base, for example, 1009 or 305. If there is a tens, then it uses the hyphen: 126 is one hundred twenty-six.

                  And hey there's a featured project! Not particularly interesting, though. Someone, make it all into one line and repost it as "3D animation 1 line of code"

                    Ravage was asking cuz letti didn't have it in his anywho here's mine

                    // minified 455 version: all
                    function a(e){for(b=",one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,,fif,,,eigh,,,,twen,,for".split(","),o="",e+="",i=t=e.length;i>0;i-=3)p=e[i-3],q=e[i-2],r=e[i-1],o=(p>0?b[p]+" hundred"+(q>0||r>0?" ":""):"")+(q>0?(v=q<2?q+r|0:20+1*q,(b[v]||b[v-10]||b[v-20]||"")+(v>19?"ty":v>12?"teen":"")):"")+(1!=q&&r>0?(q>1?"-":p>0?"and ":"")+b[r]:"")+(e.substring(i-3,3)>0?", thousand , million , billion ".split(",")[(t-i)/3|0]:"")+o;return o}

                    since i don't think anyone else wants to take a crack at it

                      15 days later

                      Varrience
                      399 chars
                      (under 400 lets go!)

                      a=",one,two,three,four,five,six,seven,eight,nine,ten,twen,thir,for,fif,six,seven,eigh,nine,,thousand,million,billion,ten,eleven,twelve,,fourteen".split(",");function c(e){for(d=e.toString().split("").map(Number),r="",j=v=d.length;j>0;j-=3)u=d[j-1],o=d[j-2],r=((p=d[j-3])?a[p]+" hundred ":"")+(o>1?a[o+9]+"ty"+(u?"-":""):"")+(1==o?a[u+23]||a[u+9]+"teen":a[u])+(u+o?" ":"")+a[(v-j)/3+19]+" "+r;return r}

                      379 chars

                      a=",one,two,three,four,five,six,seven,eight,nine,ten,twen,thir,for,fif,six,seven,eigh,nine,,thousand,million,billion,ten,eleven,twelve,,fourteen".split(","),c=n=>{for(r=e="",j=v=(d=(n+e).split(e)).length;j>0;)u=d[--j],o=d[--j],r=((p=d[--j])-0?a[p]+" hundred ":e)+(o>1?a[o- -9]+"ty"+(u?"-":e):e)+(1==o?a[u-0+23]||a[u-0+9]+"teen":a[u])+(u+o==0?e:" ")+a[(v-j)/3+18]+" "+r;return r};

                      You never mentioned having to do it in code.org.

                      Chat