Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,35 @@
' FreeBASIC v1.05.0 win64
Function SumProperDivisors(number As Integer) As Integer
If number < 2 Then Return 0
Dim sum As Integer = 0
For i As Integer = 1 To number \ 2
If number Mod i = 0 Then sum += i
Next
Return sum
End Function
Dim As Integer n, f
Dim As Integer sum(19999)
For n = 1 To 19999
sum(n) = SumProperDivisors(n)
Next
Print "The pairs of amicable numbers below 20,000 are :"
Print
For n = 1 To 19998
' f = SumProperDivisors(n)
f = sum(n)
If f <= n OrElse f < 1 OrElse f > 19999 Then Continue For
If f = sum(n) AndAlso n = sum(f) Then
Print Using "#####"; n;
Print " and "; Using "#####"; sum(n)
End If
Next
Print
Print "Press any key to exit the program"
Sleep
End

View file

@ -0,0 +1,38 @@
' version 04-10-2016
' compile with: fbc -s console
' replaced the function with 2 FOR NEXT loops
#Define max 20000 ' test for pairs below max
#Define max_1 max -1
Dim As String u_str = String(Len(Str(max))+1,"#")
Dim As UInteger n, f
Dim Shared As UInteger sum(max_1)
For n = 2 To max_1
sum(n) = 1
Next
For n = 2 To max_1 \ 2
For f = n * 2 To max_1 Step n
sum(f) += n
Next
Next
Print
Print Using " The pairs of amicable numbers below" & u_str & ", are :"; max
Print
For n = 1 To max_1 -1
f = Sum(n)
If f <= n OrElse f > max Then Continue For
If f = sum(n) AndAlso n = sum(f) Then
Print Using u_str & " and" & u_str ; n; f
End If
Next
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print : Print " Hit any key to end program"
Sleep
End