typestar

GCD in Rust

Euclid's algorithm, still the shortest correct answer after two thousand years.

fn gcd(mut a: u64, mut b: u64) -> u64 {
    while b != 0 {
        let t = b;
        b = a % b;
        a = t;
    }
    a
}

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
89
Tokens
40
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 27 seconds.

Type this snippet

Step 2 of 4 in Functions, step 24 of 39 in Language basics.

← Previous Next →

GCD in other languages