Skip to content

Instantly share code, notes, and snippets.

@ariejan
Created January 26, 2015 09:49
Show Gist options
  • Save ariejan/537680134081dbe3c468 to your computer and use it in GitHub Desktop.
Save ariejan/537680134081dbe3c468 to your computer and use it in GitHub Desktop.
# Print each value in the list as n^2
list = [1, 2, 3, 4, 5, 6, 7]
def print_list(list)
return if list.empty?
n = list.shift # Grabs the first element, removes it from list
result = n**2
puts "#{n}^2 = #{result}"
print_list(list)
end
print_list(list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment