-
-
Save waynejo/de2ee78e389c7127c9550d67c7dfc5f6 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
import java.io.FileInputStream | |
import collection.immutable.HashMap | |
import scala.annotation.tailrec | |
import scala.io.StdIn | |
def transforms(number: BigInt, subjectNumber: BigInt): BigInt = { | |
number * subjectNumber % 20201227 | |
} | |
def loopedTransforms(subjectNumber: BigInt, loop: Int, number: BigInt = 1): BigInt = { | |
if 0 == loop then | |
number | |
else | |
loopedTransforms(subjectNumber, loop - 1, transforms(number, subjectNumber)) | |
} | |
def findLoop(subjectNumber: BigInt, target: BigInt, number: BigInt = 1, loop: Int = 0): Int = { | |
if number == target then | |
loop | |
else | |
findLoop(subjectNumber, target, transforms(number, subjectNumber), loop + 1) | |
} | |
def solve25_1(cardPublicKey: BigInt, doorPublicKey: BigInt): BigInt = { | |
val cardLoopSize = findLoop(7, cardPublicKey) | |
loopedTransforms(doorPublicKey, cardLoopSize) | |
} | |
@main def solve25() = | |
val in = new FileInputStream("example25-1.in") | |
System.setIn(in) | |
val key1 = StdIn.readInt() | |
val key2 = StdIn.readInt() | |
println(solve25_1(key1, key2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment