Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,57 @@
|
|||
' FreeBASIC v1.05.0 win64
|
||||
|
||||
Function SumBinaryDigits(number As Integer) As Integer
|
||||
If number < 0 Then number = -number ' convert negative numbers to positive
|
||||
Var sum = 0
|
||||
While number > 0
|
||||
sum += number Mod 2
|
||||
number \= 2
|
||||
Wend
|
||||
Return sum
|
||||
End Function
|
||||
|
||||
Function IsPrime(number As Integer) As Boolean
|
||||
If number <= 1 Then
|
||||
Return false
|
||||
ElseIf number <= 3 Then
|
||||
Return true
|
||||
ElseIf number Mod 2 = 0 OrElse number Mod 3 = 0 Then
|
||||
Return false
|
||||
End If
|
||||
Var i = 5
|
||||
While i * i <= number
|
||||
If number Mod i = 0 OrElse number Mod (i + 2) = 0 Then
|
||||
Return false
|
||||
End If
|
||||
i += 6
|
||||
Wend
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Function IsPernicious(number As Integer) As Boolean
|
||||
Dim popCount As Integer = SumBinaryDigits(number)
|
||||
Return IsPrime(popCount)
|
||||
End Function
|
||||
|
||||
Dim As Integer n = 1, count = 0
|
||||
Print "The following are the first 25 pernicious numbers :"
|
||||
Print
|
||||
|
||||
Do
|
||||
If IsPernicious(n) Then
|
||||
Print Using "###"; n;
|
||||
count += 1
|
||||
End If
|
||||
n += 1
|
||||
Loop Until count = 25
|
||||
|
||||
Print : Print
|
||||
Print "The pernicious numbers between 888,888,877 and 888,888,888 inclusive are :"
|
||||
Print
|
||||
For n = 888888877 To 888888888
|
||||
If IsPernicious(n) Then Print Using "##########"; n;
|
||||
Next
|
||||
Print : Print
|
||||
Print "Press any key to exit the program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue