-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonHandleDirectionModule.pas
More file actions
34 lines (28 loc) · 1.23 KB
/
onHandleDirectionModule.pas
File metadata and controls
34 lines (28 loc) · 1.23 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
unit onHandleDirectionModule;
interface
function onHandleDirection(squares: array [,] of integer; size: integer): array [,] of integer;
implementation
function onHandleDirection(squares: array [,] of integer; size: integer): array [,] of integer;
begin
var newSquares := squares;
for var i := 0 to size - 1 do
for var j := 0 to size - 1 do
if (squares[i, j] <> -1) and (i >= 1) then
for var m := i downto 1 do
begin
if squares[i - m, j] = -1 then
begin
newSquares[i - m, j] := squares[i, j];
newSquares[i, j] := -1;
break;
end
else if squares[i - m, j] = squares[i, j] then
begin
newSquares[i - m, j] := squares[i, j] * 2;
newSquares[i, j] := -1;
break;
end;
end;
result := newSquares;
end;
end.