Skip to content

Instantly share code, notes, and snippets.

@timkellogg
Last active August 29, 2015 14:20
Show Gist options
  • Save timkellogg/ff53f231d90d66f51053 to your computer and use it in GitHub Desktop.
Save timkellogg/ff53f231d90d66f51053 to your computer and use it in GitHub Desktop.
Interview Challenges
puts "Enter a number you want to calculate up to in the Fibonacci sequence"
max = gets.chomp
#Fibonacci
sequence = []
0.upto(max.to_i) do |num|
if num > 2
what_to_push = sequence[num - 1] + sequence[num - 2]
sequence << what_to_push
else
sequence << num
end
end
puts "#{sequence}"
Fizzbuzz game
puts "Please enter a number you want to fizzbuzz up to"
user_input = gets.chomp
1.upto(user_input.to_i) do |num|
if num % 15 == 0
puts "FizzBuzz"
elsif num % 3 == 0
puts "Fizz"
elsif num % 5 == 0
puts "Buzz"
else
puts num
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment