diff options
-rw-r--r-- | entries/jlouis/README.md | 11 | ||||
-rw-r--r-- | entries/jlouis/bin/dune | 4 | ||||
-rw-r--r-- | entries/jlouis/bin/main.ml | 1 | ||||
-rw-r--r-- | entries/jlouis/dune-project | 3 | ||||
-rw-r--r-- | entries/jlouis/fib.opam | 0 | ||||
-rw-r--r-- | entries/jlouis/lib/dune | 5 | ||||
-rw-r--r-- | entries/jlouis/lib/fib.ml | 72 | ||||
-rw-r--r-- | entries/jlouis/shell.nix | 11 | ||||
-rw-r--r-- | entries/jyoo980/aspectj/Fibonacci.aj | 21 | ||||
-rw-r--r-- | people.json | 78 |
10 files changed, 174 insertions, 32 deletions
diff --git a/entries/jlouis/README.md b/entries/jlouis/README.md new file mode 100644 index 0000000..2f14678 --- /dev/null +++ b/entries/jlouis/README.md @@ -0,0 +1,11 @@ +# Fib like only I would write it + +## Instructions + +Everything is in `lib/fib.ml` and the rest is just scaffolding. + +Use nix to get an OCaml development environment. + +Use dune to build: `dune build` +Use dune to run: `dune exec fib` +Use dune to test: `dune test` diff --git a/entries/jlouis/bin/dune b/entries/jlouis/bin/dune new file mode 100644 index 0000000..6d6e5f9 --- /dev/null +++ b/entries/jlouis/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name fib) + (name main) + (libraries fib)) diff --git a/entries/jlouis/bin/main.ml b/entries/jlouis/bin/main.ml new file mode 100644 index 0000000..ca2c25e --- /dev/null +++ b/entries/jlouis/bin/main.ml @@ -0,0 +1 @@ +let _ = print_endline ("Mok'ra: " ^ string_of_int (Fib.Orc.iter 10))
\ No newline at end of file diff --git a/entries/jlouis/dune-project b/entries/jlouis/dune-project new file mode 100644 index 0000000..ff9f42f --- /dev/null +++ b/entries/jlouis/dune-project @@ -0,0 +1,3 @@ +(lang dune 3.4) + +(name fib) diff --git a/entries/jlouis/fib.opam b/entries/jlouis/fib.opam new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/entries/jlouis/fib.opam diff --git a/entries/jlouis/lib/dune b/entries/jlouis/lib/dune new file mode 100644 index 0000000..865a6c5 --- /dev/null +++ b/entries/jlouis/lib/dune @@ -0,0 +1,5 @@ +(library + (name fib) + (inline_tests) + (preprocess + (pps ppx_inline_test))) diff --git a/entries/jlouis/lib/fib.ml b/entries/jlouis/lib/fib.ml new file mode 100644 index 0000000..9353c6a --- /dev/null +++ b/entries/jlouis/lib/fib.ml @@ -0,0 +1,72 @@ +module type BASIS = + sig + type t + val one : t + val out : t -> int + val to_string : t -> string + end + +module type MONOIDIC = + sig + include BASIS + val concat : t -> t -> t + end + +(* Single Tuple, Multiple Data *) +module STMD : MONOIDIC = + struct + type t = int * int * int * int + + let one = (1, 1, + 1, 0) + + let out (_, _, _, x) = x + + let to_string (a,b,c,d) = "(" ^ (string_of_int a) ^ ", " + ^ (string_of_int b) ^ ", " + ^ (string_of_int c) ^ ", " + ^ (string_of_int d) ^ ")" + + let concat (a11, a12, a21, a22) (b11, b12, b21, b22) = + let muladd a x b y = (a*x) + (b*y) in + (muladd a11 b11 a12 b21, + muladd a11 b12 a12 b22, + muladd a21 b11 a22 b21, + muladd a21 b12 a22 b22) + end + +module MkLinear(M : MONOIDIC) = + struct + let iter n = + let rec loop n acc = + match n with + | 0 -> acc + | k -> loop (k-1) (M.concat M.one acc) + in + M.out (loop n M.one) + + end + +module MkLog(M : MONOIDIC) = + struct + let iter n = + let rec loop y x k = + if k = 0 then y + else if k mod 2 = 0 then loop y (M.concat x x) (k/2) + else loop (M.concat y x) (M.concat x x) ((k-1)/2) + in + M.out (loop M.one M.one n) + end + +module Kobold = MkLinear(STMD) (* You no take candle! *) +module Orc = MkLog(STMD) (* Mok'ra *) + +let%test _ = Kobold.iter 10 = 55 +let%test _ = Kobold.iter 0 = 0 +let%test _ = Orc.iter 0 = 0 +let%test _ = Orc.iter 1 = 1 +let%test _ = Orc.iter 2 = 1 +let%test _ = Orc.iter 3 = 2 +let%test _ = Orc.iter 4 = 3 +let%test _ = Orc.iter 5 = 5 +let%test _ = Orc.iter 10 = 55 diff --git a/entries/jlouis/shell.nix b/entries/jlouis/shell.nix new file mode 100644 index 0000000..d5e27a3 --- /dev/null +++ b/entries/jlouis/shell.nix @@ -0,0 +1,11 @@ +let + pkgs = import <nixpkgs> {}; + # choose the ocaml version you want to use + ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_14; +in +pkgs.mkShell { + # build tools + nativeBuildInputs = with ocamlPackages; [ ocaml utop findlib dune_3 ocaml-lsp ppx_inline_test ]; + # dependencies + buildInputs = with ocamlPackages; [ ocamlgraph ]; +} diff --git a/entries/jyoo980/aspectj/Fibonacci.aj b/entries/jyoo980/aspectj/Fibonacci.aj new file mode 100644 index 0000000..39dfd8a --- /dev/null +++ b/entries/jyoo980/aspectj/Fibonacci.aj @@ -0,0 +1,21 @@ +public aspect Fibonnacci { + + pointcut mainInvocation(): call(* Main.*(*)); + + void before(): mainInvocation() { + // Nice + int n = 69; + System.out.println("The 69th fibonacci number is: " + fibonacci(n)); + } + + public int fibonacci(int n) { + int prev = 0; + int curr = 1; + for (int i = 0; i < n; i++) { + int tmp = prev; + prev = curr; + curr = prev + tmp; + } + return prev; + } +} diff --git a/people.json b/people.json index 55b1ad4..f7edd70 100644 --- a/people.json +++ b/people.json @@ -57,6 +57,17 @@ ] }, { + "github": "jlouis", + "name": "Jesper Louis Andersen", + "title": "BSc, Copenhagen University", + "entries": [ + { + "name": "ocaml", + "link": "./entries/jlouis/lib/fib.ml" + } + ] + }, + { "github": "funemy", "name": "Yanze Li", "title": "PhD Student, UBC", @@ -91,29 +102,32 @@ { "name": "vintage-htdp", "link": "./entries/jyoo980/vintage-htdp/fib.rkt" + }, + { + "name": "aspectj", + "link": "./entries/jyoo980/aspectj/Fibonacci.aj" + } + ] + }, + { + "github": "rctcwyvrn", + "name": "Lily Lin", + "title": "BSc, UBC", + "entries": [ + { + "name": "fractran", + "link": "./entries/lilylin/fractran/fractran.py" + }, + { + "name": "cursed-x86", + "link": "./entries/lilylin/cursed-x86/" + }, + { + "name": "mov", + "link": "./entries/lilylin/mov/mov.s" } - ] }, - { - "github": "rctcwyvrn", - "name": "Lily Lin", - "title": "BSc, UBC", - "entries": [ - { - "name": "fractran", - "link": "./entries/lilylin/fractran/fractran.py" - }, - { - "name": "cursed-x86", - "link": "./entries/lilylin/cursed-x86/" - }, - { - "name": "mov", - "link": "./entries/lilylin/mov/mov.s" - } - ] - }, { "github": "lizard-business", "name": "rhiannon morris", @@ -247,17 +261,17 @@ } ] }, - { - "github": "StuartLiv", - "name": "Stuart Livingstone", - "title": "BSc Student, UBC", - "entries": [ - { - "name": "ThetaFibN", - "link": "./entries/StuartLiv/ThetaFibN.java" - } - ] - }, + { + "github": "StuartLiv", + "name": "Stuart Livingstone", + "title": "BSc Student, UBC", + "entries": [ + { + "name": "ThetaFibN", + "link": "./entries/StuartLiv/ThetaFibN.java" + } + ] + }, { "github": "Tarcisio-Teixeira", "name": "TarcĂsio Teixeira", @@ -383,4 +397,4 @@ } ] } -] +]
\ No newline at end of file |