Last active
December 19, 2018 18:18
-
-
Save em7v/0760ad9565476a13c0eef319543cca9d to your computer and use it in GitHub Desktop.
Сказ о том как хипстеры смузи делили
This file contains hidden or 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
<?php | |
/** | |
* Сказ о том как хипстеры смузи делили | |
* | |
* @param int $m Общее кол-во смузи | |
* @param int $n Кол-во хипстеров | |
* @return int | |
* @throws TrueStoryException | |
*/ | |
function distributeSmoothies(int $m, int $n) | |
{ | |
if ($n > $m) { | |
$template = 'Увы %d хипстеры в составе %d человек(а) не смогли поделить %d смузи по ровну, выкинув все запасы они пустились в пляс'; | |
throw new TrueStoryException(sprintf($template, $n, $m)); | |
} | |
if ($n === 0 || $m === 0) { | |
throw new TrueStoryException('Толи подвалы с смузи опустели, толи хипстеры уже ни те'); | |
} | |
while ($m % $n != 0 && $m > $n) { | |
$m--; | |
} | |
return $m / $n; | |
} |
This file contains hidden or 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
<?php | |
class TrueStoryException extends Exception {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment