Skip to main content
16 of 16
deleted 1 character in body
primo
  • 33.5k
  • 5
  • 61
  • 139

Perl - 47 Bytes

#!perl -p054
{map$\+=($_%2x9^lc$')!~T,$&..$'*/\d+ ?-/}}{

Amended to pass the new test case.


Original

Perl - 36 Bytes

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

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