Created
April 17, 2020 09:11
-
-
Save Sasszem/7b82e744374ebb65a932870526bc2e52 to your computer and use it in GitHub Desktop.
Brute-forcing a simple combinatorical problem to verify the correctness of out solution
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 num_to_str(n): | |
return "{:012b}".format(n) | |
def has_four(s): | |
return sum(int(ch) for ch in s)==4 | |
def no_next_to(s): | |
return s.find("11")==-1 | |
all_possible = list(filter(no_next_to, filter(has_four, map(num_to_str, range(2**12))))) | |
print(all_possible) | |
print(len(all_possible)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment