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
23
Task/Prime-decomposition/Lingo/prime-decomposition-1.lingo
Normal file
23
Task/Prime-decomposition/Lingo/prime-decomposition-1.lingo
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
-- Returns list of prime factors for given number.
|
||||
-- To overcome the limits of integers (signed 32-bit in Lingo),
|
||||
-- the number can be specified as float (which works up to 2^53).
|
||||
-- For the same reason, values in returned list are floats, not integers.
|
||||
on getPrimeFactors (n)
|
||||
f = []
|
||||
f.sort()
|
||||
c = sqrt(n)
|
||||
i = 1.0
|
||||
repeat while TRUE
|
||||
i=i+1
|
||||
if i>c then exit repeat
|
||||
check = n/i
|
||||
if bitOr(check,0)=check then
|
||||
f.add(i)
|
||||
n = check
|
||||
c = sqrt(n)
|
||||
i = 1.0
|
||||
end if
|
||||
end repeat
|
||||
f.add(n)
|
||||
return f
|
||||
end
|
||||
11
Task/Prime-decomposition/Lingo/prime-decomposition-2.lingo
Normal file
11
Task/Prime-decomposition/Lingo/prime-decomposition-2.lingo
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
put getPrimeFactors(12)
|
||||
-- [2.0000, 2.0000, 3.0000]
|
||||
|
||||
-- print floats without fractional digits
|
||||
the floatPrecision=0
|
||||
|
||||
put getPrimeFactors(12)
|
||||
-- [2, 2, 3]
|
||||
|
||||
put getPrimeFactors(1125899906842623.0)
|
||||
-- [3, 251, 601, 4051, 614141]
|
||||
Loading…
Add table
Add a link
Reference in a new issue