Skip to content

Instantly share code, notes, and snippets.

@sntxrr
Last active December 12, 2017 06:17
Show Gist options
  • Select an option

  • Save sntxrr/e58a722206e5c5e189bdf8a00c2da36d to your computer and use it in GitHub Desktop.

Select an option

Save sntxrr/e58a722206e5c5e189bdf8a00c2da36d to your computer and use it in GitHub Desktop.
kinda stucky stuck :(
def self_dividing_numbers(left, right)
# this will iterate through all the input numbers
for i in (left..right)
#puts "We're working on number: #{i}"
#puts "Each digit of #{i} is as follows"
#puts digits(i)
digits(i).each {|d|
(
#puts "Total digits: #{i}"
if d.to_i == 0
#puts "Divide by zero!"
puts "#{i} is NOT self divisible"
elsif d.to_i == 1
#puts "Divide by one!"
#puts "#{i} will always be divisable by 1"
else
divisor = (i % d)
if (divisor == 0)
puts "Divide results for #{i} divided by #{d}: #{divisor}"
end
end
)
}
end
end
def digits(x)
res = []
x.to_s.each_char {|c| res << c.to_i}
res
end
self_dividing_numbers(10, 25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment