Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 1d7c55d

Browse files
committed
oneliner #2
1 parent 5658eb1 commit 1d7c55d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

21.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
data = [x.rstrip('\n') for x in inputdata]
77

8+
89
def getRegexResult(prog, s):
910
m = prog.match(s)
1011
return m.groups() if m else []
@@ -21,7 +22,7 @@ def handle_sp(s, x, y):
2122
return ''.join(lresult)
2223

2324
def handle_sl(s, x, y):
24-
return s.replace(x, '1').replace(y, x).replace('1', y)
25+
return s.replace(x, '$').replace(y, x).replace('$', y)
2526

2627
def handle_rl(s, x):
2728
x = int(x)
@@ -84,9 +85,4 @@ def run(input):
8485

8586
# ugly part 2
8687
from itertools import permutations
87-
for p in permutations('abcdefgh'):
88-
p = ''.join(p)
89-
90-
if run(p) == 'fbgdceah':
91-
print p
92-
break
88+
print next(''.join(p) for p in permutations('abcdefgh') if run(''.join(p)) == 'fbgdceah')

0 commit comments

Comments
 (0)