aboutsummaryrefslogtreecommitdiff
path: root/entries/ionathanch
diff options
context:
space:
mode:
authorJames Yoo2022-10-24 23:47:51 +0000
committerJames Yoo2022-10-24 23:47:51 +0000
commit03315f012514bdcc5a4f654056f0103abe11eb83 (patch)
tree2b7c6e9233ecb503e7be0d8354483691f9a1e16c /entries/ionathanch
parent0921d8222bb883ea86d51c7200a865a5e4dbc469 (diff)
parent7ed13a92711a35a9c263c1f53e33e308653ae727 (diff)
Merging local with remote main
Diffstat (limited to 'entries/ionathanch')
-rw-r--r--entries/ionathanch/Fib.agda19
-rw-r--r--entries/ionathanch/fib.f9021
2 files changed, 40 insertions, 0 deletions
diff --git a/entries/ionathanch/Fib.agda b/entries/ionathanch/Fib.agda
new file mode 100644
index 0000000..a12b0a5
--- /dev/null
+++ b/entries/ionathanch/Fib.agda
@@ -0,0 +1,19 @@
+
+open import Agda.Builtin.Nat
+open import Agda.Builtin.List
+open import Agda.Builtin.Reflection
+
+data Fib : Nat → Nat → Set where
+ instance F0 : Fib 0 0
+ instance F1 : Fib 1 1
+ instance Fk : ∀ {k n m} → ⦃ Fib k n ⦄ → ⦃ Fib (suc k) m ⦄ → Fib (suc (suc k)) (n + m)
+
+fib' : ∀ k {n} → ⦃ Fib k n ⦄ → Nat
+fib' k {n} ⦃ fib ⦄ = n
+
+macro
+ fib : Term → Term → TC _
+ fib t hole = unify hole (def (quote fib') (arg i t ∷ []))
+ where i = arg-info visible (modality relevant quantity-ω)
+
+{- Get the [n]th Fibonacci number by normalization via C-n `fib [n]`. -}
diff --git a/entries/ionathanch/fib.f90 b/entries/ionathanch/fib.f90
new file mode 100644
index 0000000..3cf1850
--- /dev/null
+++ b/entries/ionathanch/fib.f90
@@ -0,0 +1,21 @@
+PROGRAM main
+ ! The 93rd Fibonacci number is the largest that fits in 64 bits anyway
+ CHARACTER(3) :: kth
+ INTEGER :: k
+ CALL get_command_argument(1, kth)
+ READ(kth, *) k
+ WRITE(*, *) fib(k)
+CONTAINS
+
+PURE RECURSIVE INTEGER*8 FUNCTION fib(k) RESULT(n)
+ INTEGER, INTENT (IN) :: k
+ IF (k == 0) THEN
+ n = 0
+ ELSE IF (k == 1) THEN
+ n = 1
+ ELSE
+ n = fib(k - 1) + fib(k - 2)
+ END IF
+END FUNCTION fib
+
+END PROGRAM