Skip to content

Instantly share code, notes, and snippets.

@matklad
Created January 15, 2017 15:21
Show Gist options
  • Save matklad/9c283f5cd2dfdac7635671e0b5d1b0ce to your computer and use it in GitHub Desktop.
Save matklad/9c283f5cd2dfdac7635671e0b5d1b0ce to your computer and use it in GitHub Desktop.
class Zn(private val modulus: Int) {
fun int(x: Int): ZnInt = ZnInt(x % modulus)
operator fun ZnInt.plus(rhs: ZnInt): ZnInt = int(this.value + rhs.value)
}
class ZnInt(val value: Int)
fun main(args: Array<String>) {
val ring = Zn(92)
ring.run {
val x = int(62)
val y = int(111)
println(x + y)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment