Skip to content

Instantly share code, notes, and snippets.

@duanebester
Created July 4, 2015 20:02
Show Gist options
  • Save duanebester/294f190b7040d95540f0 to your computer and use it in GitHub Desktop.
Save duanebester/294f190b7040d95540f0 to your computer and use it in GitHub Desktop.
Hacker Rank Warmup - Very Big Sum
//
// 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