From b5b18e46e3a5c4daaa3b4613395b1a216a47bc17 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Sun, 23 Oct 2022 11:20:39 -0700 Subject: Initial commit --- .gitignore | 3 +++ .vscode/settings.json | 5 +++++ README.md | 6 ++++++ entries/braxtonh/adam/main.py | 16 ++++++++++++++++ entries/braxtonh/express/index.js | 22 ++++++++++++++++++++++ entries/braxtonh/homework/fib.cpp | 32 ++++++++++++++++++++++++++++++++ entries/braxtonh/homework/fib.hpp | 4 ++++ entries/braxtonh/types/index.ts | 18 ++++++++++++++++++ entries/braxtonh/types/test.ts | 19 +++++++++++++++++++ 9 files changed, 125 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 entries/braxtonh/adam/main.py create mode 100644 entries/braxtonh/express/index.js create mode 100644 entries/braxtonh/homework/fib.cpp create mode 100644 entries/braxtonh/homework/fib.hpp create mode 100644 entries/braxtonh/types/index.ts create mode 100644 entries/braxtonh/types/test.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25ede3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +*.log +*.pem \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d8cb326 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "string": "cpp" + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bf79277 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# fib + +- [`adam`](./entries/braxtonh/adam/main.py) +- [`express`](./entries/braxtonh/express/index.js) +- [`homework`](./entries/braxtonh/homework) +- [`types`](./entries/braxtonh/types/index.ts) diff --git a/entries/braxtonh/adam/main.py b/entries/braxtonh/adam/main.py new file mode 100644 index 0000000..71cb8da --- /dev/null +++ b/entries/braxtonh/adam/main.py @@ -0,0 +1,16 @@ +# from tensorflow.keras.optimizers import Adam +# from tensorflow.keras.models import Sequential +# from tensorflow.keras.layers import Dense + +def main(): + # model = Sequential() + # model.add(Dense(12, input_shape=(8,), activation='relu')) + # model.add(Dense(8, activation='relu')) + # model.add(Dense(1, activation='sigmoid')) + + # model.fit(X, y, epochs=4000) + pass # TODO fill out the rest of this stupid idea + + +if __name__ == '__main__': + main() diff --git a/entries/braxtonh/express/index.js b/entries/braxtonh/express/index.js new file mode 100644 index 0000000..2da6092 --- /dev/null +++ b/entries/braxtonh/express/index.js @@ -0,0 +1,22 @@ +import { get } from "axios"; +import express from "express"; + +const app = express(); + +const getURL = (n) => `/fib?${new URLSearchParams({n})}`; + +app.get("/fib", async (res, req, next) => { + const {n} = req.params; + if (n <= 0) { + res.send(n).status(200); + } else { + const futures = [get(getURL(n - 1)), get(getURL(n - 2))]; + const [nSub1, nSub2] = await Promise.all(futures); + res.send(nSub1 + nSub2).status(200); + } + return next(); +}); + +app.start(); + +// TODO... is this syntax correct??? diff --git a/entries/braxtonh/homework/fib.cpp b/entries/braxtonh/homework/fib.cpp new file mode 100644 index 0000000..900c9d0 --- /dev/null +++ b/entries/braxtonh/homework/fib.cpp @@ -0,0 +1,32 @@ +#include "fib.hpp" + +#include +#include +#include + +using namespace std; + +int Fibonacci::fib(const int n) const +{ + // cout << "start" << endl; + if (n < 0) { + // HOW?? + cout << "wtfff got ( " << n << " )" << endl; + // https://stackoverflow.com/questions/8480640/how-to-throw-a-c-exception + throw invalid_argument("received negative value"); + } else if (n == 0) { + // cout << "********************* LINE 12" << endl; + // https://stackoverflow.com/questions/1451170/in-the-fibonacci-sequence-is-fib0-0-or-1 + return 0; //1; ?????? + } else if (n == 1) { + // cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LINE 15" << endl; + return 1; + } else { + // cout << "GOT TO LINE 19" << endl; + // cout << "got here" << endl; + // int retVal = fib(n - 1) + fib(n - 2); + return fib(n - 1) + fib(n - 2); + // // cout << "here" << endl; + // cout << "returning: (" << retVal << " )" << endl; + } +} diff --git a/entries/braxtonh/homework/fib.hpp b/entries/braxtonh/homework/fib.hpp new file mode 100644 index 0000000..a7bbd30 --- /dev/null +++ b/entries/braxtonh/homework/fib.hpp @@ -0,0 +1,4 @@ +class Fibonacci +{ + int fib(const int n) const; +}; diff --git a/entries/braxtonh/types/index.ts b/entries/braxtonh/types/index.ts new file mode 100644 index 0000000..11f4086 --- /dev/null +++ b/entries/braxtonh/types/index.ts @@ -0,0 +1,18 @@ +type Zero = "😰"; + +type Succ = {prev: N}; + +type Prev = N extends Succ ? P : never; + +type Add = B extends Zero ? A : Succ>>; + +type _Fib = + N extends Zero + ? AccumulatorA + : N extends Succ + ? AccumulatorB + : _Fib, AccumulatorB, Add>; + +type Fib = _Fib>; + +export type {Zero, Succ, Fib}; diff --git a/entries/braxtonh/types/test.ts b/entries/braxtonh/types/test.ts new file mode 100644 index 0000000..2ce83e7 --- /dev/null +++ b/entries/braxtonh/types/test.ts @@ -0,0 +1,19 @@ +import {Zero, Succ, Fib} from "./index"; + +const zero: Zero = "😰"; +const one: Succ = {prev: zero}; +const two: Succ = {prev: one}; +const three: Succ = {prev: two}; +const four: Succ = {prev: three}; +const five: Succ = {prev: four}; +const six: Succ = {prev: five}; +const seven: Succ = {prev: six}; +const eight: Succ = {prev: seven}; + +const fibZero: Fib = zero; +const fibOne: Fib = one; +const fibTwo: Fib = one; +const fibThree: Fib = two; +const fibFour: Fib = three; +const fibFive: Fib = five; +const fibSix: Fib = eight; -- cgit v1.2.3-70-g09d2