Skip to main content
1 of 4
Tommy
  • 931
  • 7
  • 7

The R language: No calls to + or -...

sum(as.numeric(readLines(stdin(), 2)))

Example:

> sum(as.numeric(readLines(stdin(), 2)))
123
456
[1] 579

The [1] 579 is the answer 579 (the [1] is to keep track of where in the result vector your are since in R all values are vectors - in this case of length 1)

Note that R has + operators just like most languages - it just so happens that it has sum too that sums up a bunch of vectors...

> sum(1:10, 101:110)
[1] 1110
Tommy
  • 931
  • 7
  • 7