Skip to content

Instantly share code, notes, and snippets.

@ginsengs
Last active December 19, 2018 18:18
Show Gist options
  • Save ginsengs/0760ad9565476a13c0eef319543cca9d to your computer and use it in GitHub Desktop.
Save ginsengs/0760ad9565476a13c0eef319543cca9d to your computer and use it in GitHub Desktop.
Сказ о том как хипстеры смузи делили
<?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;
}
<?php
class TrueStoryException extends Exception {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment