/** * Beispiel aus * * - Algorithmen und Datenstrukturen für Dummies * - von Andreas Gogol-Döring und Thomas Letschert * - Verlag Wiley-VCH; Oktober 2019 * - Kapitel 3, Daten und ihre Struktur * * @author A. Gogol-Döring, Th. Letschert */ import Foundation struct AuD_03_06_GGT { static func GGTRec(m: Int, n: Int) -> Int { if (m == n) { return m } else { return GGTRec(m: max(m,n) - min(m,n), n: min(m,n)) } } static func GGTIter(m: Int, n: Int) -> Int { var x = m var y = n while (x != y) { let (x_, y_) = (max(x,y) - min(x,y), min(x,y)) x = x_ y = y_ } return x } static func run() { print(GGTRec(m: 12, n: 18)) print(GGTIter(m: 12, n: 18)) } }