Skip to content

Instantly share code, notes, and snippets.

@akiomik
Created August 21, 2022 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiomik/f25db43a4e829b2eaf511bfd535c7fac to your computer and use it in GitHub Desktop.
Save akiomik/f25db43a4e829b2eaf511bfd535c7fac to your computer and use it in GitHub Desktop.
A simple word decoder for "7 days to end with you"
val NUM_LETTERS = 25
implicit class RichChar(c: Char) {
def shiftLetter(i: Int): Char = {
if (c.isLetter) {
val (a, z) = if (c.isLower) ('a', 'z') else ('A', 'Z')
val n = i % NUM_LETTERS
(((c + n) % z % a) + a).toChar
} else {
c
}
}
}
def words(s: String): Seq[String] = {
for (i <- 0 until NUM_LETTERS) yield s.map(_.shiftLetter(i))
}
words("orqhoc") // Vector(orqhoc, psripd, qtsjqe, rutkrf, svulsg, twvmth, uxwnui, vyxovj, waypwk, xbaqxl, ycbrym, adcsan, bedtbo, cfeucp, dgfvdq, ehgwer, fihxfs, gjiygt, hkjahu, ilkbiv, jmlcjw, knmdkx, lonely, mpofma, nqpgnb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment