diff options
Diffstat (limited to 'entries/jyoo980')
-rw-r--r-- | entries/jyoo980/aspectj/Fibonacci.aj | 21 | ||||
-rw-r--r-- | entries/jyoo980/vintage-htdp/fib.rkt | 17 |
2 files changed, 38 insertions, 0 deletions
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/entries/jyoo980/vintage-htdp/fib.rkt b/entries/jyoo980/vintage-htdp/fib.rkt new file mode 100644 index 0000000..697c17b --- /dev/null +++ b/entries/jyoo980/vintage-htdp/fib.rkt @@ -0,0 +1,17 @@ +;; Natural -> Natural +;; given n, produce the nth fibonacci number +(check-expect (fib 0) 0) +(check-expect (fib 1) 1) +(check-expect (fib 2) 1) +(check-expect (fib 7) 13) + +; (define (fib n) 0) ; stub + +;<template from Natural> +(define (fib n) + (cond + [(zero? n) 0] + [else + (if (= n 1) + 1 + (+ (fib (sub1 n)) (fib (- n 2))))])) |