Spelling of ordinal numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|REXX}}: simplified the defining of the program options.)
(removed the mention of zero in the task's preamble, it was apparently causing confusion.)
Line 1: Line 1:
{{draft task}}
{{draft task}}


'''Ordinal numbers'''   (as used in this Rosetta Code task),   are numbers that discribe the   ''position''   of something in a list.
'''Ordinal numbers'''   (as used in this Rosetta Code task),   are numbers that describe the   ''position''   of something in a list.


It is this context that ordinal numbers will be used, using an Enlish-spelled name of an ordinal number.
It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number.




Line 23: Line 23:


;Task:
;Task:
Write a driver and a function (subroutine/routine ···) that returns the English-spelled ordinal version of a specified number   (a non-negative integer).
Write a driver and a function (subroutine/routine ···) that returns the English-spelled ordinal version of a specified number   (a positive integer).


Optionally, try to support as many forms of an integer that can be expressed:   '''123'''   '''00123.0'''   '''1.23e2'''   all are forms of the same integer.
Optionally, try to support as many forms of an integer that can be expressed:   '''123'''   '''00123.0'''   '''1.23e2'''   all are forms of the same integer.

'''0'''   (zero)   should have a ordinal representation as:   zeroth


Show all output here.
Show all output here.
Line 34: Line 32:
;Test cases:
;Test cases:
Use (at least) the test cases of:
Use (at least) the test cases of:
0 1 2 3 4 5 11 65 100 101 272 23456 8007006005004003
1 2 3 4 5 11 65 100 101 272 23456 8007006005004003




Line 48: Line 46:
parse arg n /*obtain optional arguments from the CL*/
parse arg n /*obtain optional arguments from the CL*/


if n='' | n="," then n= 0 1 2 3 4 5 11 65 100 101 272 23456 8007006005004003
if n='' | n="," then n= 1 2 3 4 5 11 65 100 101 272 23456 8007006005004003


pgmOpts= 'ordinal quiet' /*define options needed for $SPELL#.REX*/
pgmOpts= 'ordinal quiet' /*define options needed for $SPELL#.REX*/

Revision as of 10:42, 7 September 2017

Spelling of ordinal numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Ordinal numbers   (as used in this Rosetta Code task),   are numbers that describe the   position   of something in a list.

It is this context that ordinal numbers will be used, using an English-spelled name of an ordinal number.


The ordinal numbers are   (at least, one form of them):

  1st  2nd  3rd  4th  5th  6th  7th  ···  99th  100th  ···  1000000000th  ···  etc

sometimes expressed as:

  1st  2nd  3rd  4th  5th  6th  7th  ···  99th  100th  ···  1000000000th  ···


For this task, the following (English-spelled form) will be used:

  first second third fourth fifth sixth seventh ninety-nineth one hundredth one billionth


Furthermore, the American version of numbers will be used here   (as opposed to the British).

2,000,000,000   is two billion,   not   two milliard.


Task

Write a driver and a function (subroutine/routine ···) that returns the English-spelled ordinal version of a specified number   (a positive integer).

Optionally, try to support as many forms of an integer that can be expressed:   123   00123.0   1.23e2   all are forms of the same integer.

Show all output here.


Test cases

Use (at least) the test cases of:

  1  2  3  4  5  11  65  100  101  272  23456  8007006005004003


Related tasks




REXX

<lang REXX>/*REXX programs spells out ordinal numbers (in English, using the American system). */ numeric digits 3000 /*just in case the user uses gihugic #s*/ parse arg n /*obtain optional arguments from the CL*/

if n= | n="," then n= 1 2 3 4 5 11 65 100 101 272 23456 8007006005004003

pgmOpts= 'ordinal quiet' /*define options needed for $SPELL#.REX*/


    do j=1  for words(n)                        /*process each of the specified numbers*/
    x=word(n, j)                                /*obtain a number from the input list. */
    os=$spell#(x  pgmOpts)                      /*invoke REXX routine to spell ordinal#*/
    say right(x, max(20, length(x) ) )      ' spelled ordinal number ───► '      os
    end   /*j*/</lang>
output   when using the default inputs:
                   1  spelled ordinal number ───►  first
                   2  spelled ordinal number ───►  second
                   3  spelled ordinal number ───►  third
                   4  spelled ordinal number ───►  fourth
                   5  spelled ordinal number ───►  fifth
                  11  spelled ordinal number ───►  eleventh
                  65  spelled ordinal number ───►  sixty-fifth
                 100  spelled ordinal number ───►  one hundredth
                 101  spelled ordinal number ───►  one hundred first
                 272  spelled ordinal number ───►  two hundred seventy-second
               23456  spelled ordinal number ───►  twenty-three thousand four hundred fifty-sixth
    8007006005004003  spelled ordinal number ───►  eight quadrillion seven trillion six billion five million four thousand third

The   $SPELL#.REX   routine can be found here   ───►   $SPELL#.REX.