langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
34
Task/Happy-numbers/PureBasic/happy-numbers.purebasic
Normal file
34
Task/Happy-numbers/PureBasic/happy-numbers.purebasic
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ToFind=8
|
||||
#MaxTests=100
|
||||
#True = 1: #False = 0
|
||||
Declare is_happy(n)
|
||||
|
||||
If OpenConsole()
|
||||
Define i=1,Happy
|
||||
Repeat
|
||||
If is_happy(i)
|
||||
Happy+1
|
||||
PrintN("#"+Str(Happy)+RSet(Str(i),3))
|
||||
EndIf
|
||||
i+1
|
||||
Until Happy>=#ToFind
|
||||
;
|
||||
Print(#CRLF$+#CRLF$+"Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
|
||||
Procedure is_happy(n)
|
||||
Protected i,j=n,dig,sum
|
||||
Repeat
|
||||
sum=0
|
||||
While j
|
||||
dig=j%10
|
||||
j/10
|
||||
sum+dig*dig
|
||||
Wend
|
||||
If sum=1: ProcedureReturn #True: EndIf
|
||||
j=sum
|
||||
i+1
|
||||
Until i>#MaxTests
|
||||
ProcedureReturn #False
|
||||
EndProcedure
|
||||
Loading…
Add table
Add a link
Reference in a new issue