Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Happy-numbers/FutureBasic/happy-numbers.basic
Normal file
30
Task/Happy-numbers/FutureBasic/happy-numbers.basic
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
local fn IsHappy( num as NSUInteger ) as NSUInteger
|
||||
NSUInteger i, happy = 0, count = 0
|
||||
|
||||
while ( count < 50 ) and ( happy != 1 )
|
||||
CFStringRef numStr = str( num )
|
||||
count++ : happy = 0
|
||||
for i = 1 to len( numStr )
|
||||
happy = happy + fn StringIntegerValue( mid( numStr, i, 1 ) ) ^ 2
|
||||
next
|
||||
num = happy
|
||||
wend
|
||||
end fn = num
|
||||
|
||||
void local fn HappyNumbers
|
||||
NSUInteger i, count = 0
|
||||
|
||||
for i = 1 to 100
|
||||
if ( fn IsHappy(i) == 1 )
|
||||
count++
|
||||
NSLog( @"%2lu. %2lu is a happy number", count, i )
|
||||
if count == 8 then exit fn
|
||||
end if
|
||||
next
|
||||
end fn
|
||||
|
||||
fn HappyNumbers
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue