title: Euclidean algorithm pseudocode conversion to Swift?
body: <p>I have been working on a function for reducing fractions in Swift, and came across the Euclidean algorithm for finding the greatest common factor (<a href="http://en.wikipedia.org/wiki/Euclidean_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Euclidean_algorithm</a>)</p>
  
  <p>I converted the pseudo code into swift, but yet I am confused how this is going to give me the greatest common factor if it is returning <code>a</code> which I thought was supposed to be the numerator of the fraction. Any help on this would be greatly appreciated. Thanks!</p>
  
  <p><strong>Pseudocode:</strong></p>
  
  <pre><code>function gcd(a, b)
      while b ≠ 0
         t := b
         b := a mod b
         a := t
       return a
  </code></pre>
  
  <p><strong>Swift:</strong></p>
  
  <pre><code>var a = 2
  var b = 4
  
  func gcd(a: Int, b: Int) -&gt; Int {
      var t = 0
      while b != 0 {
          t = b
          let b = a % b
          let a = t
      }
      return a
  }
  
  println("\(a)/\(b)")
  </code></pre>
  
  <p><strong>Console output:</strong>  2/4</p>