summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2011/qual/d/2.out20
-rw-r--r--2011/qual/d/d.py25
2 files changed, 21 insertions, 24 deletions
diff --git a/2011/qual/d/2.out b/2011/qual/d/2.out
index 440fd43..82b36df 100644
--- a/2011/qual/d/2.out
+++ b/2011/qual/d/2.out
@@ -32,23 +32,23 @@ Case #31: 10
Case #32: 0
Case #33: 8
Case #34: 2
-Case #35: 16
+Case #35: 14
Case #36: 8
Case #37: 8
Case #38: 0
-Case #39: 10
+Case #39: 8
Case #40: 0
-Case #41: 14
+Case #41: 12
Case #42: 6
Case #43: 2
Case #44: 10
Case #45: 8
-Case #46: 18
+Case #46: 16
Case #47: 4
Case #48: 10
Case #49: 2
Case #50: 2
-Case #51: 18
+Case #51: 16
Case #52: 2
Case #53: 0
Case #54: 0
@@ -60,14 +60,14 @@ Case #59: 4
Case #60: 14
Case #61: 10
Case #62: 4
-Case #63: 14
+Case #63: 12
Case #64: 18
Case #65: 2
Case #66: 4
Case #67: 6
Case #68: 0
Case #69: 12
-Case #70: 16
+Case #70: 14
Case #71: 0
Case #72: 16
Case #73: 4
@@ -80,12 +80,12 @@ Case #79: 2
Case #80: 6
Case #81: 4
Case #82: 4
-Case #83: 18
+Case #83: 16
Case #84: 2
Case #85: 6
Case #86: 8
-Case #87: 14
-Case #88: 14
+Case #87: 12
+Case #88: 12
Case #89: 2
Case #90: 4
Case #91: 8
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