Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 20, 2015 05:09
Show Gist options
  • Select an option

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

Select an option

Save shigemk2/f310edf38afde0ab110e to your computer and use it in GitHub Desktop.
def pn(str: String): Int = pnPrime(str.split(" ").toList)._1
def pnPrime(src: List[String]): (Int, List[String]) = src match {
case "+"::x::ys => {
val a = x.toInt
val (b, next) = pnPrime(ys)
(a + b, next)
}
case _ => (src.head.toInt, src.tail)
}
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