Skip to content

Instantly share code, notes, and snippets.

@omo

omo/Solution.kt Secret

Created August 4, 2022 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omo/de1d90f22a1d5320abdbe31eb6554218 to your computer and use it in GitHub Desktop.
Save omo/de1d90f22a1d5320abdbe31eb6554218 to your computer and use it in GitHub Desktop.
class Solution {
fun lcm(x: Int, y: Int) : Int {
fun gcd() : Int {
var i = x
var j = y
while (i != j) {
if (i < j) {
j = j - i
} else {
i = i - j
}
}
return i
}
return x * y / gcd()
}
fun mirrorReflection(p: Int, q: Int): Int {
val height = lcm(p, q)
val numHorizontalReflections = height / q - 1
val numTiles = height / p
return if (numTiles % 2 == 0) {
0
} else {
if (numHorizontalReflections % 2 == 1) 2 else 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment