Four is magic: Difference between revisions

→‎{{header|REXX}}: added the REXX language.
m (sigh, another typo)
(→‎{{header|REXX}}: added the REXX language.)
Line 224:
 
One hundred fifteen quattuorvigintillion seven hundred ninety-two trevigintillion eighty-nine duovigintillion two hundred thirty-seven unvigintillion three hundred sixteen vigintillion one hundred ninety-five novemdecillion four hundred twenty-three octodecillion five hundred seventy septendecillion nine hundred eighty-five sexdecillion eight quindecillion six hundred eighty-seven quattuordecillion nine hundred seven tredecillion eight hundred fifty-three duodecillion two hundred sixty-nine undecillion nine hundred eighty-four decillion six hundred sixty-five nonillion six hundred forty octillion five hundred sixty-four septillion thirty-nine sextillion four hundred fifty-seven quintillion five hundred eighty-four quadrillion seven trillion nine hundred thirteen billion one hundred twenty-nine million six hundred thirty-nine thousand nine hundred thirty-six is eight hundred sixty-nine, eight hundred sixty-nine is twenty-four, twenty-four is eleven, eleven is six, six is three, three is five, five is four, four is magic.</pre>
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm converts a # to English into the phrase: a is b, b is c, ... four is magic. */
numeric digits 3000 /*be able to handle gihugic numbers. */
parse arg x /*obtain optional numbers from the C.L.*/
if x='' then x=-164 0 4 6 11 13 75 100 337 9223372036854775807 /*use these defaults?*/
@.=. /*stemmed array used for memoization. */
do j=1 for words(x) /*process each of the numbers in list. */
say 4_is( word(x, j) ) /*display phrase that'll be returned. */
say /*display a blank line between outputs.*/
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
4_is: procedure expose @.; parse arg #,,$ /*obtain the start number.*/
if #\==4 then do until L==4 /*Not 4? Process number.*/
@.#=$spell#(# 'quiet minus negative') /*spell number in English.*/
#=@.#; L=length(#) /*get the length of spelt#*/
if @.L==. then @.L=$spell#(L 'quiet') /*¬spelt before? Spell it.*/
$=$ # "is" @.L',' /*add phrase to the answer*/
#=L /*use the new number, ··· */
end /*until*/ /* ··· which will be spelt*/
$=strip($ 'four is magic.') /*finish the sentence with the finale. */
parse var $ first 2 other; upper first /*capitalize the first letter of output*/
return first || other /*return the sentence to the invoker. */</lang>
The &nbsp; '''$SPELL#.REX''' &nbsp; routine can be found here &nbsp; ───► &nbsp; [[$SPELL.REX|$SPELL#.REX]]. <br><br>
 
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Negative one hundred sixty-four is thirty-one, thirty-one is ten, ten is three, three is five, five is four, four is magic.
 
Zero is four, four is magic.
 
Four is magic.
 
Six is three, three is five, five is four, four is magic.
 
Eleven is six, six is three, three is five, five is four, four is magic.
 
Thirteen is eight, eight is five, five is four, four is magic.
 
Seventy-five is twelve, twelve is six, six is three, three is five, five is four, four is magic.
 
One hundred is eleven, eleven is six, six is three, three is five, five is four, four is magic.
 
Three hundred thirty-seven is twenty-six, twenty-six is ten, ten is three, three is five, five is four, four is magic.
 
Nine quintillion two hundred twenty-three quadrillion three hundred seventy-two trillion thirty-six billion eight hundred fifty-four million seven hundred seventy-five thousand eight hundred seven is one hundred ninety-six, one hundred ninety-six is twenty-two, twenty-two is ten, ten is three, three is five, five is four, four is magic.
</pre>
 
=={{header|zkl}}==