Created
July 20, 2015 05:09
-
-
Save shigemk2/f310edf38afde0ab110e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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