/** * Beispiele aus * * - Algorithmen und Datenstrukturen für Dummies * - von Andreas Gogol-Döring und Thomas Letschert * - Verlag Wiley-VCH; Oktober 2019 * - Kapitel 1, Das sind Algorithmen * * @author A. Gogol-Döring, Th. Letschert */ import Foundation struct AuD_01_02_GGT { static func GGT1(m: Int, n: Int) -> Int { let t = (1...1000) .filter( { (x) -> Bool in (n % x == 0) && (m % x == 0) } ) .max() return t.unsafelyUnwrapped } static func GGT2(m: Int, n: Int) -> Int { var t = 1 for x in 1...min(m, n) { if ((m % x) == 0 && (n % x) == 0) { t = x } } return t } static func run() { print(GGT1(m:18, n:12)) print(GGT2(m:18, n:12)) } }