<?php

/**
 * Constrain integer to interval `[min,max]`
 * 
 * @param int $min lower bound
 * @param int $max upper bound
 */
function constrain(int $min, int $max, $n): int
{
  return max(min($max, $n), $min);
}
