aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ewert2022-10-24 22:42:38 +0000
committerDavid Ewert2022-10-24 22:42:38 +0000
commitdd5fef744a98521bc586b149272580456405ec8f (patch)
tree6776febddaa53b4b6ac3be1dffde074f10dd8b91
parent7ed13a92711a35a9c263c1f53e33e308653ae727 (diff)
Added Fib
-rw-r--r--entries/dewert99/fib.rs22
-rw-r--r--people.json11
2 files changed, 33 insertions, 0 deletions
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<const N: usize>() -> [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<u64> {
+ if n > MAX {
+ None // Fib of n wouldn't fit in 64-bits
+ } else {
+ Some(FIB[n])
+ }
+}
diff --git a/people.json b/people.json
index a8e6e56..16b2be7 100644
--- a/people.json
+++ b/people.json
@@ -288,4 +288,15 @@
}
]
}
+ {
+ "github": "dewert99",
+ "name": "David Ewert",
+ "title": "MSc Student, UBC",
+ "entries": [
+ {
+ "name": "tex",
+ "link": "./entries/dewert99/fib.rs"
+ }
+ ]
+ }
]