Four is magic: Difference between revisions

m
(added Mathematica solution)
Line 2,102:
Define a simple function which generates the output, using FixedPointList to iterate until a magic number is reached.
 
<lang Mathematica>magic[num_] := Capitalize[ StringRiffle[ Partition[
magic[num_] := Capitalize[ StringRiffle[ Partition[
FixedPointList[IntegerName[StringLength[#], "Cardinal"] &, IntegerName[num, "Cardinal"]],
2, 1] /. {n_, n_} :> {n, "magic"}, ", ", " is "] <> "."]</lang>
</lang>
 
Call the function a few times to show the expected output:
Line 2,126 ⟶ 2,124:
Out[5]= "One hundred ninety-four thousand sixty-four is forty-three, forty-three is eleven, eleven is six, six is three, three is five, five is four, four is magic."
</pre>
 
=={{header|Nim}}==
{{trans|Go}}
Anonymous user