Four is magic: Difference between revisions

m
m (→‎{{header|q}}: separated solution and commentary)
Line 1,966:
Eight hundred seventy four sextillion one hundred forty three quintillion four hundred twenty five quadrillion eight hundred fifty five trillion seven hundred forty five billion seven hundred thirty three million eight hundred ninety six thousand thirty is two hundred fifty three, two hundred fifty three is twenty three, twenty three is twelve, twelve is six, six is three, three is five, five is four, four is magic. </pre>
=={{header|q}}==
<lang q>C:``one`two`three`four`five`six`seven`eight`nine`ten,
<lang q>/ cardinal numbers <20
C:``one`two`three`four`five`six`seven`eight`nine`ten `eleven`twelve`thirteen`fourteen`fifteen`sixteen`seventeen`eighteen`nineteen / cardinal numbers <20
/ tens
T:``ten`twenty`thirty`forty`fifty`sixty`seventy`eighty`ninety
/ magnitudes
M:``thousand`million`billion`trillion`quadrillion`quintillion`sextillion`septillion
 
T:``ten`twenty`thirty`forty`fifty`sixty`seventy`eighty`ninety / tens
st:{ / stringify <1000
M:``thousand`million`billion`trillion`quadrillion`quintillion`sextillion`septillion / magnitudes
 
st:{ / stringify <1000
$[x<20; C x;
x<100; (T;C)@'10 vs x;
{C[y],`hundred,$[z=0;`;x z]}[.z.s] . 100 vs x] }
 
s:{$[x=0; "zero"; {" "sv string except[;`]raze x{$[x~`;x;x,y]}'M reverse til count x} st each 1000 vs x]} / stringify
/ stringify
s:{$[x=0; "zero"; {" "sv string except[;`]raze x{$[x~`;x;x,y]}'M reverse til count x} st each 1000 vs x]}
 
fim:{@[;0;upper],[;"four is magic.\n"] raze 1_{y," is ",x,", "}prior s each(count s@)\[x]} / four is magic
/ four is magic
fim:{@[;0;upper],[;"four is magic.\n"] raze 1_{y," is ",x,", "}prior s each(count s@)\[x]}
 
1 raze fim each 0 4 8 16 25 89 365 2586 25865 369854 40000000001; / tests</lang>
/ tests
1 raze fim each 0 4 8 16 25 89 365 2586 25865 369854 40000000001;</lang>
{{out}}
<pre>Zero is four, four is magic.
39

edits