Four is magic: Difference between revisions
Content added Content deleted
(added Mathematica solution) |
m (→{{header|Mathematica}}/{{header|Wolfram Language}}: removed whitespace) |
||
Line 2,102: | Line 2,102: | ||
Define a simple function which generates the output, using FixedPointList to iterate until a magic number is reached. |
Define a simple function which generates the output, using FixedPointList to iterate until a magic number is reached. |
||
<lang Mathematica> |
<lang Mathematica>magic[num_] := Capitalize[ StringRiffle[ Partition[ |
||
magic[num_] := Capitalize[ StringRiffle[ Partition[ |
|||
FixedPointList[IntegerName[StringLength[#], "Cardinal"] &, IntegerName[num, "Cardinal"]], |
FixedPointList[IntegerName[StringLength[#], "Cardinal"] &, IntegerName[num, "Cardinal"]], |
||
2, 1] /. {n_, n_} :> {n, "magic"}, ", ", " is "] <> "."] |
2, 1] /. {n_, n_} :> {n, "magic"}, ", ", " is "] <> "."]</lang> |
||
</lang> |
|||
Call the function a few times to show the expected output: |
Call the function a few times to show the expected output: |
||
Line 2,126: | Line 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." |
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> |
</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go}} |
{{trans|Go}} |