Created
May 16, 2018 13:12
-
-
Save Victorgf87/5416651e03a625d39226962fb885a261 to your computer and use it in GitHub Desktop.
Codigo de la caja
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
def allpairs(num) | |
num.to_s.chars.all?{|c| c.to_i%2==0} | |
end | |
def first_and_last_equals(num) | |
chars=num.to_s.chars | |
chars[0] == chars[-1] | |
end | |
def first_one_third_of_fifth(num) | |
chars=num.to_s.chars | |
chars[0].to_i == chars[4].to_i/3.0 | |
end | |
def first_one_is_half_of_third(num) | |
chars=num.to_s.chars | |
chars[0].to_i== chars[2].to_i/2.0 | |
end | |
def second_is_lowest(num) | |
chars=num.to_s.chars.map{|x| x.to_i} | |
min=chars.min | |
return false unless min==chars[1] | |
chars.delete_at(1) | |
!chars.include?(min) | |
end | |
def last_one_is_fourth_less_fifth(num) | |
chars=num.to_s.chars | |
chars[-1].to_i==chars[3].to_i-chars[4].to_i | |
end | |
def check(num) | |
allpairs(num) and first_and_last_equals(num) and first_one_third_of_fifth(num) and first_one_is_half_of_third(num) and second_is_lowest(num) and last_one_is_fourth_less_fifth(num) | |
end | |
num=200000 | |
while num<888888 do | |
num+=2 | |
if(check(num)) then | |
p "Answer is #{num}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment