From 77ffde450e92ffe6527c35ffc2383b17d4c04f68 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Sun, 23 Oct 2022 12:27:49 -0700 Subject: Rename directory to use GitHub ID --- entries/braxtonhall/adam/main.py | 16 ++++++++++++++++ entries/braxtonhall/express/index.js | 22 ++++++++++++++++++++++ entries/braxtonhall/homework/fib.cpp | 32 ++++++++++++++++++++++++++++++++ entries/braxtonhall/homework/fib.hpp | 4 ++++ entries/braxtonhall/types/index.ts | 18 ++++++++++++++++++ entries/braxtonhall/types/test.ts | 19 +++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 entries/braxtonhall/adam/main.py create mode 100644 entries/braxtonhall/express/index.js create mode 100644 entries/braxtonhall/homework/fib.cpp create mode 100644 entries/braxtonhall/homework/fib.hpp create mode 100644 entries/braxtonhall/types/index.ts create mode 100644 entries/braxtonhall/types/test.ts (limited to 'entries/braxtonhall') diff --git a/entries/braxtonhall/adam/main.py b/entries/braxtonhall/adam/main.py new file mode 100644 index 0000000..71cb8da --- /dev/null +++ b/entries/braxtonhall/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/braxtonhall/express/index.js b/entries/braxtonhall/express/index.js new file mode 100644 index 0000000..2da6092 --- /dev/null +++ b/entries/braxtonhall/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/braxtonhall/homework/fib.cpp b/entries/braxtonhall/homework/fib.cpp new file mode 100644 index 0000000..900c9d0 --- /dev/null +++ b/entries/braxtonhall/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/braxtonhall/homework/fib.hpp b/entries/braxtonhall/homework/fib.hpp new file mode 100644 index 0000000..a7bbd30 --- /dev/null +++ b/entries/braxtonhall/homework/fib.hpp @@ -0,0 +1,4 @@ +class Fibonacci +{ + int fib(const int n) const; +}; diff --git a/entries/braxtonhall/types/index.ts b/entries/braxtonhall/types/index.ts new file mode 100644 index 0000000..11f4086 --- /dev/null +++ b/entries/braxtonhall/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/braxtonhall/types/test.ts b/entries/braxtonhall/types/test.ts new file mode 100644 index 0000000..2ce83e7 --- /dev/null +++ b/entries/braxtonhall/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