source/euler26.rb
# Watch as I recreate the algorothm for long division
Watch as I recreate the algorothm for long division
Watch as I recreate the algorothm for long division
def divide(divisor)
    return 0 if self == 0
    results = []
    last_result = self.divmod(divisor)
    remainder = self
    until remainder == 0 or results.include?(last_result)
      results << last_result
      remainder *= 10
      last_result = remainder.divmod(divisor)
      remainder = remainder % divisor
    end
    results << last_result if remainder == 0
    results.map {|i| i[0]}[1..]
  end
def divide ( divisor ) return 0 if self == 0 results = [ ] last_result = self . divmod ( divisor ) remainder = self until remainder == 0 or results . include? ( last_result ) results << last_result remainder *= 10 last_result = remainder . divmod ( divisor ) remainder = remainder % divisor end results << last_result if remainder == 0 results . map { | i | i [ 0 ] } [ 1 .. ] end
Watch as I recreate the algorothm for long division
Watch as I recreate the algorothm for long division
divisor