Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Happy-numbers/PureBasic/happy-numbers.basic
Normal file
34
Task/Happy-numbers/PureBasic/happy-numbers.basic
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