Created
June 21, 2013 13:33
-
-
Save surrealdetective/5831168 to your computer and use it in GitHub Desktop.
#https://piazza.com/class#summer2013/002ruby/253
#What is the smallest number that is divisble by every number between 1 - 20?
This file contains 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
#https://piazza.com/class#summer2013/002ruby/253 | |
#What is the smallest number that is divisble by every number between 1 - 20? | |
# def all_divisible(num) | |
# smallest = [] | |
# (1..num).each do |test| | |
# if num % test == 0 | |
# smallest << test | |
# end | |
# end | |
# smallest.last | |
# end | |
#puts all_divisible(20) | |
#the plan: | |
#look at every number between 1 and 20 | |
#if it is divisible by 20, then add it to the array | |
#take the last array as the return | |
#fail, i did not do the right thing. | |
#instead, i need to make sure that all numbers between 1 and 20 | |
#are the_answer % (and number between 1 and 20) == 0 | |
# def all_divisible(range) | |
# divides_all = range | |
# has_not_divided_range = true | |
# while has_not_divided_range | |
# (1..range).each do |test| | |
# if divides_all % test != 0 | |
# divides_all += 1 | |
# all_divisible(range) | |
# end | |
# end | |
# has_not_divided_range = false | |
# end | |
# divides_all | |
# end | |
#failed again... stack too deep. maybe try a different approach? | |
#puts all_divisible(20) | |
#plan: | |
#focus on doing 20 for now, then make it a variable later | |
#use what you know to limit the responses | |
def all_divisible | |
has_not_divided_20 = true | |
while has_not_divided_20 | |
all_the_ | |
while testing >= 1 | |
testing -= 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment