• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

Erweiterter Euklidischer Algorithmus

mac@engelthal

Rheinischer Krummstiel
Registriert
15.03.07
Beiträge
386
Hallo zusammen,
kann mir jemand helfen, diesen Algorithmus in Apple Script zu formulieren? Wäre echt cool, wenn mir da jemand helfen könnte.
Gruß,
--Alex
 

mac@engelthal

Rheinischer Krummstiel
Registriert
15.03.07
Beiträge
386
Habe die Lösung gefunden:

Code:
on extEucl(a, b)
	set aa to a
	set bb to b
	
	set x0 to 1
	set x1 to 0
	set y0 to 0
	set y1 to 1
	
	set x to 0
	set y to 1
	
	if b = 0 then
		set x to 1 --Alpha
		set y to 0 --Beta
		set b to a --gcD
	else
		set q to a div b
		set r to a mod b
		
		repeat while r is not 0
			set x to x0 - q * x1
			set y to y0 - q * y1
			
			set x0 to x1
			set y0 to y1
			
			set x1 to x
			set y1 to y
			
			set a to b
			set b to r
			
			set q to a div b
			set r to a mod b
		end repeat
	end if
	
	if x < 0 then
		set x to bb + x
		set y to (1 - aa * x) / bb
	end if
	
	return x
end extEucl