Skip to main content
added 74 characters in body
Source Link
Tommy
  • 931
  • 7
  • 7

EDIT This was posted BEFORE the rules changed to disallow sum...

The R language: No calls to + or -... And 9 tie-breaker characters!

sum(as.numeric(readLines(n=2)))

Example:

> sum(as.numeric(readLines(n=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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142

The R language: No calls to + or -... And 9 tie-breaker characters!

sum(as.numeric(readLines(n=2)))

Example:

> sum(as.numeric(readLines(n=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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142

EDIT This was posted BEFORE the rules changed to disallow sum...

The R language: No calls to + or -... And 9 tie-breaker characters!

sum(as.numeric(readLines(n=2)))

Example:

> sum(as.numeric(readLines(n=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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142
added 13 characters in body
Source Link
Tommy
  • 931
  • 7
  • 7

The R language: No calls to + or -... And 9 tie-breaker characters!

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

Example:

> sum(as.numeric(readLines(stdin(), 2n=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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142

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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142

The R language: No calls to + or -... And 9 tie-breaker characters!

sum(as.numeric(readLines(n=2)))

Example:

> sum(as.numeric(readLines(n=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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142
added 246 characters in body
Source Link
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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 11101113.142

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

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.

In this case, readLines returns a string vector of length 2. I then coerce it to numeric (doubles) and sum it up...

Just to show some other features of R:

> 11:20 # Generate a sequence
 [1] 11 12 13 14 15 16 17 18 19 20

> sum(1:10, 101:110, pi)
[1] 1113.142
Source Link
Tommy
  • 931
  • 7
  • 7
Loading