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,19 @@
PROGRAM PERFECT
PROCEDURE PERFECT(N%->OK%)
LOCAL I%,S%
S%=1
FOR I%=2 TO SQR(N%)-1 DO
IF N% MOD I%=0 THEN S%+=I%+N% DIV I%
END FOR
IF I%=SQR(N%) THEN S%+=I%
OK%=(N%=S%)
END PROCEDURE
BEGIN
PRINT(CHR$(12);) ! CLS
FOR N%=2 TO 10000 STEP 2 DO
PERFECT(N%->OK%)
IF OK% THEN PRINT(N%)
END FOR
END PROGRAM

View file

@ -0,0 +1,24 @@
' FB 1.05.0 Win64
Function isPerfect(n As Integer) As Boolean
If n < 2 Then Return False
If n Mod 2 = 1 Then Return False '' we can assume odd numbers are not perfect
Dim As Integer sum = 1, q
For i As Integer = 2 To Sqr(n)
If n Mod i = 0 Then
sum += i
q = n \ i
If q > i Then sum += q
End If
Next
Return n = sum
End Function
Print "The first 5 perfect numbers are : "
For i As Integer = 2 To 33550336
If isPerfect(i) Then Print i; " ";
Next
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,3 @@
def perfect( n ) = sum( d | d <- 1..n if d|n ) == 2n
println( (1..500).filter(perfect) )

View file

@ -0,0 +1,15 @@
#!/usr/bin/lasso9
define isPerfect(n::integer) => {
#n < 2 ? return false
return #n == (
with i in generateSeries(1, math_floor(math_sqrt(#n)) + 1)
where #n % #i == 0
let q = #n / #i
sum (#q > #i ? (#i == 1 ? 1 | #q + #i) | 0)
)
}
with x in generateSeries(1, 10000)
where isPerfect(#x)
select #x

View file

@ -0,0 +1 @@
6, 28, 496, 8128

View file

@ -0,0 +1,8 @@
on isPercect (n)
sum = 1
cnt = n/2
repeat with i = 2 to cnt
if n mod i = 0 then sum = sum + i
end repeat
return sum=n
end

View file

@ -0,0 +1,12 @@
import math
proc isPerfect(n: int): bool =
var sum: int = 1
for i in 2 .. <(n.toFloat.sqrt+1).toInt:
if n mod i == 0:
sum += (i + n div i)
return (n == sum)
for i in 2..10_000:
if isPerfect(i):
echo(i)

View file

@ -0,0 +1 @@
: isPerfect(n) | i | 0 n 2 / loop: i [ n i mod ifZero: [ i + ] ] n == ;

View file

@ -0,0 +1,7 @@
function is_perfect(integer n)
return sum(factors(n,-1))=n
end function
for i=2 to 100000 do
if is_perfect(i) then ?i end if
end for

View file

@ -0,0 +1,11 @@
for i = 1 to 10000
if perfect(i) see i + nl ok
next
func perfect n
sum = 0
for i = 1 to n - 1
if n % i = 0 sum = sum + i ok
next
if sum = n return 1 else return 0 ok
return sum

View file

@ -0,0 +1,11 @@
func is_perfect(n) {
var sum = 0;
for i in (1 ..^ n) {
i.divides(n) && (sum += i);
}
sum == n;
}
10000.times { |i|
is_perfect(i) && say i;
}

View file

@ -0,0 +1,14 @@
func is_even_perfect(n) {
var square = (8*n + 1)
square.is_sqr || return false
var tp = ((square.isqrt + 1) / 2)
tp.is_pow || return false
(tp-1).is_prime ? true : false
}
for i in range(0, 10000, 2) {
is_even_perfect(i) && say i
}

View file

@ -0,0 +1,15 @@
func perfect(n:Int) -> Bool {
var sum = 0
for i in 1..<n {
if n % i == 0 {
sum += i
}
}
return sum == n
}
for i in 1..<10000 {
if perfect(i) {
println(i)
}
}

View file

@ -0,0 +1,7 @@
def is_perfect:
. as $in
| $in == reduce range(1;$in) as $i
(0; if ($in % $i) == 0 then $i + . else . end);
# Example:
range(1;10001) | select( is_perfect )