Last active
July 29, 2020 11:55
-
-
Save caius/1489f7b45a7fe18e5fed052070f7f161 to your computer and use it in GitHub Desktop.
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
# five digit number | |
# two of the digits are the same | |
# four of the digits are odd | |
# number is higher than 40010 | |
# number is higher than 45000 | |
# digit sum is 16 | |
# five digit, upper/lower bounds | |
candidates = (40011..44999).select { |i| | |
# two digits are the same | |
digits = i.to_s.split("") | |
digits.uniq.size == 4 | |
}.select { |i| | |
# digit sum | |
i.to_s.split("").map(&:to_i).inject(:+) == 16 | |
}.select { |i| | |
# four digits are odd | |
digits = i.to_s.split("").map(&:to_i) | |
digits.count(&:odd?) == 4 | |
} | |
candidates | |
# => [41137, | |
# 41173, | |
# 41317, | |
# 41335, | |
# 41353, | |
# 41371, | |
# 41533, | |
# 41713, | |
# 41731, | |
# 43117, | |
# 43135, | |
# 43153, | |
# 43171, | |
# 43315, | |
# 43351, | |
# 43513, | |
# 43531, | |
# 43711] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment