-
-
Save RustemB/dcdc5ff97bc9d0fe13dd0858e0189d6e to your computer and use it in GitHub Desktop.
UniLecs 133 Task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task133(N, M, row, col) { | |
if (row > M || col > N) { | |
return "Координата не фходят в поле $N на $M"; | |
} else { | |
return N * (row - 1) + (row % 2 == 1 ? col : (N - col + 1)); | |
} | |
} | |
var tests = [task133(4, 5, 4, 3), task133(5, 5, 3, 1), task133(6, 9, 2, 4), task133(9, 4, 10, 11)]; | |
main() { | |
for (var e in tests) { | |
print(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn task133 [N M row col] | |
(if (or (> row M) (> col N)) | |
(.format "Координата не фходят в поле {} на {}" N M) | |
(+ (* N (dec row)) (if (odd? row) col (- (inc N) col))))) | |
(task133 4 5 4 3) #_(14) | |
(task133 5 5 3 1) #_(11) | |
(task133 6 9 2 4) #_(9) | |
(task133 9 4 10 11) #_(Ошибка, так как координата не входит в это поле) | |
:sep "\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Трансляция кода Hy в Python с помощью оффициальной утилитой hy2py | |
from hy.core.language import dec, inc, is_odd | |
def task133(N, M, row, col): | |
return 'Координата не фходят в поле {} на {}'.format(N, M | |
) if row > M or col > N else N * dec(row) + (col if is_odd(row) else | |
inc(N) - col) | |
print(task133(4, 5, 4, 3), task133(5, 5, 3, 1), task133(6, 9, 2, 4), | |
task133(9, 4, 10, 11), sep='\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function task133(N, M, row, col) | |
if (row > M) | (col > N) | |
"Координата не фходят в поле $N на $M" | |
else | |
N * (row - 1) + (isodd(row) ? col : (N - col + 1)) | |
end | |
end | |
tests = [task133(4, 5, 4, 3), task133(5, 5, 3, 1), task133(6, 9, 2, 4), task133(9, 4, 10, 11)] | |
for i ∈ tests | |
println(i) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub task133($N, $M, $row, $col) { | |
if ($row > $M || $col > $N) { | |
return "Координата не фходят в поле $N на $M"; | |
} else { | |
return $N * ($row - 1) + ($row %% 2 ?? ($N - $col + 1) !! $col); | |
} | |
} | |
say task133(4, 5, 4, 3); | |
say task133(5, 5, 3, 1); | |
say task133(6, 9, 2, 4); | |
say task133(9, 4, 10, 11); |
Решение
В каждом ряду Pacman собирает N шариков, значит что бы узнать сколько шариков Pacman соберёт в полностью пройденных рядах нужно умножить количество рядов, которое Pacmanу нужно нужно пройти полностью (row - 1
), на количество столбцов (N
)
Плюс оставшиеся шарики, так как герой ходит "змейкой" (сначала слева направо), то в нечётных рядах он соберёт col
шаров, в чётных рядах N - col + 1
(т. к. герой движется справа налево)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Тест только для Julia и с поправками на Python, так как я не нашел Hy IDE
Вы можете сами проверить установив Hy через
pip install hy
Julia Test
И с небольшими поправками на Python
UPD:
Dart
Perl 6