module Test where import Text.Printf import System.Exit import qualified Exercise03 as Sub containsSudoku :: [[Int]] -> [[Int]] -> Bool containsSudoku sol base = aux (concat sol) (concat base) where aux [] [] = True aux (s:ss) (b:bs) = (b == s || b == 0) && aux ss bs aux _ _ = False hasEmpty :: [[Int]] -> Bool hasEmpty s = 0 `elem` concat s doesSolveSudoku :: [[Int]] -> [[Int]] -> Bool doesSolveSudoku sol base = Sol.isValidSudoku sol && not (hasEmpty sol) && containsSudoku sol base subSolveSudoku :: [[Int]] -> Bool subSolveSudoku sudoku = doesSolveSudoku (Sub.solveSudoku sudoku) sudoku sudoku32 = [[33,28,29,2,7,12,24,5,14,11,21,9,13,19,3,8,18,6,34,15,26,10,20,31,32,35,16,27,17,25,30,23,4,22,36,1], [23,31,1,21,32,20,10,17,22,16,35,2,34,30,36,26,15,9,7,14,5,3,19,12,33,18,13,11,8,4,24,27,6,28,25,29], [19,36,17,8,14,13,34,33,28,3,15,7,27,2,22,5,32,4,16,25,24,11,6,30,1,29,31,23,21,9,12,35,26,20,18,10], [5,25,24,9,6,35,4,19,12,20,26,31,33,1,14,11,29,23,27,36,18,2,21,32,30,34,15,22,10,28,7,8,3,13,17,16], [16,34,10,22,30,26,32,25,13,6,27,18,20,17,35,21,24,31,8,4,29,1,28,23,3,12,14,36,7,2,15,5,33,9,19,11], [15,11,18,27,3,4,23,36,8,29,1,30,25,7,12,28,16,10,17,33,35,9,13,22,5,19,26,6,20,24,2,32,34,14,31,21], [22,12,5,16,23,31,25,9,1,32,34,10,3,27,17,29,6,7,13,11,19,28,33,24,18,36,8,26,15,20,35,14,21,2,30,4], [17,20,34,3,8,7,16,18,24,19,29,23,36,31,2,4,28,33,30,21,12,15,27,10,25,11,22,14,35,13,5,1,9,26,6,32], [4,15,30,10,33,19,13,27,3,14,28,17,18,12,26,35,25,34,22,7,20,6,1,5,16,9,21,2,24,32,11,31,8,36,29,23], [32,21,35,36,1,27,33,2,15,4,11,26,23,16,20,22,14,5,29,9,31,25,18,8,34,10,6,30,12,3,17,28,7,19,13,24], [14,29,9,13,2,6,36,30,7,5,20,8,11,32,15,24,10,21,3,17,16,35,4,26,31,23,33,1,28,19,22,25,27,12,34,18], [25,24,26,11,18,28,22,35,21,31,12,6,30,8,19,13,9,1,23,34,36,32,14,2,29,17,7,4,27,5,10,33,20,16,15,3], [2,19,3,20,13,24,26,6,36,35,8,5,7,25,28,17,33,30,31,18,9,27,12,16,15,14,4,21,11,1,34,29,32,10,23,22], [10,22,16,6,34,14,3,21,32,1,4,12,19,18,11,31,2,26,15,35,25,7,23,13,24,33,27,17,29,8,9,30,36,5,20,28], [26,9,15,35,27,25,31,23,2,33,7,14,4,13,8,16,3,20,1,29,22,21,34,11,28,30,36,32,5,10,18,17,12,6,24,19], [7,33,11,4,36,32,29,16,18,28,17,15,9,10,24,12,1,22,6,30,14,8,5,19,23,20,2,13,34,35,25,21,31,3,26,27], [18,17,12,1,31,29,19,10,34,22,30,11,32,5,21,27,23,36,24,20,33,26,2,28,9,16,3,25,6,7,4,15,13,8,35,14], [21,8,23,5,28,30,9,20,27,25,24,13,35,15,29,6,34,14,36,32,10,4,3,17,19,26,12,31,18,22,16,11,2,1,7,33], [36,2,33,32,15,9,7,12,35,34,3,27,31,20,30,1,21,16,18,10,11,23,22,25,6,28,29,19,13,26,14,24,5,17,4,8], [20,4,19,34,25,17,18,11,23,10,16,33,6,28,9,15,22,24,32,3,13,14,7,29,27,5,35,8,31,12,1,26,30,21,2,36], [29,18,14,31,5,3,8,15,25,26,22,1,10,34,13,2,35,17,4,12,28,16,36,9,20,21,11,24,32,30,23,6,19,33,27,7], [28,13,6,12,35,11,14,31,17,21,32,24,26,36,5,7,4,18,19,27,8,33,30,1,2,15,10,34,3,23,20,9,16,29,22,25], [24,7,27,26,10,16,30,28,29,9,36,19,14,3,25,23,11,8,5,2,21,20,15,6,17,22,1,33,4,18,13,34,35,32,12,31], [8,30,21,23,22,1,6,4,5,2,13,20,29,33,27,32,19,12,26,31,17,24,35,34,36,7,25,9,14,16,3,10,11,18,28,15], [6,1,4,17,12,33,5,34,10,13,9,35,24,14,31,3,26,11,25,28,7,18,8,27,22,2,19,15,23,21,32,36,29,30,16,20], [30,35,32,24,19,8,15,14,20,23,2,16,17,21,34,18,5,27,12,13,3,22,11,36,4,1,28,29,33,6,26,7,25,31,10,9], [27,16,25,7,20,5,21,1,30,24,31,4,8,29,23,33,13,28,2,26,32,34,17,35,10,3,9,12,36,11,19,18,22,15,14,6], [31,23,22,14,11,21,17,32,19,7,25,28,1,4,10,36,12,35,9,6,15,29,16,20,8,13,30,18,26,27,33,2,24,34,3,5], [34,3,2,28,26,36,12,22,11,18,33,29,15,6,32,9,7,25,21,5,30,19,10,14,35,24,17,20,16,31,8,4,23,27,1,13], [9,10,13,15,29,18,27,8,26,36,6,3,2,22,16,20,30,19,33,1,23,31,24,4,7,32,34,5,25,14,28,12,17,11,21,35], [12,14,31,30,16,15,1,24,33,8,23,32,5,9,4,25,36,2,35,19,27,17,29,3,13,6,18,10,22,34,21,20,28,7,11,26], [13,5,28,18,21,10,20,3,31,15,19,36,12,35,6,14,27,32,11,8,4,30,9,7,26,25,23,16,2,17,29,22,1,24,33,34], [1,27,8,25,17,23,11,29,6,30,5,34,16,26,33,10,20,15,28,22,2,13,32,18,21,4,24,7,19,36,31,3,14,35,9,12], [11,32,36,33,4,2,35,26,9,27,18,22,28,24,7,19,17,29,20,16,34,12,25,21,14,31,5,3,1,15,6,13,10,23,8,30], [35,26,7,29,9,22,2,13,16,12,14,25,21,23,1,34,8,3,10,24,6,5,31,15,11,27,20,28,30,33,36,19,18,4,32,17], [3,6,20,19,24,34,28,7,4,17,10,21,22,11,18,30,31,13,14,23,1,36,26,33,12,8,32,35,9,29,27,16,15,0,5,2]] sudoku32_unsolvable = [[33,28,29,2,7,12,24,5,14,11,21,9,13,19,3,8,18,6,34,15,26,10,20,31,32,35,16,27,17,25,30,23,4,22,36,1], [23,31,1,21,32,20,10,17,22,16,35,2,34,30,36,26,15,9,7,14,5,3,19,12,33,18,13,11,8,4,24,27,6,28,25,29], [19,36,17,8,14,13,34,33,28,3,15,7,27,2,22,5,32,4,16,25,24,11,6,30,1,29,31,23,21,9,12,35,26,20,18,10], [5,25,24,9,6,35,4,19,12,20,26,31,33,1,14,11,29,23,27,36,18,2,21,32,30,34,15,22,10,28,7,8,3,13,17,16], [16,34,10,22,30,26,32,25,13,6,27,18,20,17,35,21,24,31,8,4,29,1,28,23,3,12,14,36,7,2,15,5,33,9,19,11], [15,11,18,27,3,4,23,36,8,29,1,30,25,7,12,28,16,10,17,33,35,9,13,22,5,19,26,6,20,24,2,32,34,14,31,21], [22,12,5,16,23,31,25,9,1,32,34,10,3,27,17,29,6,7,13,11,19,28,33,24,18,36,8,26,15,20,35,14,21,2,30,4], [17,20,34,3,8,7,16,18,24,19,29,23,36,31,2,4,28,33,30,21,12,15,27,10,25,11,22,14,35,13,5,1,9,26,6,32], [4,15,30,10,33,19,13,27,3,14,28,17,18,12,26,35,25,34,22,7,20,6,1,5,16,9,21,2,24,32,11,31,8,36,29,23], [32,21,35,36,1,27,33,2,15,4,11,26,23,16,20,22,14,5,29,9,31,25,18,8,34,10,6,30,12,3,17,28,7,19,13,24], [14,29,9,13,2,6,36,30,7,5,20,8,11,32,15,24,10,21,3,17,16,35,4,26,31,23,33,1,28,19,22,25,27,12,34,18], [25,24,26,11,18,28,22,35,21,31,12,6,30,8,19,13,9,1,23,34,36,32,14,2,29,17,7,4,27,5,10,33,20,16,15,3], [2,19,3,20,13,24,26,6,36,35,8,5,7,25,28,17,33,30,31,18,9,27,12,16,15,14,4,21,11,1,34,29,32,10,23,22], [10,22,16,6,34,14,3,21,32,1,4,12,19,18,11,31,2,26,15,35,25,7,23,13,24,33,27,17,29,8,9,30,36,5,20,28], [26,9,15,35,27,25,31,23,2,33,7,14,4,13,8,16,3,20,1,29,22,21,34,11,28,30,36,32,5,10,18,17,12,6,24,19], [7,33,11,4,36,32,29,16,18,28,17,15,9,10,24,12,1,22,6,30,14,8,5,19,23,20,2,13,34,35,25,21,31,3,26,27], [18,17,12,1,31,29,19,10,34,22,30,11,32,5,21,27,23,36,24,20,33,26,2,28,9,16,3,25,6,7,4,15,13,8,35,14], [21,8,23,5,28,30,9,20,27,25,24,13,35,15,29,6,34,14,36,32,10,4,3,17,19,26,12,31,18,22,16,11,2,1,7,33], [36,2,33,32,15,9,7,12,35,34,3,27,31,20,30,1,21,16,18,10,11,23,22,25,6,28,29,19,13,26,14,24,5,17,4,8], [20,4,19,34,25,17,18,11,23,10,16,33,6,28,9,15,22,24,32,3,13,14,7,29,27,5,35,8,31,12,1,26,30,21,2,36], [29,18,14,31,5,3,8,15,25,26,22,1,10,34,13,2,35,17,4,12,28,16,36,9,20,21,11,24,32,30,23,6,19,33,27,7], [28,13,6,12,35,11,14,31,17,21,32,24,26,36,5,7,4,18,19,27,8,33,30,1,2,15,10,34,3,23,20,9,16,29,22,25], [24,7,27,26,10,16,30,28,29,9,36,19,14,3,25,23,11,8,5,2,21,20,15,6,17,22,1,33,4,18,13,34,35,32,12,31], [8,30,21,23,22,1,6,4,5,2,13,20,29,33,27,32,19,12,26,31,17,24,35,34,36,7,25,9,14,16,3,10,11,18,28,15], [6,1,4,17,12,33,5,34,10,13,9,35,24,14,31,3,26,11,25,28,7,18,8,27,22,2,19,15,23,21,32,36,29,30,16,20], [30,35,32,24,19,8,15,14,20,23,2,16,17,21,34,18,5,27,12,13,3,22,11,36,4,1,28,29,33,6,26,7,25,31,10,9], [27,16,25,7,20,5,21,1,30,24,31,4,8,29,23,33,13,28,2,26,32,34,17,35,10,3,9,12,36,11,19,18,22,15,14,6], [31,23,22,14,11,21,17,32,19,7,25,28,1,4,10,36,12,35,9,6,15,29,16,20,8,13,30,18,26,27,33,2,24,34,3,5], [34,3,2,28,26,36,12,22,11,18,33,29,15,6,32,9,7,25,21,5,30,19,10,14,35,24,17,20,16,31,8,4,23,27,1,13], [9,10,13,15,29,18,27,8,26,36,6,3,2,22,16,20,30,19,33,1,23,31,24,4,7,32,34,5,25,14,28,12,17,11,21,35], [12,14,31,30,16,15,1,24,33,8,23,32,5,9,4,25,36,2,35,19,27,17,29,3,13,6,18,10,22,34,21,20,28,7,11,26], [13,5,28,18,21,10,20,3,31,15,19,36,12,35,6,14,27,32,11,8,4,30,9,7,26,25,23,16,2,17,29,22,1,24,33,34], [1,27,8,25,17,23,11,29,6,30,5,34,16,26,33,10,20,15,28,22,2,13,32,18,21,4,24,7,19,36,31,3,14,35,9,12], [11,32,36,33,4,2,35,26,9,27,18,22,28,24,7,19,17,29,20,16,34,12,25,21,14,31,5,3,1,15,6,13,10,23,8,30], [35,26,7,29,9,22,2,13,16,12,14,25,21,23,1,34,8,3,10,24,6,5,31,15,11,27,20,28,30,33,36,19,18,4,32,17], [3,6,20,19,24,34,28,7,4,17,10,21,22,11,18,30,31,13,14,23,1,36,26,33,12,8,32,35,9,29,27,16,15,25,0,22]] main :: IO () main = do if subSolveSudoku sudoku32 && null (Sub.solveSudoku sudoku32_unsolvable) then putStrLn "0" else exitWith (ExitFailure 1)