Skip to content

Instantly share code, notes, and snippets.

@zspencer
Created January 21, 2012 04:00
Show Gist options
  • Save zspencer/1651203 to your computer and use it in GitHub Desktop.
Save zspencer/1651203 to your computer and use it in GitHub Desktop.
Tell Don't Ask Project Euler #1
#http://projecteuler.net/problem=1
module SumMultiplesOf3And5
def self.below number
max = number - 1
stepify([3,5], max).collect(&:step).reduce(:|).reduce(0, :+)
end
def self.stepify numbers, max
numbers.map { |n| Stepper.new(n, max) }
end
end
class Stepper
def initialize value, max
@value = value
@max = max
end
def step
@value.step(@max, @value).to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment