Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
18
Task/Leonardo-numbers/ANSI-BASIC/leonardo-numbers.basic
Normal file
18
Task/Leonardo-numbers/ANSI-BASIC/leonardo-numbers.basic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
100 REM Leonardo numbers
|
||||
110 DECLARE EXTERNAL SUB PrintLeonardoNums
|
||||
120 CALL PrintLeonardoNums(1, 1, 1, 25, "Leonardo numbers")
|
||||
130 CALL PrintLeonardoNums(0, 1, 0, 25, "Fibonacci numbers")
|
||||
140 END
|
||||
150 REM **
|
||||
160 EXTERNAL SUB PrintLeonardoNums(L0, L1, Sum, Lmt, What$)
|
||||
170 PRINT What$; " ("; L0; ","; L1; ","; Sum; "):"
|
||||
180 IF Lmt >= 1 THEN PRINT L0;
|
||||
190 IF Lmt >= 2 THEN PRINT L1;
|
||||
200 FOR I = 3 TO Lmt
|
||||
210 PRINT L0 + L1 + Sum;
|
||||
220 LET Tmp = L0
|
||||
230 LET L0 = L1
|
||||
240 LET L1 = Tmp + L1 + Sum
|
||||
250 NEXT I
|
||||
260 PRINT
|
||||
270 END SUB
|
||||
18
Task/Leonardo-numbers/Forth/leonardo-numbers.fth
Normal file
18
Task/Leonardo-numbers/Forth/leonardo-numbers.fth
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
: leonardo-next ( n1 n2 n3 -- n1 n1+n2+n3 n2 )
|
||||
swap dup >r + over + r> ;
|
||||
|
||||
: leonardo-print ( n1 n2 n3 u -- )
|
||||
0 do
|
||||
dup .
|
||||
leonardo-next
|
||||
loop
|
||||
drop 2drop ;
|
||||
|
||||
: main ( -- )
|
||||
." First 25 Leonardo numbers:" cr
|
||||
1 1 1 25 leonardo-print cr
|
||||
." First 25 Fibonacci numbers:" cr
|
||||
0 1 0 25 leonardo-print cr ;
|
||||
|
||||
main
|
||||
bye
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
program LeonardoNumbers;
|
||||
|
||||
procedure WriteLeonardoNums(L0, L1: longint; Sum: integer;
|
||||
Lmt: integer; What: string);
|
||||
var
|
||||
I: integer;
|
||||
Tmp: longint;
|
||||
begin
|
||||
WriteLn(What, ' (', L0, ', ', L1, ', ', Sum, '):');
|
||||
if Lmt >= 1 then
|
||||
Write(L0, ' ');
|
||||
if Lmt >= 2 then
|
||||
Write(L1, ' ');
|
||||
for I := 3 to Lmt do
|
||||
begin
|
||||
Write(L0 + L1 + Sum, ' ');
|
||||
Tmp := L0;
|
||||
L0 := L1;
|
||||
L1 := Tmp + L1 + Sum;
|
||||
end;
|
||||
WriteLn;
|
||||
end;
|
||||
|
||||
begin
|
||||
WriteLeonardoNums(1, 1, 1, 25, 'Leonardo numbers');
|
||||
WriteLeonardoNums(0, 1, 0, 25, 'Fibonacci numbers');
|
||||
ReadLn;
|
||||
end.
|
||||
17
Task/Leonardo-numbers/GW-BASIC/leonardo-numbers.basic
Normal file
17
Task/Leonardo-numbers/GW-BASIC/leonardo-numbers.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
10 REM Leonardo numbers
|
||||
20 LIMIT = 25
|
||||
30 L0 = 1: L1 = 1: SUMA = 1
|
||||
40 PRINT "Numeros de Leonardo (";L0;",";L1;",";SUMA;"):"
|
||||
50 GOSUB 100
|
||||
60 L0 = 0: L1 = 1: SUMA = 0
|
||||
70 PRINT "Numeros de Fibonacci (";L0;",";L1;",";SUMA;"):"
|
||||
80 GOSUB 100
|
||||
90 END
|
||||
100 IF LIMIT >= 1 THEN PRINT L0;
|
||||
110 IF LIMIT >= 2 THEN PRINT L1;
|
||||
120 FOR I = 3 TO LIMIT
|
||||
130 PRINT L0 + L1 + SUMA;
|
||||
140 TMP = L0: L0 = L1: L1 = TMP + L1 + SUMA
|
||||
150 NEXT I
|
||||
160 PRINT
|
||||
170 RETURN
|
||||
|
|
@ -1,18 +1,12 @@
|
|||
function L(n, add::Int=1, firsts::Vector=[1, 1])
|
||||
l = max(maximum(n) .+ 1, length(firsts))
|
||||
r = Vector{Int}(l)
|
||||
r[1:length(firsts)] = firsts
|
||||
for i in 3:l
|
||||
r[i] = r[i - 1] + r[i - 2] + add
|
||||
function leonardo(first::Int, second::Int, add::Int, amount::Int)
|
||||
nums = [first, second]
|
||||
for i in 3:amount
|
||||
append!(nums, nums[i-1] + nums[i-2] + add)
|
||||
end
|
||||
return r[n .+ 1]
|
||||
return nums
|
||||
end
|
||||
|
||||
# Task 1
|
||||
println("First 25 Leonardo numbers: ", join(L(0:24), ", "))
|
||||
|
||||
# Task 2
|
||||
@show L(0) L(1)
|
||||
|
||||
# Task 4
|
||||
println("First 25 Leonardo numbers starting with [0, 1]: ", join(L(0:24, 0, [0, 1]), ", "))
|
||||
println("First 25 Leonardo numbers with L1 = 1 L2 = 1 and add number = 1 :")
|
||||
println(leonardo(1,1,1,25))
|
||||
println("First 25 Leonardo numbers with L1 = 0 L2 = 1 and add number = 0 :")
|
||||
println(leonardo(1,1,0,25))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
Module Leonardo_Task {
|
||||
base1=lambda (l0 as decimal,l1 as decimal,add as decimal)->{
|
||||
a=list:=0:=l0,1:=l1
|
||||
=lambda a, add (i as decimal) ->{
|
||||
i=int(i)-1
|
||||
if i<0 then =a(0) exit
|
||||
if not exist(a, i) then
|
||||
do
|
||||
j=len(a)
|
||||
Append a, j:=a(j-1)+a(j-2)+add
|
||||
j++
|
||||
until j>i
|
||||
end if
|
||||
=a(i)
|
||||
}
|
||||
}
|
||||
leonardo=base1(1,1,1)
|
||||
for i=1 to 25
|
||||
? leonardo(i)+" ";
|
||||
next
|
||||
print
|
||||
fibonacci=base1(0,1,0)
|
||||
for i=1 to 25
|
||||
? fibonacci(i)+" ";
|
||||
next
|
||||
print
|
||||
}
|
||||
Leonardo_Task
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
base1=lambda (l0 as decimal=1, l1 as decimal=1, add as decimal=1)-> {
|
||||
ret=stack:=l0, l1
|
||||
= lambda l0, l1, add, ret (x as long)->{
|
||||
z=x
|
||||
x-=len(ret)
|
||||
stack ret {
|
||||
while x>0
|
||||
push l1: l1+=l0+add:read l0
|
||||
data l1 ' at the end
|
||||
x--
|
||||
end while
|
||||
}
|
||||
' stack up ret, z Return z members from ret
|
||||
=array(stack up ret, z)
|
||||
}
|
||||
}
|
||||
Leonardo=base1()
|
||||
Print Leonardo(25)#str$(" ")
|
||||
fibonacci=base1(0,1,0)
|
||||
Print fibonacci(25)#str$(" ")
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
class Leonardo {
|
||||
events "export", "exportdone"
|
||||
decimal l0=1, l1=1, add=1
|
||||
ret=stack
|
||||
module take (x as long){
|
||||
while x>0
|
||||
if len(.ret)=0 then
|
||||
push .l1: .l1+=.l0+.add:read .l0
|
||||
callevent(&.l1)
|
||||
else
|
||||
stack .ret {
|
||||
read a
|
||||
callevent(&a)
|
||||
}
|
||||
end if
|
||||
x--
|
||||
end while
|
||||
sub callevent(&v)
|
||||
if x>1 then
|
||||
call event "export", v
|
||||
else
|
||||
call event "exportdone", v
|
||||
end if
|
||||
end sub
|
||||
}
|
||||
class:
|
||||
module Leonardo (.l0, .l1, .add) {
|
||||
stack .ret {data .l0, .l1}
|
||||
}
|
||||
}
|
||||
Module Solution1 {
|
||||
group withevents Leonardo=Leonardo()
|
||||
group withevents Fibonacci=Leonardo(0,1,0)
|
||||
function leonardo_export {
|
||||
Print number+" ";
|
||||
}
|
||||
function leonardo_exportdone {
|
||||
Print number
|
||||
}
|
||||
function fibonacci_export {
|
||||
Print number+" ";
|
||||
}
|
||||
function fibonacci_exportdone {
|
||||
Print number
|
||||
}
|
||||
Leonardo.take 25
|
||||
Fibonacci.take 25
|
||||
}
|
||||
Solution1
|
||||
Module Solution2 {
|
||||
group withevents Leonardo=Leonardo()
|
||||
group withevents Fibonacci=Leonardo(0,1,0)
|
||||
ret=stack
|
||||
function leonardo_export {
|
||||
read new Value
|
||||
stack ret {data value}
|
||||
}
|
||||
function leonardo_exportdone {
|
||||
call local leonardo_export()
|
||||
Print array(ret)#str$(" ")
|
||||
}
|
||||
function fibonacci_export {
|
||||
call local leonardo_export()
|
||||
}
|
||||
function fibonacci_exportdone {
|
||||
call local leonardo_exportdone()
|
||||
}
|
||||
module dosomething(&ThatObject as Leonardo){
|
||||
ThatObject.take 25
|
||||
}
|
||||
dosomething &Leonardo
|
||||
dosomething &Fibonacci
|
||||
}
|
||||
Solution2
|
||||
|
|
@ -1,17 +1,18 @@
|
|||
100 LIMIT = 25
|
||||
110 L0 = 1
|
||||
120 L1 = 1
|
||||
130 SUMA = 1
|
||||
140 PRINT "Numeros de Leonardo (";L0;",";L1;",";SUMA;"):"
|
||||
150 GOSUB 220
|
||||
160 LET L0 = 0
|
||||
170 LET L1 = 1
|
||||
180 LET SUMA = 0
|
||||
190 PRINT "Numeros de Fibonacci (";L0;",";L1;",";SUMA;"):"
|
||||
200 GOSUB 220
|
||||
210 END
|
||||
220 FOR I = 1 TO LIMIT
|
||||
230 IF I = 1 THEN PRINT L0; : ELSE IF I = 2 THEN PRINT L1; : ELSE PRINT L0+L1+SUMA; : TMP = L0 : L0 = L1 : L1 = TMP+L1+SUMA
|
||||
240 NEXT I
|
||||
250 PRINT CHR$(10)
|
||||
260 RETURN
|
||||
10 REM Leonardo numbers
|
||||
20 LIMIT = 25
|
||||
30 L0 = 1: L1 = 1: SUMA = 1
|
||||
40 PRINT "Numeros de Leonardo (";L0;",";L1;",";SUMA;"):"
|
||||
50 GOSUB 100
|
||||
60 L0 = 0: L1 = 1: SUMA = 0
|
||||
70 PRINT "Numeros de Fibonacci (";L0;",";L1;",";SUMA;"):"
|
||||
80 GOSUB 100
|
||||
90 END
|
||||
100 IF LIMIT >= 1 THEN PRINT L0;
|
||||
110 IF LIMIT >= 2 THEN PRINT L1;
|
||||
120 IF LIMIT < 3 THEN 170: REM In MSX, FOR works like REPEAT
|
||||
130 FOR I = 3 TO LIMIT
|
||||
140 PRINT L0 + L1 + SUMA;
|
||||
150 TMP = L0: L0 = L1: L1 = TMP + L1 + SUMA
|
||||
160 NEXT I
|
||||
170 PRINT
|
||||
180 RETURN
|
||||
|
|
|
|||
18
Task/Leonardo-numbers/Miranda/leonardo-numbers.miranda
Normal file
18
Task/Leonardo-numbers/Miranda/leonardo-numbers.miranda
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout "First 25 Leonardo numbers:\n",
|
||||
Stdout (tab 5 10 (take 25 (leo 1 1 1))),
|
||||
Stdout "\nFirst 25 Fibonacci numbers:\n",
|
||||
Stdout (tab 5 10 (take 25 (leo 0 1 0)))]
|
||||
|
||||
tab :: num->num->[num]->[char]
|
||||
tab w cw = lay . map (concat . map (rjustify cw . shownum)) . group w
|
||||
|
||||
group :: num->[*]->[[*]]
|
||||
group n [] = []
|
||||
group n ls = take n ls:group n (drop n ls)
|
||||
|
||||
leo :: num->num->num->[num]
|
||||
leo s0 s1 add
|
||||
= ks
|
||||
where ks = s0 : s1 : map step (zip2 ks (tl ks))
|
||||
step (a,b) = a + b + add
|
||||
21
Task/Leonardo-numbers/PHP/leonardo-numbers.php
Normal file
21
Task/Leonardo-numbers/PHP/leonardo-numbers.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
// Leonardo numbers
|
||||
|
||||
function echo_Leonardo_nums($l0, $l1, $sum, $lmt, $what) {
|
||||
echo($what.' ('.$l0.', '.$l1.', '.$sum.'):'.PHP_EOL);
|
||||
if ($lmt >= 1)
|
||||
echo($l0.' ');
|
||||
if ($lmt >= 2)
|
||||
echo($l1.' ');
|
||||
for ($i = 3; $i <= $lmt; $i++) {
|
||||
echo(($l0 + $l1 + $sum).' ');
|
||||
$tmp = $l0;
|
||||
$l0 = $l1;
|
||||
$l1 = $tmp + $l1 + $sum;
|
||||
}
|
||||
echo(PHP_EOL);
|
||||
}
|
||||
|
||||
echo_Leonardo_nums(1, 1, 1, 25, 'Leonardo numbers');
|
||||
echo_Leonardo_nums(0, 1, 0, 25, 'Fibonacci numbers');
|
||||
?>
|
||||
12
Task/Leonardo-numbers/PascalABC.NET/leonardo-numbers.pas
Normal file
12
Task/Leonardo-numbers/PascalABC.NET/leonardo-numbers.pas
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
##
|
||||
function Leonardo(L0: integer; L1: integer; add: integer): sequence of integer;
|
||||
begin
|
||||
while (true) do
|
||||
begin
|
||||
yield L0;
|
||||
(L0, L1) := (L1, L0 + L1 + add);
|
||||
end;
|
||||
end;
|
||||
|
||||
Leonardo(1, 1, 1).Take(25).println;
|
||||
Leonardo(0, 1, 0).Take(25).println;
|
||||
|
|
@ -1,25 +1,20 @@
|
|||
REM Leonardo numbers
|
||||
DECLARE SUB leonardo (L0!, L1!, suma!, texto$)
|
||||
|
||||
CONST limit = 25
|
||||
CALL leonardo(1, 1, 1, "Leonardo")
|
||||
CALL leonardo(0, 1, 0, "Fibonacci")
|
||||
CALL leonardo(1, 1, 1, "Numeros de Leonardo")
|
||||
CALL leonardo(0, 1, 0, "Numeros de Fibonacci")
|
||||
END
|
||||
|
||||
SUB leonardo (L0, L1, suma, texto$)
|
||||
PRINT "Numeros de "; texto$; " ("; L0; ","; L1; ","; suma; "):"
|
||||
FOR i = 1 TO limit
|
||||
IF i = 1 THEN
|
||||
PRINT L0;
|
||||
ELSE
|
||||
IF i = 2 THEN
|
||||
PRINT L1;
|
||||
ELSE
|
||||
PRINT L0 + L1 + suma;
|
||||
LET tmp = L0
|
||||
LET L0 = L1
|
||||
LET L1 = tmp + L1 + suma
|
||||
END IF
|
||||
END IF
|
||||
PRINT texto$; " ("; L0; ","; L1; ","; suma; "):"
|
||||
IF limit >= 1 THEN PRINT L0;
|
||||
IF limit >= 2 THEN PRINT L1;
|
||||
FOR i = 3 TO limit
|
||||
PRINT L0 + L1 + suma;
|
||||
LET tmp = L0
|
||||
LET L0 = L1
|
||||
LET L1 = tmp + L1 + suma
|
||||
NEXT i
|
||||
PRINT CHR$(10)
|
||||
PRINT
|
||||
END SUB
|
||||
|
|
|
|||
27
Task/Leonardo-numbers/Tiny-BASIC/leonardo-numbers.basic
Normal file
27
Task/Leonardo-numbers/Tiny-BASIC/leonardo-numbers.basic
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
10 REM Leonardo numbers
|
||||
20 N=21
|
||||
30 K=1
|
||||
40 L=1
|
||||
50 S=1
|
||||
60 PRINT "Leonardo numbers (";K;", ";L;", ";S;"):"
|
||||
70 GOSUB 140
|
||||
80 K=0
|
||||
90 L=1
|
||||
100 S=0
|
||||
110 PRINT "Fibonacci numbers (";K;", ";L;", ";S;"):"
|
||||
120 GOSUB 140
|
||||
130 END
|
||||
140 IF N<1 GOTO 260
|
||||
150 PRINT K;" ";
|
||||
160 IF N<2 GOTO 260
|
||||
170 PRINT L;" ";
|
||||
180 I=3
|
||||
190 IF I>N GOTO 260
|
||||
200 PRINT K+L+S;" ";
|
||||
210 T=K
|
||||
220 K=L
|
||||
230 L=T+L+S
|
||||
240 I=I+1
|
||||
250 GOTO 190
|
||||
260 PRINT
|
||||
270 RETURN
|
||||
|
|
@ -1,23 +1,17 @@
|
|||
SUB leonardo (L0, L1, suma, texto$)
|
||||
PRINT "Numeros de "; texto$; " ("; L0; ","; L1; ","; suma; "):"
|
||||
FOR i = 1 TO limit
|
||||
IF i = 1 THEN
|
||||
PRINT L0;
|
||||
ELSE
|
||||
IF i = 2 THEN
|
||||
PRINT L1;
|
||||
ELSE
|
||||
PRINT L0 + L1 + suma;
|
||||
LET tmp = L0
|
||||
LET L0 = L1
|
||||
LET L1 = tmp + L1 + suma
|
||||
END IF
|
||||
END IF
|
||||
PRINT texto$; " ("; L0; ","; L1; ","; suma; "):"
|
||||
IF limit >= 1 THEN PRINT L0;
|
||||
IF limit >= 2 THEN PRINT L1;
|
||||
FOR i = 3 TO LIMIT
|
||||
PRINT L0 + L1 + suma;
|
||||
LET tmp = L0
|
||||
LET L0 = L1
|
||||
LET L1 = tmp + L1 + suma
|
||||
NEXT i
|
||||
PRINT CHR$(10)
|
||||
PRINT
|
||||
END SUB
|
||||
|
||||
LET limit = 25
|
||||
CALL leonardo(1, 1, 1, "Leonardo")
|
||||
CALL leonardo(0, 1, 0, "Fibonacci")
|
||||
CALL leonardo(1, 1, 1, "Numeros de Leonardo")
|
||||
CALL leonardo(0, 1, 0, "Numeros de Fibonacci")
|
||||
END
|
||||
|
|
|
|||
15
Task/Leonardo-numbers/TypeScript/leonardo-numbers.ts
Normal file
15
Task/Leonardo-numbers/TypeScript/leonardo-numbers.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function leoNums(
|
||||
n: number,
|
||||
L0: number = 1,
|
||||
L1: number = 1,
|
||||
add: number = 1
|
||||
): number[] {
|
||||
const lNums: number[] = [L0, L1];
|
||||
while (lNums.length < n) {
|
||||
lNums.push(lNums[lNums.length - 1] + lNums[lNums.length - 2] + add);
|
||||
}
|
||||
return lNums
|
||||
}
|
||||
|
||||
console.log(leoNums(25))
|
||||
console.log(leoNums(25, 0, 1, 0))
|
||||
Loading…
Add table
Add a link
Reference in a new issue