title: Find range of a set where values in the set wrap around a modulus
body: <p>I have a Python set containing numbers representing hours on a 24 hour clock, for example </p>
  
  <pre><code>s = set([1, 3, 8, 23])
  s
  &gt;&gt;&gt; {1, 3, 8, 23}
  </code></pre>
  
  <p>I want to find the size of the smallest range of hours that covers every hour in the set. Normally I could use </p>
  
  <pre><code>max(s) - min(s)
  22 
  </code></pre>
  
  <p>But in this case, the smallest range is allowed to wrap around the modulus (midnight), so the answer would be wrong. The correct answer would be that all the values occur between 23 and 8, so the smallest range is 9 hours. </p>
  
  <p>Is there an efficient way to calculate this using Python? </p>