Created
September 21, 2010 11:32
-
-
Save ymnk/589543 to your computer and use it in GitHub Desktop.
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
$ scala | |
Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_16). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> def caesarCipher(text:String, n: Int) = { | |
| val l = (' ' to '~').toList | |
| val ll = (l drop n) ::: (l take n) | |
| text map (l compose ll.zipWithIndex.toMap) mkString | |
| } | |
caesarCipher: (text: String,n: Int)String | |
scala> caesarCipher("The quick brown fox jumps over the lazy dog", 3) | |
res0: String = Qeb|nrf`h|_oltk|clu|grjmp|lsbo|qeb|i^wv|ald | |
scala> caesarCipher("Qeb|nrf`h|_oltk|clu|grjmp|lsbo|qeb|i^wv|ald", (' ' to '~').toList.size-3) | |
res1: String = The quick brown fox jumps over the lazy dog | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment