Skip to content

Instantly share code, notes, and snippets.

@phillipoertel
Created October 28, 2009 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phillipoertel/220289 to your computer and use it in GitHub Desktop.
Save phillipoertel/220289 to your computer and use it in GitHub Desktop.
#
# a smoke test to check basic programming skills
#
# Task:
# - print out the numbers 1 to 100
# - output "foo" for every number divisible by 3
# - output "bar" for every number divisible by 5
# - output "foobar" for every number divisible by 3 and 5
#
(1..100).each do |number|
case
when (number % 3) == 0 && (number % 5) == 0
puts "#{number} foobar"
when (number % 3) == 0
puts "#{number} foo"
when (number % 5) == 0
puts "#{number} bar"
end
end
(1..100).each do |number|
if (number % 3 == 0 && number % 5 == 0)
puts "#{number} foobar"
elsif (number % 3 == 0)
puts "#{number} foo"
elsif (number % 5 == 0)
puts "#{number} bar"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment