diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2022-11-20 14:22:01 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2022-11-20 14:22:01 -0500 |
| commit | dd682dfee966fe63cbfbbbf6a9cb903b1d831416 (patch) | |
| tree | a71619e10c8dcd29fc13a08beb1325f4a7bc5a84 /challenge-191/roger-bell-west/python/ch-2.py | |
| parent | d6d01468fd7a5647b9ba96ebf7a0157ff79f3352 (diff) | |
| parent | bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (diff) | |
| download | perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.gz perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.tar.bz2 perlweeklychallenge-club-dd682dfee966fe63cbfbbbf6a9cb903b1d831416.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-191/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-191/roger-bell-west/python/ch-2.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-191/roger-bell-west/python/ch-2.py b/challenge-191/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..a06335557f --- /dev/null +++ b/challenge-191/roger-bell-west/python/ch-2.py @@ -0,0 +1,43 @@ +#! /usr/bin/python3 + +import unittest + +def cutelist(n): + tab = [[False]] + for x in range(1, n+1): + tab.append([False] * (n+1)) + for x in range(1, n+1): + for y in range(1, x+1): + if x % y != 0 and y % x != 0: + tab[x][y] = True + tab[y][x] = True + count = 0 + stackl = [[]] + stackc = [[x for x in range(1,n+1)]] + while len(stackl) > 0: + l = stackl.pop() + c = stackc.pop() + if len(c) == 0 and len(l) == n: + count += 1 + else: + place = len(l) + 1 + for candidate in c: + if not tab[place][candidate]: + q = l.copy() + q.append(candidate) + stackl.append(q) + stackc.append([i for i in c if i != candidate]) + return count + +class TestCutelist(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(cutelist(2), 2, 'example 1') + + def test_ex2(self): + self.assertEqual(cutelist(10), 700, 'example 2') + + def test_ex3(self): + self.assertEqual(cutelist(15), 24679, 'example 3') + +unittest.main() |
