Created
July 4, 2015 20:02
-
-
Save duanebester/294f190b7040d95540f0 to your computer and use it in GitHub Desktop.
Hacker Rank Warmup - Very Big Sum
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
// | |
// Code for: https://www.hackerrank.com/challenges/a-very-big-sum | |
// | |
object Solution { | |
def main(args: Array[String]) { | |
val num = readInt() | |
// See if number is positive or negative | |
def pos(s:String):Long = if(s.head == '1') s.toLong else ((s.toLong) * -1) | |
// Read numbers, map to positive or negative Longs, then sum | |
val output = readLine().split(' ').toList.map(x => pos(x)).sum | |
println(output) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment