aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBraxton Hall2022-12-18 09:10:42 +0000
committerGitHub2022-12-18 09:10:42 +0000
commit883f7d6767492bd576f37f2b5fd4ada26e55ac83 (patch)
treee11b42b9d950405e23d2e3c7194151b174dfb63e
parent754ba58f00791f21eaf47a8be085df2bffc857d4 (diff)
parent612feb8cad7eb6a67ef69cef117e2b0ffa87b184 (diff)
Merge pull request #94 from williamvietnguyen/fibberoni
Fibberoni
-rw-r--r--entries/williamvietnguyen/fibberoni.c39
-rw-r--r--entries/williamvietnguyen/makefile5
-rw-r--r--people.json11
3 files changed, 55 insertions, 0 deletions
diff --git a/entries/williamvietnguyen/fibberoni.c b/entries/williamvietnguyen/fibberoni.c
new file mode 100644
index 0000000..e3c3c4d
--- /dev/null
+++ b/entries/williamvietnguyen/fibberoni.c
@@ -0,0 +1,39 @@
+/* fib.c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int fibberoni_compute(int n, int* cache) {
+ if (n < 2) {
+ return n;
+ }
+ if (cache[n] != -1) {
+ return cache[n];
+ }
+ cache[n] = fibberoni_compute(n - 1, cache) + fibberoni_compute(n - 2, cache);
+ return cache[n];
+}
+
+int fibberoni(int n) {
+ int sign, result, cache[abs(n) + 1];
+ sign = (n < 0) ? -1 : 1;
+ memset(cache, -1, sizeof(int) * (abs(n) + 1));
+ result = fibberoni_compute(abs(n), cache);
+ return sign * result;
+}
+
+void usage() {
+ printf("Usage: ./fibberoni -12\n");
+ exit(EXIT_FAILURE);
+}
+
+int main(int argc, char** argv) {
+ int n, result;
+ if (argc < 2) {
+ usage();
+ }
+ n = atoi(argv[1]);
+ result = fibberoni(n);
+ printf("%d", result);
+ exit(EXIT_SUCCESS);
+}
diff --git a/entries/williamvietnguyen/makefile b/entries/williamvietnguyen/makefile
new file mode 100644
index 0000000..78843cb
--- /dev/null
+++ b/entries/williamvietnguyen/makefile
@@ -0,0 +1,5 @@
+all:
+ gcc -o fibberoni fibberoni.c
+
+clean:
+ -rm -f fibberoni \ No newline at end of file
diff --git a/people.json b/people.json
index 897a585..defd08b 100644
--- a/people.json
+++ b/people.json
@@ -721,5 +721,16 @@
}
]
+ },
+ {
+ "github": "williamvietnguyen",
+ "name": "William Nguyen",
+ "title": "Software Engineer, Bloomberg LP",
+ "entries": [
+ {
+ "name": "fibberoni",
+ "link": "./entries/williamvietnguyen/fibberoni.c"
+ }
+ ]
}
]