<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: euclid code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 12:18:58 GMT</pubDate>
    <description>DZone Snippets: euclid code</description>
    <item>
      <title>Modular linear equation solver</title>
      <link>http://snippets.dzone.com/posts/show/4194</link>
      <description>Prints the roots of this equation:&lt;br /&gt;ax = b (mod n)&lt;br /&gt;&lt;br /&gt;Relies on Euclid's extended algorithm:&lt;br /&gt;http://snippets.dzone.com/posts/show/4192&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def solveLinearModularEquation(a, b, n):&lt;br /&gt;  d, xx, yy = euclidExtended(a, n)&lt;br /&gt;  if (b % d == 0):&lt;br /&gt;    x0 = (xx * (b / d)) % n&lt;br /&gt;    for i in xrange(0, d):&lt;br /&gt;      print (x0 + i * (n / d)) % n,&lt;br /&gt;  else:&lt;br /&gt;    print "No solution"&lt;br /&gt;  print&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Jun 2007 15:13:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4194</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Euclid's extended algorithm</title>
      <link>http://snippets.dzone.com/posts/show/4192</link>
      <description>Basically Euclid's algorithm for finding the largest common denominator, this one is modified in order to obtain the numbers d, x, y, where d is the dennominator and they check the following equation:&lt;br /&gt;d = ax + by&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def euclidExtended(a, b):&lt;br /&gt;  if b == 0:&lt;br /&gt;    return a, 1, 0&lt;br /&gt;  dd, xx, yy = euclidExtended(b, a % b)&lt;br /&gt;  d, x, y = dd, yy, xx - int(a / b) * yy&lt;br /&gt;  return d, x, y&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Jun 2007 14:59:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4192</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
    <item>
      <title>Euclid's algorithm</title>
      <link>http://snippets.dzone.com/posts/show/4191</link>
      <description>Euclid(a, b) calculates the largest common denominator d, and returns it.&lt;br /&gt;&lt;br /&gt;Uses the well-known Euclid's algorithm.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def euclid(a, b):&lt;br /&gt;  while b != 0:&lt;br /&gt;    r = a % b&lt;br /&gt;    a = b&lt;br /&gt;    b = r&lt;br /&gt;  return a&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 22 Jun 2007 14:54:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4191</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
  </channel>
</rss>
