aboutsummaryrefslogtreecommitdiff
path: root/entries
diff options
context:
space:
mode:
Diffstat (limited to 'entries')
-rw-r--r--entries/kekerr/fib.ts16
-rw-r--r--entries/nwoeanhinnogaehr/fib.asm12
-rw-r--r--entries/patricebelleville/fib.py13
3 files changed, 35 insertions, 6 deletions
diff --git a/entries/kekerr/fib.ts b/entries/kekerr/fib.ts
new file mode 100644
index 0000000..cc42fcf
--- /dev/null
+++ b/entries/kekerr/fib.ts
@@ -0,0 +1,16 @@
+function fibonacci(n: number): string {
+ if (n <= 0) {
+ return "Surely that's a mistake! We can't give you anything interesting!";
+ }
+
+ if (n == 1) {
+ return "This one's easy: [1]";
+ }
+
+ const seq = [1, 1];
+ for(let i = 2; i < n; i++) {
+ seq.push(seq[i-1] + seq[i-2]);
+ }
+
+ return "Fibonacci this: " + seq.toString();
+}
diff --git a/entries/nwoeanhinnogaehr/fib.asm b/entries/nwoeanhinnogaehr/fib.asm
index 26ccf11..729958f 100644
--- a/entries/nwoeanhinnogaehr/fib.asm
+++ b/entries/nwoeanhinnogaehr/fib.asm
@@ -25,25 +25,25 @@ entry:
loop:
mov eax,esi
push 10
- pop ebp
- push ebp
- jmp format
+ mov ecx,esp
+ jmp skip
dw $20 ; e_phentsize
dw 1 ; e_phnum
+skip:
+ pop ebp
format:
cdq
div ebp
inc ebx
- dec esp
+ dec ecx
or edx,'0'
- mov [esp],dl
+ mov [ecx],dl
test eax,eax
jnz format
print:
mov al,4
- mov ecx,esp
mov edx,ebx
mov bl,1
int 0x80
diff --git a/entries/patricebelleville/fib.py b/entries/patricebelleville/fib.py
new file mode 100644
index 0000000..767ce11
--- /dev/null
+++ b/entries/patricebelleville/fib.py
@@ -0,0 +1,13 @@
+def fibonacci(n):
+ return fib_helper(n, 0, 1)
+
+def fib_helper(n, prev, curr):
+ # Base cases
+ if n < 0:
+ raise ValueError('Negative argument to fibonnaci')
+ if n == 0:
+ return prev
+ if n == 1:
+ return curr
+ return fib_helper(n-1, curr, prev + curr)
+