# 039: Recursion
# Functions that call themselves

# Factorial
factorial(n):
  if n <= 1:
    return 1
  return n * factorial(n - 1)

show factorial(5)  # 120 (5 * 4 * 3 * 2 * 1)

# Fibonacci
fibonacci(n):
  if n <= 1:
    return n
  return fibonacci(n - 1) + fibonacci(n - 2)

show fibonacci(7)  # 13

# Sum of list
sum_list(numbers):
  if numbers.length == 0:
    return 0
  return numbers[0] + sum_list(numbers[1:])

show sum_list([1, 2, 3, 4, 5])  # 15

# Countdown
countdown(n):
  if n <= 0:
    show "Blast off!"
    return

  show n
  countdown(n - 1)

countdown(5)
