Last active
December 12, 2017 06:17
-
-
Save sntxrr/e58a722206e5c5e189bdf8a00c2da36d to your computer and use it in GitHub Desktop.
kinda stucky stuck :(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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