Skip to content

Instantly share code, notes, and snippets.

@ngsw-taro
Forked from necoco/divisor.kt
Created December 8, 2012 07:17
Show Gist options
  • Save ngsw-taro/4239085 to your computer and use it in GitHub Desktop.
Save ngsw-taro/4239085 to your computer and use it in GitHub Desktop.
宿題
fun divisor(val a: Int,val b: Int) : Int = if(b == 0) a else divisor(b, a % b)
fun main(args: Array<String>){
test(1, divisor(1, 1))
test(2, divisor(2, 4))
test(2, divisor(4, 2))
test(6, divisor(24, 18))
test(6, divisor(18, 24))
test(1, divisor(13, 19))
test(1, divisor(19, 13))
}
fun test(expected : Int, actual : Int) {
if(expected != actual)
throw AssertionError("expected $expected, but actual $actual")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment