Four is magic: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: added zkl header)
(→‎{{header|zkl}}: added code)
Line 92: Line 92:


=={{header|zkl}}==
=={{header|zkl}}==
{{trans|Perl6}}
<lang zkl></lang>
Limitiation: zkl only has 64 bit signed integars.
<lang zkl></lang>

Uses the nth function from [[Spelling_of_ordinal_numbers#zkl]]

<lang zkl>fcn fourIsMagic(int){
if(int==0) return("Zero is four, four is magic.");
string:="";
while(1){ c:=nth(int,False);
string+="%s is ".fmt(c);
if(int = ( if(int==4) 0 else c.len() )){
string+="%s, ".fmt(nth(int,False));
}else{
string+="magic.";
break;
}
}
string[0].toUpper() + string[1,*]
}</lang>
<lang zkl>foreach n in (T(0,4,6,11,13,75,337,-164,9876543209)){
println(fourIsMagic(n),"\n")
}</lang>
{{out}}
{{out}}
<pre>
<pre>
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.

Three hundred thirty-seven is twenty-six, twenty-six is ten, ten is three, three is five, five is four, four is magic.

Negative one hundred sixty-four is thirty-one, thirty-one is ten, ten is three, three is five, five is four, four is magic.

Nine billion eight hundred seventy-six million five hundred forty-three thousand two hundred nine is ninety-seven, ninety-seven is twelve, twelve is six, six is three, three is five, five is four, four is magic.
</pre>
</pre>