-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_16.jl
128 lines (124 loc) · 3.14 KB
/
task_16.jl
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function mark_all!(r::Robot)
num_vert,num_hor = ugol(r)
side = Ost
num_steps = moves!(r,Ost)
for _ in 1:num_steps
move!(r,West)
end
putmarkers!(r,side,num_steps)
while isborder(r,Nord)==false
if isborder(r,side)==true
side = inverse(side)
putmarkers!(r,side,num_steps)
end
end
putmarkers_last!(r,Ost)
moves!(r, West)
moves!(r, Sud)
moves!(r, Ost, num_hor)
moves1!(r, Nord, num_vert)
end
function moves!(r::Robot,side::HorizonSide)
num_steps=0
while isborder(r,side)==false
move!(r,side)
num_steps+=1
end
return num_steps
end
function moves1!(r::Robot,side::HorizonSide,num_steps::Int)
q=0
while q<num_steps
if isborder(r,Nord)==true
while isborder(r,side)==true
move!(r,Ost)
end
move!(r,Nord)
q+=1
if isborder(r,West)==true
while isborder(r,West)==true
move!(r,Nord)
q+=1
end
end
move!(r,West)
end
if q<num_steps
move!(r,side)
q+=1
end
end
end
function moves!(r::Robot,side::HorizonSide,num_steps::Int)
for _ in 1:num_steps # символ "_" заменяет фактически не используемую переменную
move!(r,side)
end
end
function putmarkers!(r::Robot,side::HorizonSide,num_steps::Int)
q=0
while q<num_steps
k=0
putmarker!(r)
if isborder(r,side)==false
move!(r,side)
q+=1
else isborder(r,side)==true
while isborder(r,side)==true
move!(r,Nord)
k+=1
end
move!(r,side)
q+=1
if isborder(r,Sud)==true
move!(r,side)
q+=1
end
for _ in 1:k
move!(r,Sud)
end
end
end
putmarker!(r)
move!(r,Nord)
end
function putmarkers_last!(r::Robot,side::HorizonSide)
while isborder(r,side)==false
putmarker!(r)
move!(r,side)
end
putmarker!(r)
end
function ugol(r::Robot)
num_vert=0
num_hor=0
while (isborder(r,Sud)==false || isborder(r,West)==false)
num_vert+= moves!(r, Sud)
num_hor+= moves!(r, West)
repeat
end
return num_vert,num_hor
end
function moves1!(r::Robot,side::HorizonSide,num_steps::Int)
q=0
while q<num_steps
if isborder(r,Nord)==true
while isborder(r,side)==true
move!(r,Ost)
end
move!(r,Nord)
q+=1
if isborder(r,West)==true
while isborder(r,West)==true
move!(r,Nord)
q+=1
end
end
move!(r,West)
end
if q<num_steps
move!(r,side)
q+=1
end
end
end
inverse(side::HorizonSide)=HorizonSide(mod(Int(side)+2,4))