Four is magic: Difference between revisions

Add APL
(Added Delphi example)
(Add APL)
Line 281:
C:\>magic 999999
Nine hundred ninety-nine thousand nine-hundred ninety-nine is fifty-eight, fifty-eight is eleven, eleven is six, six is three, three is five, five is four, four is magic.</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<lang APL>magic←{
t20←'one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' 'nine'
t20←t20,'ten' 'eleven' 'twelve' 'thirteen' 'fourteen' 'fifteen' 'sixteen'
t20←t20,'seventeen' 'eighteen' 'nineteen'
tens←'twenty' 'thirty' 'forty' 'fifty' 'sixty' 'seventy' 'eighty' 'ninety'
spell←{
⍵=0:'zero'
{
⍵=0:''
⍵<20:⍵⊃t20
⍵<100:∊tens[(⌊⍵÷10)-1],((0≠≢r)/'-'),r←∇10|⍵
⍵<1000:(∇⌊⍵÷100),' hundred',((0≠≢r)/' '),r←∇100|⍵
⍵<1e6:(∇⌊⍵÷1000),' thousand',((0≠≢r)/' '),r←∇1000|⍵
⍵<1e9:(∇⌊⍵÷1e6),' million',((0≠≢r)/' '),r←∇1e6|⍵
⍵<1e12:(∇⌊⍵÷1e9),' billion',((0≠≢r)/' '),r←∇1e9|⍵
⍵<1e15:(∇⌊⍵÷1e12),' trillion',((0≠≢r)/' '),r←∇1e12|⍵
⍵<1e18:(∇⌊⍵÷1e15),' quadrillion',((0≠≢r)/' '),r←∇1e15|⍵
⍵<1e21:(∇⌊⍵÷1e18),' quintillion',((0≠≢r)/' '),r←∇1e18|⍵
'Overflow' ⎕SIGNAL 11
}⍵
}
1(819⌶)@1⊢{
n←spell ⍵
⍵=4:n,' is magic.'
n,' is ',(spell ≢n),', ',∇≢n
}⍵
}</lang>
{{out}}
<pre> magic 0
Zero is four, four is magic.
magic 4
Four is magic.
magic 10
Ten is three, three is five, five is four, four is magic.
magic 1234567
One million two hundred thirty-four thousand five hundred sixty-seven is sixty-n
ine, sixty-nine is ten, ten is three, three is five, five is four, four is
magic.
magic 2*64
Eighteen quintillion four hundred forty-six quadrillion seven hundred forty-four
trillion seventy-three billion seven hundred nine million five hundred fi
fty-one thousand six hundred sixteen is one hundred ninety, one hundred ni
nety is eighteen, eighteen is eight, eight is five, five is four, four is
magic.</pre>
 
=={{header|AutoHotkey}}==
Line 326 ⟶ 373:
94,837,286,837 ninety-four billion , eight hundred thirty-seven million , two hundred eighty-six thousand , eight hundred thirty-seven is one hundred nineteen, one hundred nineteen is twenty, twenty is six, six is three, three is five, five is four, four is magic!
636,478,294,710 six hundred thirty-six billion , four hundred seventy-eight million , two hundred ninety-four thousand , seven hundred ten is one hundred twenty-two, one hundred twenty-two is twenty-two, twenty-two is ten, ten is three, three is five, five is four, four is magic!</pre>
 
=={{header|AWK}}==
<lang AWK>
2,119

edits