Inspired by this challenge, and similar to this and this.
After seeing these, I figured I would continue the trend as there was no inclusive/exclusive sum. The goal here is to sum an interval of integers, either inclusive and exclusive, and output the total to stdout.
Input format: either a (
or [
followed by 2 comma separated integers followed by a )
or ]
. Ex: [a, b]
(a, b]
[a, b)
(a, b)
- Note:
b > a >= 0
and the range will always contain at least 1 value. - Input regex:
[\(\[]\d+,\d+[\)\]]
Examples:
Input -> Output
[2,6] -> 20
(15,25] -> 205
[0,16) -> 120
(15,20) -> 70
[1,2) -> 1
(2,12] -> 75
[11,16] -> 81
(15,29) -> 286
[14,15) -> 14
(2,16] -> 133
(12,18) -> 75
This is code-golf, so the shortest code in bytes wins.