Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -1,100 +1,100 @@
|
|||
;-------------------------------------------------------
|
||||
; useful equates
|
||||
;-------------------------------------------------------
|
||||
;-------------------------------------------------------
|
||||
; useful equates
|
||||
;-------------------------------------------------------
|
||||
bdos equ 5 ; BDOS entry
|
||||
cr equ 13 ; ASCII carriage return
|
||||
lf equ 10 ; ASCII line feed
|
||||
space equ 32 ; ASCII space char
|
||||
cr equ 13 ; ASCII carriage return
|
||||
lf equ 10 ; ASCII line feed
|
||||
space equ 32 ; ASCII space char
|
||||
conout equ 2 ; BDOS console output function
|
||||
putstr equ 9 ; BDOS print string function
|
||||
nterms equ 20 ; number of terms (max=24) to display
|
||||
;-------------------------------------------------------
|
||||
; main code begins here
|
||||
;-------------------------------------------------------
|
||||
org 100h
|
||||
lxi h,0 ; save CP/M's stack
|
||||
dad sp
|
||||
shld oldstk
|
||||
lxi sp,stack ; set our own stack
|
||||
lxi d,signon ; print signon message
|
||||
mvi c,putstr
|
||||
call bdos
|
||||
mvi a,0 ; start with Fib(0)
|
||||
mloop: push a ; save our count
|
||||
call fib
|
||||
call putdec
|
||||
mvi a,space ; separate the numbers
|
||||
call putchr
|
||||
pop a ; get our count back
|
||||
inr a ; increment it
|
||||
cpi nterms+1 ; have we reached our limit?
|
||||
jnz mloop ; no, keep going
|
||||
lhld oldstk ; all done; get CP/M's stack back
|
||||
sphl ; restore it
|
||||
ret ; back to command processor
|
||||
;-------------------------------------------------------
|
||||
; calculate nth Fibonacci number (max n = 24)
|
||||
; entry: A = n
|
||||
; exit: HL = Fib(n)
|
||||
;-------------------------------------------------------
|
||||
fib: mov c,a ; C holds n
|
||||
lxi d,0 ; DE holds Fib(n-2)
|
||||
lxi h,1 ; HL holds Fib(n-1)
|
||||
ana a ; Fib(0) is a special case
|
||||
jnz fib2 ; n > 0 so calculate normally
|
||||
xchg ; otherwise return with HL=0
|
||||
ret
|
||||
fib2: dcr c
|
||||
jz fib3 ; we're done
|
||||
push h ; save Fib(n-1)
|
||||
dad d ; HL = Fib(n), soon to be Fib(n-1)
|
||||
pop d ; DE = old F(n-1), now Fib(n-2)
|
||||
jmp fib2 ; ready for next pass
|
||||
putstr equ 9 ; BDOS print string function
|
||||
nterms equ 20 ; number of terms (max=24) to display
|
||||
;-------------------------------------------------------
|
||||
; main code begins here
|
||||
;-------------------------------------------------------
|
||||
org 100h
|
||||
lxi h,0 ; save CP/M's stack
|
||||
dad sp
|
||||
shld oldstk
|
||||
lxi sp,stack ; set our own stack
|
||||
lxi d,signon ; print signon message
|
||||
mvi c,putstr
|
||||
call bdos
|
||||
mvi a,0 ; start with Fib(0)
|
||||
mloop: push a ; save our count
|
||||
call fib
|
||||
call putdec
|
||||
mvi a,space ; separate the numbers
|
||||
call putchr
|
||||
pop a ; get our count back
|
||||
inr a ; increment it
|
||||
cpi nterms+1 ; have we reached our limit?
|
||||
jnz mloop ; no, keep going
|
||||
lhld oldstk ; all done; get CP/M's stack back
|
||||
sphl ; restore it
|
||||
ret ; back to command processor
|
||||
;-------------------------------------------------------
|
||||
; calculate nth Fibonacci number (max n = 24)
|
||||
; entry: A = n
|
||||
; exit: HL = Fib(n)
|
||||
;-------------------------------------------------------
|
||||
fib: mov c,a ; C holds n
|
||||
lxi d,0 ; DE holds Fib(n-2)
|
||||
lxi h,1 ; HL holds Fib(n-1)
|
||||
ana a ; Fib(0) is a special case
|
||||
jnz fib2 ; n > 0 so calculate normally
|
||||
xchg ; otherwise return with HL=0
|
||||
ret
|
||||
fib2: dcr c
|
||||
jz fib3 ; we're done
|
||||
push h ; save Fib(n-1)
|
||||
dad d ; HL = Fib(n), soon to be Fib(n-1)
|
||||
pop d ; DE = old F(n-1), now Fib(n-2)
|
||||
jmp fib2 ; ready for next pass
|
||||
fib3: ret
|
||||
;-------------------------------------------------------
|
||||
; console output of char in A register
|
||||
;-------------------------------------------------------
|
||||
;-------------------------------------------------------
|
||||
; console output of char in A register
|
||||
;-------------------------------------------------------
|
||||
putchr: push h
|
||||
push d
|
||||
push b
|
||||
mov e,a
|
||||
mvi c,conout
|
||||
call bdos
|
||||
pop b
|
||||
pop d
|
||||
pop h
|
||||
ret
|
||||
;---------------------------------------------------------
|
||||
; Output decimal number to console
|
||||
; HL holds 16-bit unsigned binary number to print
|
||||
;---------------------------------------------------------
|
||||
push d
|
||||
push b
|
||||
mov e,a
|
||||
mvi c,conout
|
||||
call bdos
|
||||
pop b
|
||||
pop d
|
||||
pop h
|
||||
ret
|
||||
;---------------------------------------------------------
|
||||
; Output decimal number to console
|
||||
; HL holds 16-bit unsigned binary number to print
|
||||
;---------------------------------------------------------
|
||||
putdec: push b
|
||||
push d
|
||||
push h
|
||||
lxi b,-10
|
||||
lxi d,-1
|
||||
push d
|
||||
push h
|
||||
lxi b,-10
|
||||
lxi d,-1
|
||||
putdec2:
|
||||
dad b
|
||||
inx d
|
||||
jc putdec2
|
||||
lxi b,10
|
||||
dad b
|
||||
xchg
|
||||
mov a,h
|
||||
ora l
|
||||
cnz putdec ; recursive call
|
||||
mov a,e
|
||||
adi '0'
|
||||
call putchr
|
||||
pop h
|
||||
pop d
|
||||
pop b
|
||||
ret
|
||||
;-------------------------------------------------------
|
||||
; data area
|
||||
;-------------------------------------------------------
|
||||
signon: db 'Fibonacci number sequence:',cr,lf,'$'
|
||||
oldstk: dw 0
|
||||
stack equ $+128 ; 64-level stack
|
||||
;
|
||||
end
|
||||
dad b
|
||||
inx d
|
||||
jc putdec2
|
||||
lxi b,10
|
||||
dad b
|
||||
xchg
|
||||
mov a,h
|
||||
ora l
|
||||
cnz putdec ; recursive call
|
||||
mov a,e
|
||||
adi '0'
|
||||
call putchr
|
||||
pop h
|
||||
pop d
|
||||
pop b
|
||||
ret
|
||||
;-------------------------------------------------------
|
||||
; data area
|
||||
;-------------------------------------------------------
|
||||
signon: db 'Fibonacci number sequence:',cr,lf,'$'
|
||||
oldstk: dw 0
|
||||
stack equ $+128 ; 64-level stack
|
||||
;
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program numfibo64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessDebutPgm: .asciz "Program 64 bits start. \n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
szMessFinOK: .asciz "Program normal end. \n"
|
||||
szMessErreur: .asciz "Error !!!\n"
|
||||
szMessFibo: .asciz "\nFibonaci numbers :\n"
|
||||
|
||||
.align 4
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
sZoneConv: .skip 24
|
||||
.align 4
|
||||
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main:
|
||||
ldr x0,qAdrszMessDebutPgm
|
||||
bl affichageMess // start message
|
||||
|
||||
ldr x0,qAdrszMessFibo
|
||||
bl affichageMess
|
||||
mov x0,#0 // rank
|
||||
mov x1,#0 // L(0) or L(n-2)
|
||||
mov x2,#1 // L(1) or L(n-1)
|
||||
mov x3,#20 // maxi
|
||||
bl genererFibo
|
||||
|
||||
ldr x0,qAdrszMessFinOK
|
||||
bl affichageMess
|
||||
b 100f
|
||||
99:
|
||||
ldr x0,qAdrszMessErreur // error
|
||||
bl affichageMess
|
||||
mov x0, #1 // return code error
|
||||
b 100f
|
||||
100:
|
||||
mov x8,EXIT
|
||||
svc #0 // system call
|
||||
qAdrszMessDebutPgm: .quad szMessDebutPgm
|
||||
qAdrszMessFinOK: .quad szMessFinOK
|
||||
qAdrszMessErreur: .quad szMessErreur
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
qAdrszMessFibo: .quad szMessFibo
|
||||
/***************************************************/
|
||||
/* Generation Fibonacci number */
|
||||
/***************************************************/
|
||||
/* x0 contains n */
|
||||
/* x1 contains L(0) */
|
||||
/* x2 contains L(1) */
|
||||
/* x3 contains limit number */
|
||||
genererFibo:
|
||||
stp x4,lr,[sp,-16]!
|
||||
stp x5,x6,[sp,-16]!
|
||||
mov x4,x0
|
||||
cmp x3,#0 // end compute ?
|
||||
ble 100f
|
||||
cmp x0,#0 // L(0) ?
|
||||
bne 1f
|
||||
mov x0,x1
|
||||
bl displayNumber
|
||||
add x0,x4,#1 // increment rank
|
||||
sub x3,x3,#1 // decrement counter
|
||||
bl genererFibo
|
||||
b 100f
|
||||
1:
|
||||
cmp x0,#1 // L(1) ?
|
||||
bne 2f
|
||||
mov x0,x2
|
||||
bl displayNumber
|
||||
add x0,x4,#1
|
||||
sub x3,x3,#1
|
||||
bl genererFibo
|
||||
b 100f
|
||||
2:
|
||||
add x5,x2,x1 // add L(n-2) L(n-1)
|
||||
mov x0,x5
|
||||
bl displayNumber
|
||||
add x0,x4,#1
|
||||
sub x3,x3,#1
|
||||
mov x1,x2 // L(n-1) -> L(n-2)
|
||||
mov x2,x5 // number -> L(n-1)
|
||||
bl genererFibo
|
||||
b 100f
|
||||
|
||||
100:
|
||||
ldp x5,x6,[sp],16
|
||||
ldp x4,lr,[sp],16 // TODO: a completer
|
||||
ret
|
||||
/***************************************************/
|
||||
/* display number */
|
||||
/***************************************************/
|
||||
/* x0 contains number */
|
||||
displayNumber:
|
||||
stp x1,lr,[sp,-16]! // TODO: a completer
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10
|
||||
ldr x0,qAdrsZoneConv
|
||||
bl affichageMess
|
||||
ldr x0,qAdrszCarriageReturn
|
||||
bl affichageMess
|
||||
100:
|
||||
ldp x1,lr,[sp],16 // TODO: a completer
|
||||
ret
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
|
||||
|
||||
/***************************************************/
|
||||
/* ROUTINES INCLUDE */
|
||||
/***************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeARM64.inc"
|
||||
21
Task/Fibonacci-sequence/CBASIC/fibonacci-sequence.basic
Normal file
21
Task/Fibonacci-sequence/CBASIC/fibonacci-sequence.basic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
def fn.fib%(n%)
|
||||
p1% = 0
|
||||
p2% = 1
|
||||
if n% = 0 then \
|
||||
f% = 0 \
|
||||
else \
|
||||
for i% = 1 to n%
|
||||
f% = p1% + p2%
|
||||
p2% = p1%
|
||||
p1% = f%
|
||||
next i%
|
||||
fn.fib% = f%
|
||||
return
|
||||
fend
|
||||
|
||||
print "First 20 Fibonacci numbers:"
|
||||
for k% = 1 to 20
|
||||
print fn.fib%(k%);
|
||||
next k%
|
||||
|
||||
end
|
||||
13
Task/Fibonacci-sequence/Dart/fibonacci-sequence-2.dart
Normal file
13
Task/Fibonacci-sequence/Dart/fibonacci-sequence-2.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Iterable<int> fibonacci(int n) sync* {
|
||||
int a = 1, b = 1;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
yield a;
|
||||
|
||||
int temp = a;
|
||||
a = b;
|
||||
b = temp + b;
|
||||
}
|
||||
}
|
||||
|
||||
void main() => print(fibonacci(20));
|
||||
6
Task/Fibonacci-sequence/Dart/fibonacci-sequence-3.dart
Normal file
6
Task/Fibonacci-sequence/Dart/fibonacci-sequence-3.dart
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Iterable<int> fibonacci([int n = 1, int m = 1]) sync* {
|
||||
yield n;
|
||||
yield* fibonacci(m, n + m);
|
||||
}
|
||||
|
||||
void main() => print(fibonacci().take(20));
|
||||
13
Task/Fibonacci-sequence/Dart/fibonacci-sequence-4.dart
Normal file
13
Task/Fibonacci-sequence/Dart/fibonacci-sequence-4.dart
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Iterable<int> fibonacci() sync* {
|
||||
int a = 1, b = 1;
|
||||
|
||||
while (true) {
|
||||
yield a;
|
||||
|
||||
int temp = a;
|
||||
a = b;
|
||||
b = temp + b;
|
||||
}
|
||||
}
|
||||
|
||||
void main() => print(fibonacci().take(20));
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
: fib ( n -- m )
|
||||
dup 2 < [
|
||||
[ 0 1 ] dip [ swap [ + ] keep ] times
|
||||
drop
|
||||
] unless ;
|
||||
! produce the nth fib
|
||||
: fib ( n -- fib ) 1 0 rot [ tuck + ] times drop ; inline
|
||||
|
||||
! produce a list of the first n fibs
|
||||
: fibseq ( n -- fibs ) 1 0 rot [ [ + ] 2keep ] replicate 2nip ; inline
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
: fib ( n -- m )
|
||||
dup 2 < [
|
||||
[ 1 - fib ] [ 2 - fib ] bi +
|
||||
[ 0 1 ] dip [ swap [ + ] keep ] times
|
||||
drop
|
||||
] unless ;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
: fib2 ( x y n -- a )
|
||||
dup 1 <
|
||||
[ 2drop ]
|
||||
[ [ swap [ + ] keep ] dip 1 - fib2 ]
|
||||
if ;
|
||||
: fib ( n -- m ) [ 0 1 ] dip fib2 ;
|
||||
: fib ( n -- m )
|
||||
dup 2 < [
|
||||
[ 1 - fib ] [ 2 - fib ] bi +
|
||||
] unless ;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
USE: math.matrices
|
||||
|
||||
: fib ( n -- m )
|
||||
dup 2 < [
|
||||
[ { { 0 1 } { 1 1 } } ] dip 1 - m^n
|
||||
second second
|
||||
] unless ;
|
||||
: fib2 ( x y n -- a )
|
||||
dup 1 <
|
||||
[ 2drop ]
|
||||
[ [ swap [ + ] keep ] dip 1 - fib2 ]
|
||||
if ;
|
||||
: fib ( n -- m ) [ 0 1 ] dip fib2 ;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
USE: math.matrices
|
||||
|
||||
: fib ( n -- m )
|
||||
dup 2 < [
|
||||
[ { { 0 1 } { 1 1 } } ] dip 1 - m^n
|
||||
second second
|
||||
] unless ;
|
||||
|
|
@ -1,2 +1,4 @@
|
|||
: fib ( n -- fib )
|
||||
0 1 rot 0 ?do over + swap loop drop ;
|
||||
0 1 rot 0 do
|
||||
over + swap
|
||||
loop drop ;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
fibN=: [: {."1 +/\@|.@]^:[&0 1
|
||||
fibN=: ([: +&$:/ <:^:1 2)^:(1&<) M."0
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
fibN 12
|
||||
144
|
||||
fibN i.31
|
||||
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
|
||||
fibN=: [: {."1 +/\@|.@]^:[&0 1
|
||||
|
|
|
|||
4
Task/Fibonacci-sequence/J/fibonacci-sequence-4.j
Normal file
4
Task/Fibonacci-sequence/J/fibonacci-sequence-4.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fibN 12
|
||||
144
|
||||
fibN i.31
|
||||
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040
|
||||
|
|
@ -1 +1 @@
|
|||
{(x(|+\)\1 1)[;1]}
|
||||
+/[;0;1]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{x{x,+/-2#x}/!2}
|
||||
{(x(|+\)\1 1)[;1]}
|
||||
|
|
|
|||
1
Task/Fibonacci-sequence/K/fibonacci-sequence-6.k
Normal file
1
Task/Fibonacci-sequence/K/fibonacci-sequence-6.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
{x{x,+/-2#x}/!2}
|
||||
1
Task/Fibonacci-sequence/K/fibonacci-sequence-7.k
Normal file
1
Task/Fibonacci-sequence/K/fibonacci-sequence-7.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
+\[;0;1]
|
||||
5
Task/Fibonacci-sequence/Nu/fibonacci-sequence.nu
Normal file
5
Task/Fibonacci-sequence/Nu/fibonacci-sequence.nu
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def 'seq fibonacci' [] {
|
||||
generate { {out: $in.0, next: [$in.1 ($in | math sum)]} } [0 1]
|
||||
}
|
||||
|
||||
seq fibonacci | get 7
|
||||
|
|
@ -8,13 +8,16 @@
|
|||
100 100 moveto
|
||||
|
||||
%define the function recursively:
|
||||
/fib { dup
|
||||
3 lt
|
||||
{ pop 1 }
|
||||
{ dup 1 sub fib exch 2 sub fib add }
|
||||
ifelse
|
||||
} def
|
||||
/fib {
|
||||
dup 2 lt
|
||||
{ }
|
||||
{
|
||||
dup 1 sub fib
|
||||
exch 2 sub fib
|
||||
add
|
||||
} ifelse
|
||||
} def
|
||||
|
||||
(Fib\() show n (....) cvs show (\)=) show n fib (.....) cvs show
|
||||
(Fib\() show n (....) cvs show (\) = ) show n fib (.....) cvs show
|
||||
|
||||
showpage
|
||||
34
Task/Fibonacci-sequence/PostScript/fibonacci-sequence-2.ps
Normal file
34
Task/Fibonacci-sequence/PostScript/fibonacci-sequence-2.ps
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
%!PS
|
||||
|
||||
/Courier 16 selectfont
|
||||
|
||||
/fibonacci {
|
||||
dup 2 lt
|
||||
{ }
|
||||
{
|
||||
0 exch
|
||||
1 exch
|
||||
2 exch 1 exch {
|
||||
pop
|
||||
exch
|
||||
1 index
|
||||
add
|
||||
} for
|
||||
exch
|
||||
pop
|
||||
} ifelse
|
||||
} def
|
||||
|
||||
/str 4 string def
|
||||
|
||||
/n 10 def
|
||||
|
||||
72 720 moveto
|
||||
|
||||
0 1 n {
|
||||
fibonacci str cvs
|
||||
str show
|
||||
pop
|
||||
} for
|
||||
|
||||
showpage
|
||||
20
Task/Fibonacci-sequence/SQL/fibonacci-sequence-5.sql
Normal file
20
Task/Fibonacci-sequence/SQL/fibonacci-sequence-5.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
SET @row_count := 10;
|
||||
WITH RECURSIVE fibonacci_row (seq, current_value, next_value) AS
|
||||
(
|
||||
(
|
||||
SELECT
|
||||
CAST(1 AS UNSIGNED INTEGER) AS seq,
|
||||
CAST(0 AS UNSIGNED INTEGER) AS current_value,
|
||||
CAST(1 AS UNSIGNED INTEGER) AS next_value
|
||||
) UNION ALL (
|
||||
SELECT
|
||||
seq + 1 AS seq,
|
||||
next_value AS current_value,
|
||||
current_value + next_value AS next_value
|
||||
FROM fibonacci_row
|
||||
WHERE seq + 1 <= @row_count
|
||||
)
|
||||
)
|
||||
SELECT seq, current_value
|
||||
FROM fibonacci_row
|
||||
;
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
templates nthFibonacci
|
||||
@: {n0: 0"1", n1: 1"1"};
|
||||
1..$ -> @: {n0: $@.n1, n1: $@.n0 + $@.n1};
|
||||
$@.n0!
|
||||
nthFibonacci templates
|
||||
when <|=0|=1> do $ !
|
||||
otherwise ($ - 1 -> #) + ($ - 2 -> #) !
|
||||
end nthFibonacci
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
templates nthFibonacci
|
||||
@: {n0: 0"1", n1: 1"1"};
|
||||
def sign: $ -> \(<0..> 1! <> -1!\);
|
||||
1..$*$sign -> $sign -> #
|
||||
1..$ -> @: {n0: $@.n1, n1: $@.n0 + $@.n1};
|
||||
$@.n0!
|
||||
<=1>
|
||||
@: {n0: $@.n1, n1: $@.n0 + $@.n1};
|
||||
<=-1>
|
||||
@: {n0: $@.n1 - $@.n0, n1: $@.n0};
|
||||
end nthFibonacci
|
||||
|
|
|
|||
|
|
@ -1,16 +1,5 @@
|
|||
templates nthFibonacci
|
||||
{ N: ($)"1", n0: 0"1", n1: 1"1" } -> #
|
||||
when <{ N: <=0"1"> }> do
|
||||
$.n0 !
|
||||
when <{ N: <1"1"..>}> do
|
||||
{ N: $.N - 1"1", n0: $.n1, n1: $.n0 + $.n1} -> #
|
||||
otherwise
|
||||
{ N: $.N + 1"1", n1: $.n0, n0: $.n1 - $.n0} -> #
|
||||
nthFibonacci templates
|
||||
@ set {n0: 0"1", n1: 1"1"};
|
||||
1..$ -> @ set {n0: $@(n1:), n1: $@(n0:) + $@(n1:)};
|
||||
$@(n0:)!
|
||||
end nthFibonacci
|
||||
|
||||
8 -> nthFibonacci -> '$;
|
||||
' -> !OUT::write
|
||||
-5 -> nthFibonacci -> '$;
|
||||
' -> !OUT::write
|
||||
-6 -> nthFibonacci -> '$;
|
||||
' -> !OUT::write
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
templates nthFibonacci
|
||||
@: {n0: 0"1", n1: 1"1"};
|
||||
def sign: $ -> \(<0..> 1! <> -1!\);
|
||||
1..$*$sign -> $sign -> #
|
||||
$@.n0!
|
||||
<=1>
|
||||
@: {n0: $@.n1, n1: $@.n0 + $@.n1};
|
||||
<=-1>
|
||||
@: {n0: $@.n1 - $@.n0, n1: $@.n0};
|
||||
end nthFibonacci
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
nthFibonacci templates
|
||||
@ set {n0: 0"1", n1: 1"1"};
|
||||
sign is $ -> templates
|
||||
when <|0..> do 1!
|
||||
otherwise -1!
|
||||
end;
|
||||
1..$*$sign -> $sign -> !#
|
||||
$@(n0:)!
|
||||
when <|=1> do
|
||||
@ set {n0: $@(n1:), n1: $@(n0:) + $@(n1:)};
|
||||
when <|=-1> do
|
||||
@ set {n0: $@(n1:) - $@(n0:), n1: $@(n0:)};
|
||||
end nthFibonacci
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
templates nthFibonacci
|
||||
{ N: ($)"1", n0: 0"1", n1: 1"1" } -> #
|
||||
when <{ N: <=0"1"> }> do
|
||||
$.n0 !
|
||||
when <{ N: <1"1"..>}> do
|
||||
{ N: $.N - 1"1", n0: $.n1, n1: $.n0 + $.n1} -> #
|
||||
otherwise
|
||||
{ N: $.N + 1"1", n1: $.n0, n0: $.n1 - $.n0} -> #
|
||||
end nthFibonacci
|
||||
|
||||
8 -> nthFibonacci -> '$;
|
||||
' -> !OUT::write
|
||||
-5 -> nthFibonacci -> '$;
|
||||
' -> !OUT::write
|
||||
-6 -> nthFibonacci -> '$;
|
||||
' -> !OUT::write
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
nthFibonacci templates
|
||||
{ N: ($)"1", n0: 0"1", n1: 1"1" } -> # !
|
||||
when <|{ N: <|=0"1"> }> do
|
||||
$(n0:) !
|
||||
when <|{ N: <|1"1"..>}> do
|
||||
{ N: $(N:) - 1"1", n0: $(n1:), n1: $(n0:) + $(n1:)} -> # !
|
||||
otherwise
|
||||
{ N: $(N:) + 1"1", n1: $(n0:), n0: $(n1:) - $(n0:)} -> # !
|
||||
end nthFibonacci
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
!yamlscript/v0
|
||||
|
||||
defn main(n=10):
|
||||
loop [a 0, b 1, i 1]:
|
||||
loop a 0, b 1, i 1:
|
||||
say: a
|
||||
if (i < n):
|
||||
recur: b, (a + b), (i + 1)
|
||||
when i < n:
|
||||
recur: b, (a + b), i.++
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue