-
-
Save reteps/11163ec0199c65969993f1f5da38ac72 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
import itertools | |
#in_ = input() | |
mod = 1000000007 | |
# find possible expressions | |
# find number of steps to sort expression | |
def iters_to_sort(s: str): | |
c = 0 | |
s_list = list(s) | |
while s_list != sorted(s): | |
for i in reversed(range(len(s))): | |
if i == 0: | |
continue | |
if int(s_list[i]) < int(s_list[i-1]): | |
s_list[i], s_list[i-1] = s_list[i-1], s_list[i] | |
c+=1 | |
return c | |
s = "?0?" | |
print(list(itertools.permutations(list(s.replace("0","").replace("1",""))))) | |
def find_perms(s: str): | |
characters_to_change = s.replace("0","").replace("1","") | |
combos = 2**len(characters_to_change) | |
print(combos) | |
for i in range(combos): | |
s.format(list( | |
return ["1"] | |
score = sum([iters_to_sort(z) for z in find_perms(s)]) | |
print(score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment