aboutsummaryrefslogtreecommitdiff
path: root/entries/braxtonh/types/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'entries/braxtonh/types/index.ts')
-rw-r--r--entries/braxtonh/types/index.ts18
1 files changed, 18 insertions, 0 deletions
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<N> = {prev: N};
+
+type Prev<N> = N extends Succ<infer P> ? P : never;
+
+type Add<A, B> = B extends Zero ? A : Succ<Add<A, Prev<B>>>;
+
+type _Fib<N, AccumulatorA, AccumulatorB> =
+ N extends Zero
+ ? AccumulatorA
+ : N extends Succ<Zero>
+ ? AccumulatorB
+ : _Fib<Prev<N>, AccumulatorB, Add<AccumulatorA, AccumulatorB>>;
+
+type Fib<N> = _Fib<N, Zero, Succ<Zero>>;
+
+export type {Zero, Succ, Fib};