Skip to content

Instantly share code, notes, and snippets.

@jamesmcm
Created October 12, 2019 17:54
Show Gist options
  • Select an option

  • Save jamesmcm/a796b3023c9b6dd2c753025d88ef4853 to your computer and use it in GitHub Desktop.

Select an option

Save jamesmcm/a796b3023c9b6dd2c753025d88ef4853 to your computer and use it in GitHub Desktop.
scalaq.scala
def encodePair(pair: (Char, Char)): (Char, Char) = {
(findLetterInSquare(pair._1), findLetterInSquare(pair._2)) match {
case ((A, B), (A, D)) => (indexToLetter((A, (B+1)%5)), indexToLetter((A, (D+1)%5))) // same row
case ((A, B), (C, B)) => (indexToLetter(((A + 1)%5, B)), indexToLetter(((C+1)%5, B))) // same column
case ((A, B), (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