Skip to content

Instantly share code, notes, and snippets.

@h0tk3y
Last active April 15, 2016 13:32
Show Gist options
  • Select an option

  • Save h0tk3y/9b4e4bc2d9e0eeb9f020193d897621ad to your computer and use it in GitHub Desktop.

Select an option

Save h0tk3y/9b4e4bc2d9e0eeb9f020193d897621ad to your computer and use it in GitHub Desktop.
fun fibonacci(n) {
fibI, fibPrev = 1, 1
for (i 3..n)
fibPrev, fibI = fibI, fibPrev + fibI
fibI
}
from, to = 1, 30
from, x, y, z = fibonacci(5)
<< "Here are the first", to, "Fibonacci numbers:"
for (i from..to) {
<< "fib", i, "is", fibonacci(i)
}
fun fibfib(i) = fibonacci(fibonacci(i))
<< "Gonna count fib(fib(x)), enter x:"
>> x
<< "fibfib is ", fibfib(x)
fun fact(n) {
if (n <= 1) ret 1
n * fact(n-1)
}
<< "3!! =", fact(fact(3))
fun power(m, e) {
r = 1
for (i 1..e)
r = r * m
r
}
fun powerTwo(x) = power(2, x)
fun shl(i, s) = i * powerTwo(s)
<< "4 << 3 =", shl(4, 3)
<< "How old are you?"
>> age
<< "You are at least", age * 365 * 24 * 60 * 60, "seconds old!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment