#
# euclid.jako
#
# Knuth, Donald E.
# The Art of Computer Programming
# Volume 1: Fundamental Algorithms
# Third Edition
#
# Section 1.1
# Algorithm E (Euclid's algorithm)
# Page 2
#
# Copyright (C) 2001-2005, The Perl Foundation
# This program is free software. It is subject to the same
# license as the Parrot interpreter.
#
# $Id: /mirror/trunk/languages/jako/examples/euclid.jako 12840 2006-05-30T15:08:05.048089Z coke  $
#

use sys;

var int m, n, r;

m = 96;
n = 64;

sys::print("Algorithm E (Euclid's algorithm)\n");
sys::print("  Calculating gcd($m, $n) = ...\n");

r = m % n;
while (r != 0) {
  m = n;
  n = r;
  r = m % n;
} 

sys::print("  ... = $n\n");

