Created
August 21, 2022 06:19
-
-
Save akiomik/f25db43a4e829b2eaf511bfd535c7fac to your computer and use it in GitHub Desktop.
A simple word decoder for "7 days to end with you"
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
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