Skip to content

Instantly share code, notes, and snippets.

@Wendly
Last active May 29, 2017 14:54
Show Gist options
  • Save Wendly/6faf5fcac9a54a013c16e404538784f7 to your computer and use it in GitHub Desktop.
Save Wendly/6faf5fcac9a54a013c16e404538784f7 to your computer and use it in GitHub Desktop.
n = int(input())
def translate(index, s):
for i in range(1, n + 1):
s += str(index[i]) if (index[i - 1] & 1) == 0 else str(9 - index[i])
return s
for i in range(0, (10 ** n)):
print(translate(list(map(int, str(i).zfill(n + 1))), ''))
@Wendly
Copy link
Author

Wendly commented May 28, 2017

n = int(input())

op = [1, -1]
num = [0] * (n + 1)
for i in range(1, (10 ** n) + 1):
    print(''.join([str(i) for i in num[0:-1]][::-1]))

    s = str(i).zfill(n + 2)[::-1]
    index = 0
    while s[index] == '0':
        index += 1

    num[index] = num[index] + op[int(s[index + 1]) & 1]

@Wendly
Copy link
Author

Wendly commented May 29, 2017

n = int(input())

numMax = 10 ** n
num = 0

carry = [0] * (n + 2)
dNums = [[10 ** i for i in range(0, n + 2)], [-1 * 10 ** i for i in range(0, n + 2)]]

while num < numMax:
    print("%0*d" % (n, num))

    carry[0] += 1

    index = 0
    while carry[index] == 10:
        carry[index] = 0
        index += 1
        carry[index] += 1

    num += dNums[carry[index + 1] & 1][index]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment