-
-
Save omo/de1d90f22a1d5320abdbe31eb6554218 to your computer and use it in GitHub Desktop.
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
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