Four is magic: Difference between revisions

Initial FutureBasic task solution added
m (→‎{{header|Wren}}: Removed two lines which are now redundant.)
(Initial FutureBasic task solution added)
Line 1,515:
123456: One centenas twenty-three thousand four centenas fifty-six is fifty-eight, fifty-eight is eleven, eleven is six, six is three, three is five, five is four, four is magic.
1010101: One million ten thousand one centenas one is forty-one, forty-one is nine, nine is four, four is magic.
</pre>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn FourIsMagic( number as CFNumberRef ) as CFStringRef
CFMutableStringRef result = fn MutableStringNew
NumberFormatterRef formatter = fn NumberFormatterWithStyle( NSNumberFormatterSpellOutStyle )
NumberFormatterSetLocale( formatter, fn LocaleWithIdentifier( @"en_EN" ) )
CFStringRef numberString = fn NumberFormatterStringFromNumber( formatter, number )
MutableStringAppendString( result, fn StringCapitalizedString( numberString ) )
while ( fn StringIsEqual( numberString, @"four" ) == NO )
numberString = fn NumberFormatterStringFromNumber( formatter, fn NumberWithInteger( len(numberString) ) )
MutableStringAppendString( result, fn StringWithFormat( @" is %@, %@", numberString, numberString ) )
wend
MutableStringAppendString( result, @" is magic." )
end fn = result
 
NSInteger i
CFNumberRef testInput
CFArrayRef testNumbers : testNumbers = @[@23, @1000000000, @20140, @100, @130, @151, @-7]
 
NSLog( @"Outputs 0 through 9:\n" )
for i = 0 to 9
NSLog( @"%@", fn FourIsMagic( fn NumberWithInteger( i ) ) )
next
 
NSLog( @"\nOther number tests:\n" )
for testInput in testNumbers
NSLog( @"%@", fn FourIsMagic( testInput ) )
next
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Outputs 0 through 9:
 
Zero is four, four is magic.
One is three, three is five, five is four, four is magic.
Two is three, three is five, five is four, four is magic.
Three is five, five is four, four is magic.
Four is magic.
Five is four, four is magic.
Six is three, three is five, five is four, four is magic.
Seven is five, five is four, four is magic.
Eight is five, five is four, four is magic.
Nine is four, four is magic.
 
Other number tests:
 
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>
 
715

edits