コード例 #1
0
def main(keys):
    global size
    
    begin = time.time()

    size = len(keys[0])
    
    # possibleSolutions = [row, col]
    possibleSolutions = [[[] for i in range(0, size)], [[] for i in range(0, size)]]

    ### ---- Find set of possible solutions for each row ----
    getArrayPermutations(keys, possibleSolutions)

    ### ---- Calculate Posibilities ----

    end = time.time()
    total = end - begin

    print('')
    print("##################################################")
    print("Permutation Time : ", "{:,.3f}s".format(total))
    print("##################################################")

    calculatePossibleSolutionCount(possibleSolutions)

    ### ---- Remove Impossible rows ---
    deletedPossibleItem = True
    while deletedPossibleItem:
        deletedPossibleItem = False
        for solutionSet in range(0, 2):
            for s in range(0, size):
                count = len(possibleSolutions[solutionSet-1][s])
                comboSum = np.sum(possibleSolutions[solutionSet-1][s], axis=0)

                for i in range(0, size):
                    if comboSum[i] == count or comboSum[i] == 0:
                        toDelete = []
                        for psIndex in range(0, len(possibleSolutions[solutionSet][i])):
                            if comboSum[i] == count and possibleSolutions[solutionSet][i][psIndex][s] == 0:
                                toDelete.append(psIndex)
                                deletedPossibleItem = True
                            elif comboSum[i] == 0 and possibleSolutions[solutionSet][i][psIndex][s] == 1:
                                toDelete.append(psIndex)
                                deletedPossibleItem = True
                        possibleSolutions[solutionSet][i] = np.delete(possibleSolutions[solutionSet][i], toDelete, axis=0)

    ### --- Display The Result ----
    remainingSolutions = np.product([len(i) for i in possibleSolutions[0]], dtype=np.uint64)
    if remainingSolutions != 1:
        print('Possible Error In Puzzle Clue Or Puzzle Is Impossible')
    else:    
        c = np.stack(mit.nth_product(0, *possibleSolutions[0]))

        ### ---- COMPLETE ----
        end = time.time()
        total = end - begin

        print('')
        print("##################################################")
        print("Solution Time : ", "{:,.3f}s".format(total))
        print("##################################################")

        printMatrix(c)
コード例 #2
0
 def test_invalid_index(self):
     with self.assertRaises(IndexError):
         mi.nth_product(24, 'ab', 'cde', 'fghi')
コード例 #3
0
 def test_long(self):
     actual = mi.nth_product(1337, range(101), range(22), range(53))
     expected = (1, 3, 12)
     self.assertEqual(actual, expected)
コード例 #4
0
 def test_negative(self):
     iterables = ['abc', 'de', 'fghi']
     for index, expected in enumerate(product(index, **iterables)):
         actual = mi.nth_product(index - 24, **iterables)
         self.assertEqual(actual, expected)
コード例 #5
0
 def test_basic(self):
     iterables = ['ab', 'cdef', 'ghi']
     for index, expected in enumerate(product(index, **iterables)):
         actual = mi.nth_product(index, **iterables)
         self.assertEqual(actual, expected)