Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 20, 2015 04:42
Show Gist options
  • Select an option

  • Save shigemk2/b4f37c22e9eab9ddce7f to your computer and use it in GitHub Desktop.

Select an option

Save shigemk2/b4f37c22e9eab9ddce7f to your computer and use it in GitHub Desktop.
def pn(str: String): Int = pnPrime(str.split(" ").toList)
def pnPrime(list: List[String]): Int = list match {
case "+"::x::ys => x.toInt + pnPrime(ys)
case _ => list.head.toInt
}
println(pn("1"))
println(pn("+ 1 2"))
println(pn("+ 1 + 2 3"))
println(pn("+ + 1 2 3"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment