Created
August 19, 2015 11:30
-
-
Save ochaochaocha3/3485650aae710bd4c8b8 to your computer and use it in GitHub Desktop.
2015-08-19 Code Kata2 問題 7
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
# 7 けたの整数 2004XXX は 2, 3, 4, 5, 6, 7, 8 すべての倍数です。 | |
# XXX に入る 3 けたの整数を求めなさい。 | |
# 2 で割り切れるので 2004XXX は偶数 | |
# 約数について | |
# * 8 で割り切れる => 4, 2 でも割り切れる | |
# * 6 で割り切れる => 3 でも割り切れる | |
# ので、[5, 6, 7, 8] で割り切れるものを選べばよい | |
nums = (0..999).select { |n| n % 2 == 0 } | |
answers = nums.select do |n| | |
p m = 2004000 + n | |
[5, 6, 7, 8].all? { |d| m % d == 0 } | |
end | |
puts("2004XXX が 2, 3, 4, 5, 6, 7, 8 で割り切れる XXX:") | |
puts(answers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment