Created
July 1, 2015 11:36
-
-
Save smarr/4c0a88f1054c8735a691 to your computer and use it in GitHub Desktop.
Golo GCD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Arithmetics | |
import java.lang.System | |
function gcd = |x, y, repeat| { | |
var res = 0_L | |
for (var i = 0_L, i < repeat, i = i + 1_L) { | |
var a = x | |
var b = y | |
while a != b { | |
if a > b { | |
a = a - b | |
} else { | |
b = b - a | |
} | |
} | |
res = a | |
} | |
return res | |
} | |
function sum = |x, y| -> x + y | |
function main = |args| { | |
println("Hello world!") | |
for (var i = 0_L, i < 1000_L, i = i + 1_L) { | |
var start = System.nanoTime() / 1000_L | |
gcd(1000000_L, 1312312_L, 100_L) | |
var duration = System.nanoTime() / 1000_L - start | |
println("gcd: " + duration + "ms") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment