Skip to content

Instantly share code, notes, and snippets.

@aeg
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeg/9106579 to your computer and use it in GitHub Desktop.
Save aeg/9106579 to your computer and use it in GitHub Desktop.
@memoized について
@Memoized
def fibo(n) {
def result = (n == 0 || n == 1) ? 1G : fibo(n - 2) + fibo(n - 1)
println "$n: $result"
result
}
println "result:" + fibo(5)
1: 1
0: 1
2: 2
3: 3
4: 5
5: 8
result:8
1: 1
0: 1
1: 1
2: 2
3: 3
0: 1
1: 1
2: 2
1: 1
0: 1
1: 1
2: 2
3: 3
4: 5
5: 8
result:8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment