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

Important: you might have noticed that of recent times, the challenges are involving taking an input and converting it to something. Please, do not think I'm losing creativity! Rather, that decision is the fruit of some thinking in which I found that the more outputs are possible, the more involved the coding will get. Anyways...

Challenge #4 - Number to English

This one should be genuinely hard, and open to lots of solutions and improvements. Write a 1-parameter function that takes an integer (whole number) greater than or equal to 0 and outputs that in English. For example, 1 becomes "one", 10 becomes "ten", 10000 becomes "ten thousand". However, note that there is a hyphen between the 10s and the 1s, for example, 92 is "ninety-two". This does not apply to 100s or more: 106 = one hundred and six. 126, however, would be "one hundred twenty-six".

Previous winner was, once again, @Varrience . Beat him! I'll be surprised to see a sub-500!

And wish a happy birthday to @[WUT] Adam !

    Ravage does this have to include the whole JS "Integer" range of 252? what are we capping this at?
    and happy birthday @[WUT] Adam

      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"

                        Chat