Beispiel #1
0
def test_permutations():
    """
    Test tools.permutations
    """
    assert list(tools.permutations('ABC', 2)) == (list(itertools.permutations('ABC', 2)))

    assert list(tools.permutations(range(3))) == (list(itertools.permutations(range(3))))

    assert list(tools.permutations('abc', 0)) == (list(itertools.permutations('abc', 0)))

    assert list(tools.permutations('', 2)) == (list(itertools.permutations('', 2)))

    assert list(tools.permutations({'A', 'B', 'C'}, 2)) == \
            list(itertools.permutations({'A', 'B', 'C'}, 2))
Beispiel #2
0
 def test_permutations_1_el(self):
     a = [
         1,
     ]
     r = tools.permutations(a)
     self.assertEqual(r, [
         [
             1,
         ],
     ])
Beispiel #3
0
def instantiate_factored_mapping(pairs):
    part_mappings = [[
        zip(preimg, perm_img) for perm_img in tools.permutations(img)
    ] for (preimg, img) in pairs]
    return tools.cartesian_product(part_mappings)
Beispiel #4
0
def instantiate_factored_mapping(pairs):
    part_mappings = [[zip(preimg, perm_img) for perm_img in tools.permutations(img)]
                     for (preimg, img) in pairs]
    return tools.cartesian_product(part_mappings)
Beispiel #5
0
 def test_permutations_3_el(self):
     a = [1, 2, 3]
     r = tools.permutations(a)
     self.assertEqual(
         r,
         [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]])
Beispiel #6
0
 def test_permutations_2_el(self):
     a = [1, 2]
     r = tools.permutations(a)
     self.assertEqual(r, [[1, 2], [2, 1]])
Beispiel #7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Project Euler No. 24

http://projecteuler.net/index.php?section=problems&id=24
A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

012   021   102   120   201   210

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
"""

from tools import permutations

n = 0
p = permutations(range(10))
while n < (int(1e6) - 1):
    p.next()
    n += 1
print "".join(str(x) for x in p.next())