From dd5fef744a98521bc586b149272580456405ec8f Mon Sep 17 00:00:00 2001 From: David Ewert Date: Mon, 24 Oct 2022 15:42:38 -0700 Subject: Added Fib --- entries/dewert99/fib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 entries/dewert99/fib.rs (limited to 'entries/dewert99') diff --git a/entries/dewert99/fib.rs b/entries/dewert99/fib.rs new file mode 100644 index 0000000..b1744d5 --- /dev/null +++ b/entries/dewert99/fib.rs @@ -0,0 +1,22 @@ +const MAX: usize = 94; + +const fn fibc() -> [u64; N] { + let mut res = [0; N]; + res[1] = 1; + let mut i = 2; + while i < N { + res[i] = res[i - 1] + res[i - 2]; + i += 1; + } + res +} + +static FIB: [u64; MAX] = fibc(); + +pub fn fib(n: usize) -> Option { + if n > MAX { + None // Fib of n wouldn't fit in 64-bits + } else { + Some(FIB[n]) + } +} -- cgit v1.2.3-70-g09d2 From b707a7103789116363427bdd248007b61d527196 Mon Sep 17 00:00:00 2001 From: David Ewert Date: Mon, 24 Oct 2022 16:01:26 -0700 Subject: >= --- entries/dewert99/fib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entries/dewert99') diff --git a/entries/dewert99/fib.rs b/entries/dewert99/fib.rs index b1744d5..ecf0a85 100644 --- a/entries/dewert99/fib.rs +++ b/entries/dewert99/fib.rs @@ -14,7 +14,7 @@ const fn fibc() -> [u64; N] { static FIB: [u64; MAX] = fibc(); pub fn fib(n: usize) -> Option { - if n > MAX { + if n >= MAX { None // Fib of n wouldn't fit in 64-bits } else { Some(FIB[n]) -- cgit v1.2.3-70-g09d2 From 40fdd4d0694f2dc0dd394901dad9884d277459db Mon Sep 17 00:00:00 2001 From: David Ewert Date: Mon, 24 Oct 2022 16:06:31 -0700 Subject: Added compiled version --- entries/dewert99/fib_compiled | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 entries/dewert99/fib_compiled (limited to 'entries/dewert99') diff --git a/entries/dewert99/fib_compiled b/entries/dewert99/fib_compiled new file mode 100644 index 0000000..0a0d3a8 --- /dev/null +++ b/entries/dewert99/fib_compiled @@ -0,0 +1,13 @@ +example::fib: + cmp rdi, 94 + jb .LBB0_3 + xor eax, eax + ret +.LBB0_3: + lea rax, [rip + example::FIB] + mov rdx, qword ptr [rax + 8*rdi] + mov eax, 1 + ret + +example::FIB: + .ascii "\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\003\000\000\000\000\000\000\000\005\000\000\000\000\000\000\000\b\000\000\000\000\000\000\000\r\000\000\000\000\000\000\000\025\000\000\000\000\000\000\000\"\000\000\000\000\000\000\0007\000\000\000\000\000\000\000Y\000\000\000\000\000\000\000\220\000\000\000\000\000\000\000\351\000\000\000\000\000\000\000y\001\000\000\000\000\000\000b\002\000\000\000\000\000\000\333\003\000\000\000\000\000\000=\006\000\000\000\000\000\000\030\n\000\000\000\000\000\000U\020\000\000\000\000\000\000m\032\000\000\000\000\000\000\302*\000\000\000\000\000\000/E\000\000\000\000\000\000\361o\000\000\000\000\000\000 \265\000\000\000\000\000\000\021%\001\000\000\000\000\0001\332\001\000\000\000\000\000B\377\002\000\000\000\000\000s\331\004\000\000\000\000\000\265\330\007\000\000\000\000\000(\262\f\000\000\000\000\000\335\212\024\000\000\000\000\000\005=!\000\000\000\000\000\342\3075\000\000\000\000\000\347\004W\000\000\000\000\000\311\314\214\000\000\000\000\000\260\321\343\000\000\000\000\000y\236p\001\000\000\000\000)pT\002\000\000\000\000\242\016\305\003\000\000\000\000\313~\031\006\000\000\000\000m\215\336\t\000\000\000\0008\f\370\017\000\000\000\000\245\231\326\031\000\000\000\000\335\245\316)\000\000\000\000\202?\245C\000\000\000\000_\345sm\000\000\000\000\341$\031\261\000\000\000\000@\n\215\036\001\000\000\000!/\246\317\001\000\000\000a93\356\002\000\000\000\202h\331\275\004\000\000\000\343\241\f\254\007\000\000\000e\n\346i\f\000\000\000H\254\362\025\024\000\000\000\255\266\330\177 \000\000\000\365b\313\2254\000\000\000\242\031\244\025U\000\000\000\227|o\253\211\000\000\0009\226\023\301\336\000\000\000\320\022\203lh\001\000\000\t\251\226-G\002\000\000\331\273\031\232\257\003\000\000\342d\260\307\366\005\000\000\273 \312a\246\t\000\000\235\205z)\235\017\000\000X\246D\213C\031\000\000\365+\277\264\340(\000\000M\322\003@$B\000\000B\376\302\364\004k\000\000\217\320\3064)\255\000\000\321\316\211).\030\001\000`\237P^W\305\001\0001n\332\207\205\335\002\000\221\r+\346\334\242\004\000\302{\005nb\200\007\000S\2110T?#\f\000\025\0056\302\241\243\023\000h\216f\026\341\306\037\000}\223\234\330\202j3\000\345!\003\357c1S\000b\265\237\307\346\233\206\000G\327\242\266J\315\331\000\251\214B~1i`\001\360c\3454|6:\002\231\360'\263\255\237\232\003\211T\r\350)\326\324\005\"E5\233\327uo\t\253\231B\203\001LD\017\315\336w\036\331\301\263\030xx\272\241\332\r\370'EW2\300\263\317\253@\275\317\354a\216\335\243h\002'\037\"B\255O\251" -- cgit v1.2.3-70-g09d2