Skip to content

Instantly share code, notes, and snippets.

@stmkza
Created April 5, 2020 12:13
Show Gist options
  • Save stmkza/e24c212b4401087f915271c04df2226d to your computer and use it in GitHub Desktop.
Save stmkza/e24c212b4401087f915271c04df2226d to your computer and use it in GitHub Desktop.
<?php
[$s, $l, $r] = explode(' ', file_get_contents('php://stdin'));
if($l <= $s && $s <= $r) printf("%d\n", $s);
else if($l > $s) printf("%d\n", $l);
else printf("%d\n", $r);
<?php
[$s, $l, $r] = explode(' ', file_get_contents('php://stdin'));
$x = $s;
while(!isStopPosition($x, $l, $r)) {
if($x < $l) $x += 1;
else if($x > $r) $x -= 1;
}
printf("%d\n", $x);
function isStopPosition($pos, $l, $r): bool
{
return $l <= $pos && $pos <= $r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment