Four is magic: Difference between revisions
Content added Content deleted
(→{{header|Clojure}}: Add implementation.) |
No edit summary |
||
Line 3,431: | Line 3,431: | ||
Negative one hundred sixty-four is thirty-one, thirty-one 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. |
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> |
|||
=={{header|Swift}}== |
|||
<lang swift>import Foundation |
|||
func fourIsMagic(number: NSNumber) -> String { |
|||
let formatter = NumberFormatter() |
|||
formatter.numberStyle = .spellOut |
|||
formatter.locale = Locale(identifier: "en_EN") |
|||
var result: [String] = [] |
|||
var numberString = formatter.string(from: number)! |
|||
result.append(numberString.capitalized) |
|||
while numberString != "four" { |
|||
numberString = formatter.string(from: NSNumber(value: numberString.count))! |
|||
result.append(contentsOf: [" is ", numberString, ", ", numberString]) |
|||
} |
|||
result.append(" is magic.") |
|||
return result.joined() |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Twenty-Three is twelve, twelve is six, six is three, three is five, five is four, four is magic. |
|||
One Billion is eleven, eleven is six, six is three, three is five, five is four, four is magic. |
|||
Twenty Thousand One Hundred Forty is thirty-three, thirty-three is twelve, twelve is six, six is three, three is five, five is four, four is magic. |
|||
One Hundred is eleven, eleven is six, six is three, three is five, five is four, four is magic. |
|||
One Hundred Thirty is eighteen, eighteen is eight, eight is five, five is four, four is magic. |
|||
One Hundred Fifty-One is twenty-one, twenty-one is ten, ten is three, three is five, five is four, four is magic. |
|||
Minus Seven is eleven, eleven is six, six is three, three is five, five is four, four is magic. |
|||
</pre> |
</pre> |
||