lazy val values = "abcdefghijklmnopqrstuvwxyz".toList.zip(Stream.from(1)).toMap def solve (str: String): Int = { ("[aeiou]".r.split(str).toList map evaluate).max } def evaluate (str: String): Int = { (str map (values.getOrElse(_, 0))).sum } solve("zodiacs") // 26 solve("chruschtschov") // 80 solve("khrushchev") // 38 solve("strength") // 57 solve("catchphrase") // 73 solve("twelfthstreet") // 103 solve("mischtschenkoana") // 80
I've always appreciated Scala solutions for their mixed-notation to function-call chaining, it's truly bizarre. 😲
...(str map ([expr]) // prefix-notation chaining... ...[expr]).sum // object-notation chaining...
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
Where hackers, sticks, weekend warriors, pros, architects and wannabes come together
Scala
I've always appreciated Scala solutions for their mixed-notation to function-call chaining, it's truly bizarre. 😲