Skip to content

Instantly share code, notes, and snippets.

@johandahlberg
Last active December 16, 2015 15:58
Show Gist options
  • Save johandahlberg/5459321 to your computer and use it in GitHub Desktop.
Save johandahlberg/5459321 to your computer and use it in GitHub Desktop.
Ugly code example for slides on Best practices in scientific computing.
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