# Commits

committed 7ec003b

• Participants
• Parent commits 9c0a034

# File 11146/11146.py

`+#!/usr/bin/python`
`+# http://community.topcoder.com/stat?c=problem_statement&pm=11146`
`+`
`+`
`+import math`
`+`
`+# conditions`
`+`
`+condition1 = [1, 1, 3, 1, 5]`
`+condition2 = [7, 47, 5, 113, 73, 179, 53]`
`+`
`+`
`+def even(k):`
`+    return k % 2 != 0`
`+`
`+`
`+def is_good_even_diff(a, d):`
`+    for i in range(2, len(a), 2):`
`+        if a[i] - d * 2 != a[i-2]:`
`+            return False`
`+    return True`
`+`
`+`
`+def is_good_odd_diff(a, d):`
`+    for i in range(3, len(a), 2):`
`+        if a[i] - d*2 != a[i-2]:`
`+            return False`
`+    return True`
`+`
`+`
`+def restore_progression(a):`
`+    # find a diff`
`+    pde = a[2] - a[0]`
`+    pdo = a[3] - a[1]`
`+    if not even(pde) and is_good_even_diff(a, pde/2):`
`+        d = pde/2`
`+        for i in range(1, len(a), 2):`
`+            a[i] = a[0] + i * d`
`+`
`+    elif not even(pdo) and is_good_odd_diff(a, pdo/2):`
`+        d = pdo/2`
`+        a[0] = a[1] - d`
`+        for i in range(1, len(a)):`
`+            a[i] = a[0] + i * d`
`+`
`+    return a`
`+`
`+`
`+def main():`
`+    print restore_progression(condition2)`
`+`
`+`
`+main()`