Last active
December 16, 2015 15:58
-
-
Save johandahlberg/5459321 to your computer and use it in GitHub Desktop.
Ugly code example for slides on Best practices in scientific computing.
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
object UglyCodeExample extends App { | |
def m(stringToTransform: String): String = { | |
def t(string: String): List[String] = { | |
def th(string: String, si: Int): List[String] = { | |
if (si == 0) Nil | |
else { | |
val (firstString, secondString) = string.splitAt(si); val newString = secondString + firstString | |
newString :: th(string, si - 1)}} | |
th(string, string.length) | |
} | |
val list: List[String] = t(stringToTransform); val sortedList = list.sortWith((x, y) => { x <= y }); val lastColumn = sortedList.map(row => row.last).mkString | |
lastColumn | |
} | |
println(m("^BANANA|")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment