-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask10.jl
46 lines (41 loc) · 848 Bytes
/
Task10.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
function find_average(r::Robot)
(sum, count) = count_markers(r)
if count == 0
print(0)
else
print(sum / count)
end
end
function count_markers(r::Robot)
count = 0
sum = 0
side = Ost
(n_sum, n_count) = check_line(r, side)
sum += n_sum
count += n_count
while !isborder(r, Nord)
move!(r, Nord)
side = inverse(side)
(n_sum, n_count) = check_line(r, side)
sum += n_sum
count += n_count
end
return (sum, count)
end
inverse(side::HorizonSide) = HorizonSide(mod(Int(side) + 2, 4))
function check_line(r::Robot, side::HorizonSide)
count = 0
sum = 0
while !isborder(r, side)
if ismarker(r)
count += 1
sum += temperature(r)
end
move!(r, side)
end
if ismarker(r)
count += 1
sum += temperature(r)
end
return (sum, count)
end