Exemplo n.º 1
0
def unit_test_next_permutation():
    assert next_permutation('') == ''
    assert next_permutation('a') == 'a'
    assert next_permutation('aaa') == 'aaa'
    assert next_permutation('aba') == 'baa'
    assert next_permutation('word') == 'wrdo'
    assert next_permutation('wrdo') == 'wrod'
    assert next_permutation('wrod') == 'dorw'
    assert next_permutation('abaaacb') == 'abaabac'
    assert next_permutation('abzzzzcb') == 'acbbzzzz'
Exemplo n.º 2
0
from permutations import next_permutation
from primes import isPrime

for n in range(1234, 10000):
    nums = [int("".join(s)) for s in list(next_permutation(list(str(n))))]
    primeNums = [i for i in nums if isPrime(i)]
    if len(primeNums) == 3 and (primeNums[2] - primeNums[1]) == (primeNums[1] - primeNums[0]):
        print "".join(str(p) for p in primeNums)
        break
Exemplo n.º 3
0
#!/usr/bin/env python
from permutations import next_permutation

master = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
all = 0
for perm in next_permutation(master):
   strPerm = ''.join([str(n) for n in perm])

   if int(strPerm[1:4]) % 2 == 0 and int(strPerm[2:5]) % 3 == 0 and int(strPerm[3:6]) % 5 == 0 \
      and int(strPerm[4:7]) % 7 == 0 and int(strPerm[5:8]) % 11 == 0 and int(strPerm[6:9]) % 13 == 0 \
      and int(strPerm[7:10]) % 17 == 0:
         all += int(strPerm)

print(all)
Exemplo n.º 4
0
from permutations import next_permutation

i = 1
for p in next_permutation([0,1,2,3,4,5,6,7,8,9]):
   if i == 1000000:
      print "".join([str(c) for c in p])
      break
   i += 1