Last active
October 13, 2019 17:44
-
-
Save leifwickland/188e0fbb693caf9b02a232a2981f6c6d to your computer and use it in GitHub Desktop.
encodePair.scala
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
def encodePair(pair: (Char, Char)): (Char, Char) = findLetterInSquare(pair._1) match { | |
case (a, b) => findLetterInSquare(pair._2) match { | |
case (`a`, `b`) => throw new Exception("UNPOSSIBLE!") // same cell | |
case (`a`, d ) => (indexToLetter((a, (b+1)%5)), indexToLetter((a, (d+1)%5))) // same row | |
case ( c, `b`) => (indexToLetter(((a + 1)%5, b)), indexToLetter(((c+1)%5, b))) // same column | |
case ( c, d ) => (indexToLetter((a, d)),indexToLetter((c, b))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment