package kapitel_03 /** * 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 scala.annotation.tailrec object AuD_03_06_GGT_App extends App { import Math.{max, min} @tailrec def GGTRec(m: Int, n: Int): Int = if (m == n) m else GGTRec(max(m,n) - min(m,n), min(m,n)) def GGTIter(m: Int, n: Int): Int = { var x = m var y = n while (x != y) { val (x_, y_) = (max(x,y) - min(x,y), min(x,y)) x = x_ y = y_ } x } println(GGTRec(12, 18)) println(GGTIter(12, 18)) }