Skip to content

Instantly share code, notes, and snippets.

@Sasszem
Created April 17, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sasszem/7b82e744374ebb65a932870526bc2e52 to your computer and use it in GitHub Desktop.
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
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