airemalalaJerendos airemalalaJerendos
  • 10-12-2016
  • Computers and Technology
contestada

Design a recursive version of the Euclidean algorithm

Respuesta :

rsmith6559
rsmith6559 rsmith6559
  • 11-12-2016
Here's a recursive Python program that finds the greatest common denominator:

#!/usr/bin/python

import sys

def gcdR( x, y ):
    if( y ):
        return( gcdR( y, x % y ) )
    return x
       

if( __name__ == "__main__" ):
    x = max( int( sys.argv[ 1 ] ), int( sys.argv[ 2 ] ) )
    y = min( int( sys.argv[ 1 ] ), int( sys.argv[ 2 ] ) )

    print gcdR( y, x % y )

    sys.exit( 0 )


Answer Link

Otras preguntas

Can someone show me how to do Mean absolute deviation What is the means-to-MAD ratio of the two data sets, expressed as a decimal? Data set Mean Mean abso
does anyone know about this one? I appreciate you guys helping me((:
The fog slowly crept by is what type of figurative language
Which answer shows a correct way to divide the word at the end of a line? A. u-pon B. up-on C. upo-n D. cannot be divided
What is the product? -5* (-3) * ( -7) * (2) * (0.5) A. –210 B. –105 C. 105 D. 210
factor completely : 6x^2 - 4x - 2
What are the cause and the effect of the Treaty of Guadalupe Hidalgo
In Eastern Europe, the transition to independent and democratic governments can best be described as
Which product is negative? A. –3 • 5 • (–6) • 4 B. –7 • (–3) • (–9) • 0 C. –4 • (–6) • (–3) • (–5) D. –3 • 4 • (–2) • (–7)
Cattle are bred to create offspring that produce a lot of milk. What is this an example of?