Skip to content

Instantly share code, notes, and snippets.

@leifwickland
Last active October 13, 2019 17:44
Show Gist options
  • Save leifwickland/188e0fbb693caf9b02a232a2981f6c6d to your computer and use it in GitHub Desktop.
Save leifwickland/188e0fbb693caf9b02a232a2981f6c6d to your computer and use it in GitHub Desktop.
encodePair.scala
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