summaryrefslogtreecommitdiff
path: root/2011/qual/d/d.py
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2011-05-07 17:32:30 +0300
committerYuval Adam <yuv.adm@gmail.com>2011-05-07 17:32:30 +0300
commitfe8ca301ff2bba036ead7273168357879adc1dfd (patch)
tree7d5f0d63c003ee8d7cece733042a3c50bfbc25cc /2011/qual/d/d.py
parent582b8ef5019ba10d5848d9d000e8aecbd0848b30 (diff)
i think i got it
Diffstat (limited to '2011/qual/d/d.py')
-rw-r--r--2011/qual/d/d.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/2011/qual/d/d.py b/2011/qual/d/d.py
index 0bdf8dd..d978a3c 100644
--- a/2011/qual/d/d.py
+++ b/2011/qual/d/d.py
@@ -6,31 +6,28 @@ def solve(a):
# stop if solved
while a != sol:
print "%s is not %s" % (a, sol)
-
+ flipped = False
# first flip all pairs
for i in range(len(a)):
if a[i] != i+1 and a[a[i]-1] == i+1:
print 'flipping %d and %d' % (a[a[i]-1], a[i])
- t = a[i]
- a[i] = a[a[i]-1]
- print 'flipping %d and %d' % (a[a[i]-1], a[i])
- a[a[i]-1] = t
- print 'flipping %d and %d' % (a[a[i]-1], a[i])
- break
+ t = a[a[i]-1]
+ a[a[i]-1] = a[i]
+ a[i] = t
steps += 2
-
- # did that suffice?
- if a == sol:
- print "%s is not %s" % (a, sol)
- break
+ flipped = True
+
+ if flipped:
+ continue
# now find the first mixed index to fix
for i in range(len(a)):
if a[i] != i+1:
print 'flipping %d and %d' % (a[a[i]-1], a[i])
- a[i], a[a[i]-1] = a[a[i]-1], a[i]
+ t = a[a[i]-1]
+ a[a[i]-1] = a[i]
+ a[i] = t
steps += 2
- sleep(1)
return steps