Popular recipes by elazar http://code.activestate.com/recipes/users/4187847/2015-07-05T23:46:59-07:00ActiveState Code RecipesBader-Offer Method (Hagenbach-Bischoff) (JavaScript) 2015-01-14T11:14:06-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/579002-bader-offer-method-hagenbach-bischoff/ <p style="color: grey"> JavaScript recipe 579002 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/calculation/">calculation</a>). </p> <p>A recipe for calculating the seats allocated to each party in the Knesset.</p> <p>More information:</p> <ul> <li><a href="http://www.knesset.gov.il/lexicon/eng/seats_eng.htm" rel="nofollow">http://www.knesset.gov.il/lexicon/eng/seats_eng.htm</a></li> <li><a href="https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system" rel="nofollow">https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system</a></li> <li>(Hebrew) <a href="http://bechirot.gov.il/election/about/Pages/CalculatingSeatsMethod.aspx" rel="nofollow">http://bechirot.gov.il/election/about/Pages/CalculatingSeatsMethod.aspx</a></li> <li>(Hebrew) <a href="http://main.knesset.gov.il/About/Lexicon/Pages/seats.aspx" rel="nofollow">http://main.knesset.gov.il/About/Lexicon/Pages/seats.aspx</a></li> </ul> Numbers as Ranges - iterable integers (C++) 2014-10-02T12:13:52-07:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578945-numbers-as-ranges-iterable-integers/ <p style="color: grey"> C++ recipe 578945 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/range/">range</a>). Revision 2. </p> <p>This header file makes simple integers iterable. Note that it works only on C++11 or above.</p> <p>Usage:</p> <pre class="prettyprint"><code>#include "num_range.h" for (int i : 3) cout &lt;&lt; i &lt;&lt; endl; </code></pre> <p>Output: 0 1 2</p> <p>Implementation note: This code is far too generic. We only need <code>DerefableInt</code>. The templates are there for no practical reason.</p> <p>Cons: pollutes namespace std; nonstandard idiom;</p> Bader-Offer Method (Hagenbach-Bischoff) (Python) 2014-02-13T04:33:19-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578831-bader-offer-method-hagenbach-bischoff/ <p style="color: grey"> Python recipe 578831 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/calculation/">calculation</a>). Revision 3. </p> <p>A recipe for calculating the seats allocated to each party in the Knesset.</p> <p>More information:</p> <ul> <li><a href="http://www.knesset.gov.il/lexicon/eng/seats_eng.htm" rel="nofollow">http://www.knesset.gov.il/lexicon/eng/seats_eng.htm</a></li> <li><a href="https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system" rel="nofollow">https://en.wikipedia.org/wiki/Hagenbach-Bischoff_system</a></li> <li>(Hebrew) <a href="http://www.bechirot.gov.il/elections19/heb/about/MandatesSystem.aspx" rel="nofollow">http://www.bechirot.gov.il/elections19/heb/about/MandatesSystem.aspx</a></li> </ul> Priority Queue (with deletion) (Python) 2013-12-08T21:12:55-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578780-priority-queue-with-deletion/ <p style="color: grey"> Python recipe 578780 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/heap/">heap</a>, <a href="/recipes/tags/heapq/">heapq</a>, <a href="/recipes/tags/priority_queue/">priority_queue</a>, <a href="/recipes/tags/queue/">queue</a>). Revision 5. </p> <p>Based on the interface defined in aima-python <a href="http://aima-python.googlecode.com/svn/trunk/utils.py" rel="nofollow">http://aima-python.googlecode.com/svn/trunk/utils.py</a></p> <p>Yields better performance.</p> RecursionError exception: concise and informative output (Python) 2015-07-05T23:46:59-07:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578660-recursionerror-exception-concise-and-informative-o/ <p style="color: grey"> Python recipe 578660 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/exception/">exception</a>, <a href="/recipes/tags/handler/">handler</a>, <a href="/recipes/tags/recursion/">recursion</a>). Revision 3. </p> <p>Replaces the default exception hook with one that, upon "infinite recursion", removes the last cycle. This results in a significantly cleaner and shorter error message.</p> <p>Usage: simply import &lt;module&gt; as _</p> <p>For more details see the descussion here: <a href="https://mail.python.org/pipermail/python-ideas/2013-September/023190.html" rel="nofollow">https://mail.python.org/pipermail/python-ideas/2013-September/023190.html</a></p>