Skip to main content
7 of 16
Rollback to Revision 4
primo
  • 33.5k
  • 5
  • 61
  • 139

Perl - 41 Bytes

#!perl -paF,
$\+=/\d+ ?-/*($'-$&>>/o|e/i)+1for@F}{

Counting the shebang as 4, input is taken from stdin.


Sample Usage

$ echo pg. 546: 17-19, 22, 26, pg. 548: 35-67 odd, 79, 80-86 even | perl math-problems.pl
27

$ echo pg. 34: 1 | perl math-problems.pl
1

$ echo PG. 565: 2-5,PG.345:7 | perl math-problems.pl
5

$ echo pg. 343: 5,8,13 - 56 even,pg. 345: 34 - 78,80 | perl math-problems.pl
70

Caveats

For even/odd ranges, it is expected that at least one of the endpoints matches the parity of the range. For example, 11-19 odd, 11-20 odd, and 10-19 odd will all be correctly counted as 5, but 10-20 odd will be over-counted as 6.

primo
  • 33.5k
  • 5
  • 61
  • 139