-
-
Save nilium/d2fbec2e3705f5e38069 to your computer and use it in GitHub Desktop.
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
# Attempts to compute all possible numbers in (0, 1000) that are: | |
# - even | |
# - only contain the digits { 0 1 3 4 6 7 9 } | |
# - both with repeating and non-repeating digits (all digits are unique) | |
[1,!1].map{|u|(?2..'996').step(2).select{|i|v=731;i.chars.all?{|k|k=1<<k.to_i;v&k!=0&&(!u||v&=~k)}}} |
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 numbers_containing_digits(range, digits, uniq = false) | |
digits = digits.chars if digits.kind_of? String | |
range.select do |i| | |
i.even? && i.to_s.chars.each_with_object(digits.dup).all? do |k, valids| | |
uniq ? valids.delete(k) : valids.include?(k) | |
end | |
end | |
end | |
POSSIBLE = "0134679" | |
NUM_RANGE = 1 ... 1000 | |
numbers_containing_digits(NUM_RANGE, POSSIBLE, false) | |
numbers_containing_digits(NUM_RANGE, POSSIBLE, true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment