-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem.hs
More file actions
110 lines (97 loc) · 2.21 KB
/
Copy pathProblem.hs
File metadata and controls
110 lines (97 loc) · 2.21 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module Problem
( Color,
Row,
Column,
Problem,
mkProblem,
(!),
size,
problem1,
problem2,
problem3,
problem4,
problem5,
parse,
)
where
import Data.Array (Array, (!))
import qualified Data.Array as Array
import Data.Char (ord)
type Color = Int
type Row = Int
type Column = Int
type Problem = Array (Row, Column) Color
mkProblem :: [[Color]] -> Problem
mkProblem colorsList =
Array.array
((0, 0), (n - 1, n - 1))
[((i, j), color) | (i, row) <- zip [0 ..] colorsList, (j, color) <- zip [0 ..] row]
where
n = length colorsList
size :: Problem -> Int
size problem = n + 1
where
((_, _), (_, n)) = Array.bounds problem
-- Sample problem on https://www.linkedin.com/games/queens
problem1 :: Problem
problem1 =
mkProblem
[ [0, 1, 1, 1, 1],
[2, 3, 2, 1, 2],
[2, 3, 2, 1, 2],
[2, 2, 2, 4, 4],
[2, 2, 2, 2, 2]
]
-- https://queensgame.vercel.app/level/1
problem2 :: Problem
problem2 =
mkProblem
[ [0, 0, 1, 1, 1, 2, 2, 2],
[0, 3, 1, 3, 1, 4, 2, 2],
[0, 3, 1, 3, 1, 2, 2, 2],
[0, 3, 3, 3, 1, 5, 6, 2],
[0, 3, 3, 3, 1, 5, 6, 6],
[0, 3, 7, 3, 1, 5, 6, 6],
[7, 3, 7, 3, 1, 5, 5, 6],
[7, 7, 7, 7, 6, 6, 6, 6]
]
-- https://queensgame.vercel.app/community-level/1
problem3 :: Problem
problem3 =
mkProblem
[ [0, 0, 0, 1, 2, 3],
[0, 0, 0, 1, 2, 3],
[1, 1, 1, 1, 2, 3],
[1, 1, 4, 2, 2, 3],
[5, 4, 4, 2, 2, 3],
[5, 5, 4, 4, 2, 2]
]
-- https://queensgame.vercel.app/community-level/3
problem4 :: Problem
problem4 =
mkProblem
[ [0, 0, 0, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1],
[2, 2, 2, 1, 3, 3, 3],
[2, 4, 4, 4, 3, 3, 3],
[2, 4, 4, 4, 3, 3, 3],
[2, 4, 4, 4, 5, 5, 6],
[2, 2, 2, 2, 5, 5, 5]
]
problem5 :: Problem
problem5 =
mkProblem
[ [0, 1, 1, 1, 2, 1, 1, 3],
[0, 0, 0, 1, 2, 2, 1, 3],
[1, 1, 1, 1, 1, 2, 1, 3],
[4, 4, 4, 1, 1, 1, 1, 3],
[4, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 5, 1, 1, 6],
[7, 7, 1, 5, 5, 1, 6, 6],
[7, 7, 1, 5, 1, 1, 1, 6]
]
parse :: String -> Problem
parse input = mkProblem matrix
where
matrix = (map . map) f $ lines input
f ch = ord ch - ord 'A'