source/euler43.rb
def substring_divisibity(pandigital)
  return false if pandigital[1..3].to_i % 2 != 0
  return false if pandigital[2..4].to_i % 3 != 0
  return false if pandigital[3..5].to_i % 5 != 0
  return false if pandigital[4..6].to_i % 7 != 0
  return false if pandigital[5..7].to_i % 11 != 0
  return false if pandigital[6..8].to_i % 13 != 0
  return false if pandigital[7..9].to_i % 17 != 0
  true
end
# Very direct and obvious way of going about this, but it's a tad slow. Should
# probably think of a faster way to do this eventually.
Very direct and obvious way of going about this, but it's a tad slow. Should
probably think of a faster way to do this eventually.
Very direct and obvious way of going about this but it ' s a tad slow . Should probably think of a faster way to do this eventually .
def substring_divisibity(pandigital)
  return false if pandigital[1..3].to_i % 2 != 0
  return false if pandigital[2..4].to_i % 3 != 0
  return false if pandigital[3..5].to_i % 5 != 0
  return false if pandigital[4..6].to_i % 7 != 0
  return false if pandigital[5..7].to_i % 11 != 0
  return false if pandigital[6..8].to_i % 13 != 0
  return false if pandigital[7..9].to_i % 17 != 0
  true
end
def substring_divisibity ( pandigital ) return false if pandigital [ 1 .. 3 ] . to_i % 2 != 0 return false if pandigital [ 2 .. 4 ] . to_i % 3 != 0 return false if pandigital [ 3 .. 5 ] . to_i % 5 != 0 return false if pandigital [ 4 .. 6 ] . to_i % 7 != 0 return false if pandigital [ 5 .. 7 ] . to_i % 11 != 0 return false if pandigital [ 6 .. 8 ] . to_i % 13 != 0 return false if pandigital [ 7 .. 9 ] . to_i % 17 != 0 true end
Very direct and obvious way of going about this, but it's a tad slow.
Very direct and obvious way of going about this but it ' s a tad slow .
pandigital