-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exercises.hs
86 lines (67 loc) · 1.48 KB
/
Exercises.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Data.List (intercalate)
import qualified Answers
-- Data types
type Row a = [a]
type Matrix a = [Row a]
type Digit = Int
type Grid = Matrix Digit
-- Printing functions
p :: Grid -> IO ()
p = putStrLn . unlines . map (intercalate " " . map show)
ps :: [Grid] -> IO [()]
ps = sequence . map p
-- Some grids
grid1 :: Grid
grid1 = [[0, 2, 4, 0],
[1, 0, 0, 3],
[4, 0, 0, 2],
[0, 1, 3, 0]]
grid2 :: Grid
grid2 = [[0, 3, 0, 1],
[1, 0, 3, 2],
[3, 0, 1, 0],
[0, 1, 0, 3]]
-- Define grid size
boxSize = 2
gridSize = boxSize * boxSize
-- Exercise 1
-- Given: completions, valid
solve :: Grid -> [Grid]
solve = undefined
-- Exercise 2
-- Given: choices, expand
completions :: Grid -> [Grid]
completions = Answers.completions
-- Exercise 3
choices :: Grid -> Matrix [Digit]
choices = Answers.choices
-- Exercise 4
-- Given: cp
expand :: Matrix [Digit] -> [Grid]
expand = Answers.expand
-- Exercise 5
cp :: [[a]] -> [[a]]
cp = Answers.cp
-- Exercise 6
-- Given: nodups, rows, cols, boxs
valid :: Grid -> Bool
valid = Answers.valid
-- Exercise 7
nodups :: Eq a => [a] -> Bool
nodups = Answers.nodups
-- Exercise 8
rows :: Matrix a -> Matrix a
rows = Answers.rows
-- Exercise 9
cols :: Matrix a -> Matrix a
cols = Answers.cols
-- Exercise 10
-- Given: group, ungroup
boxs :: Matrix a -> Matrix a
boxs = Answers.boxs
-- Exercise 11
group :: [a] -> [[a]]
group = Answers.group
-- Exercise 12
ungroup :: [[a]] -> [a]
ungroup = Answers.ungroup