Skip to content

Instantly share code, notes, and snippets.

@reteps
Created February 7, 2019 19:39
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 reteps/11163ec0199c65969993f1f5da38ac72 to your computer and use it in GitHub Desktop.
Save reteps/11163ec0199c65969993f1f5da38ac72 to your computer and use it in GitHub Desktop.
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