Skip to content

Instantly share code, notes, and snippets.

@nicholalexander
Created January 10, 2018 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholalexander/44f63f5b6dcc0e035c546ba7183a275b to your computer and use it in GitHub Desktop.
Save nicholalexander/44f63f5b6dcc0e035c546ba7183a275b to your computer and use it in GitHub Desktop.
cracklepop
# Write a program that prints out the numbers 1 to 100 (inclusive). If the number is
# divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop.
# If it's divisible by both 3 and 5, print CracklePop. You can use any language.
module CracklePop
class CracklePop
class << self
def evaluate_and_print(number)
puts evaluate(number)
end
private
def evaluate(number)
return "CracklePop" if crackable?(number) && poppable?(number)
return "Crackle" if crackable?(number)
return "Pop" if poppable?(number)
number
end
def crackable?(number)
number % 3 == 0
end
def poppable?(number)
number % 5 == 0
end
end
end
refine Integer do
def to_crackle_pop
CracklePop.evaluate_and_print(self)
end
end
end
class Blurgh
using CracklePop
def self.run
1.upto 100 do |number|
number.to_crackle_pop
end
end
end
Blurgh.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment