-
Notifications
You must be signed in to change notification settings - Fork 2
/
solutions.ms
63 lines (53 loc) · 1.25 KB
/
solutions.ms
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
solutionOffsets = function(runLength = 4)
offsets = genericOffsets(runLength)
directions = {
"horizontal": {"col": 1, "row": 0},
"vertical": {"col": 0, "row": 1},
"diagonal_1": {"col": 1, "row": 1},
"diagonal_2": {"col": 1, "row": -1} }
solutions = []
for directionName in directions.indexes
direction = directions[directionName]
for offsetFactors in offsets
solution = calculateSolution(direction, offsetFactors)
solutions.push solution
end for
end for
return solutions
end function
calculateSolution = function(direction, offsetFactors)
solution = []
for offset in offsetFactors
col = direction.col * offset
row = direction.row * offset
offsetToCheck = {"col": col, "row": row}
solution.push offsetToCheck
end for
return solution
end function
genericOffsets = function(runLength)
offsets = []
for i in range(1,runLength)
solution = []
left = i - 1
right = runLength - i
if left > 0 then
for offset in range(left,1)
solution.push -1 * offset
end for
end if
solution.push 0
if right > 0 then
for offset in range(1,right)
solution.push offset
end for
end if
offsets.push solution
end for
return offsets
end function
if globals == locals then
clear
s = solutionOffsets(4)
pprint s
end if