Most viewed recipes tagged "common"http://code.activestate.com/recipes/tags/common/views/2016-03-03T07:12:28-08:00ActiveState Code RecipesFinding the GCD of a list of numbers (a.k.a. Reducing numbers in a list) (Python)
2010-07-06T18:52:55-07:00Stephen Akikihttp://code.activestate.com/recipes/users/4172143/http://code.activestate.com/recipes/577282-finding-the-gcd-of-a-list-of-numbers-aka-reducing-/
<p style="color: grey">
Python
recipe 577282
by <a href="/recipes/users/4172143/">Stephen Akiki</a>
(<a href="/recipes/tags/common/">common</a>, <a href="/recipes/tags/denominator/">denominator</a>, <a href="/recipes/tags/gcd/">gcd</a>, <a href="/recipes/tags/greatest/">greatest</a>, <a href="/recipes/tags/lisst/">lisst</a>, <a href="/recipes/tags/reduce/">reduce</a>).
</p>
<p><a href="http://akiscode.com/articles/gcd_of_a_list.shtml" rel="nofollow">http://akiscode.com/articles/gcd_of_a_list.shtml</a></p>
<p>This python code snippet allows you to find the GCD of a list of numbers, after this it is a simple matter of diving all the numbers in the list by the GCD to reduce it.</p>
<p>Why this works...</p>
<p>The GCD of a list of numbers [a, b, c] is GCD(GCD(a, b), c). The reduce function does exactly this and thus gives you the GCD of all the numbers in the list.</p>
Extended Euclidean Algorithm (Python)
2016-03-03T07:12:28-08:00Samuel James Ericksonhttp://code.activestate.com/recipes/users/4187478/http://code.activestate.com/recipes/578631-extended-euclidean-algorithm/
<p style="color: grey">
Python
recipe 578631
by <a href="/recipes/users/4187478/">Samuel James Erickson</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/common/">common</a>, <a href="/recipes/tags/discrete/">discrete</a>, <a href="/recipes/tags/divisor/">divisor</a>, <a href="/recipes/tags/euclid/">euclid</a>, <a href="/recipes/tags/extended/">extended</a>, <a href="/recipes/tags/gcd/">gcd</a>, <a href="/recipes/tags/greatest/">greatest</a>, <a href="/recipes/tags/logarithm/">logarithm</a>).
Revision 2.
</p>
<p>given input of integers a and b, this program returns GCD(a,b) along with integers x and y such that ax+by=GCD(a,b).</p>
GCD of an arbitrary list (Python)
2010-12-22T00:05:45-08:00Jason Schornhttp://code.activestate.com/recipes/users/4176312/http://code.activestate.com/recipes/577512-gcd-of-an-arbitrary-list/
<p style="color: grey">
Python
recipe 577512
by <a href="/recipes/users/4176312/">Jason Schorn</a>
(<a href="/recipes/tags/arbitrary/">arbitrary</a>, <a href="/recipes/tags/common/">common</a>, <a href="/recipes/tags/divisor/">divisor</a>, <a href="/recipes/tags/gcd/">gcd</a>, <a href="/recipes/tags/greatest/">greatest</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/schorn/">schorn</a>).
</p>
<p>Given an arbitrary list (of length >= 1) of positive integers, return the greatest common divisor (<code>gcd</code>) of the list.</p>
Shortest Common Supersequence algorithms (Python)
2013-10-02T12:52:23-07:00Rutger Saalminkhttp://code.activestate.com/recipes/users/4187940/http://code.activestate.com/recipes/578678-shortest-common-supersequence-algorithms/
<p style="color: grey">
Python
recipe 578678
by <a href="/recipes/users/4187940/">Rutger Saalmink</a>
(<a href="/recipes/tags/approximation/">approximation</a>, <a href="/recipes/tags/bound/">bound</a>, <a href="/recipes/tags/breadth_first_search/">breadth_first_search</a>, <a href="/recipes/tags/common/">common</a>, <a href="/recipes/tags/depth_first_search/">depth_first_search</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/shortest/">shortest</a>, <a href="/recipes/tags/super/">super</a>).
</p>
<p>The Shortest Common Supersequence (SCS) problem is an NP-hard problem (<a href="https://en.wikipedia.org/wiki/Shortest_common_supersequence" rel="nofollow">https://en.wikipedia.org/wiki/Shortest_common_supersequence</a>), which occurs in problems originating from various domains, e.g. Bio Genetics. Given a set of strings, the common supersequence of minimal length is sought after. Below a set of algorithms is given, which I used in approximating and/or backtracking the optimal solution(s). </p>