From 20d18558c503a9763cbcffb0aee79ece6f92f5de Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 5 Dec 2018 16:27:42 +0000 Subject: [PATCH] Attempt to clean up 2018/05 --- 2018/05/solve.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/2018/05/solve.py b/2018/05/solve.py index 6ef8463..ead1665 100644 --- a/2018/05/solve.py +++ b/2018/05/solve.py @@ -15,21 +15,35 @@ def naive_react(pol): print("Naive react says: More reacting is possible.") def react(pol): - start = 0 while True: - i = start + i = 0 while i < len(pol) - 1: - if pol[i].lower() == pol[i+1].lower() and pol[i] != pol[i+1]: + pol_cur, pol_next = pol[i], pol[i+1] + if pol_cur.lower() == pol_next.lower() and pol_cur != pol_next: del pol[i] del pol[i] - start = max(0, start - 1) - break - elif i == start + 1: - start = i - i += 1 + i = max(0, i - 1) + else: + i += 1 else: return +#def react(pol): +# start = 0 +# while True: +# i = start +# while i < len(pol) - 1: +# if pol[i].lower() == pol[i+1].lower() and pol[i] != pol[i+1]: +# del pol[i] +# del pol[i] +# start = max(0, start - 1) +# break +# elif i == start + 1: +# start = i +# i += 1 +# else: +# return + def result(pol): l = pol.copy() #print("".join(l))