36
1
My teacher always gives me the most complicated set of math problems for homework. Like: pg. 546: 17-19, 22, 26, pg. 548: 35-67 odd, 79, 80-86 even
. And I want to know in advance how much time to set aside for my homework, but I don't want to have to figure all that out. That's why its your task to program it for me.
Specifications
- You will get a string detailing the problems that I have to complete as args, stdio, etc.
- They will be comma separated (possibly
comma-space
separated) - It will include single problems in the form of just a number (e.g.
79
) - And ranges in the form
17-18
(again, you have to deal with optional spaces) - The ranges are inclusive of both ends
- The ranges will optionally be suffixed by
odd
oreven
, which you have to take into account. - A set of ranges/pages will be prepended by a page number in the form
pg. 545:
, again having to deal with optional spaces. You can safely ignore these, as you need to get the problems over all the pages - The text may be in uppercase or lowercase, but will not be both.
- Return, stdout, etc. the number of problems I have to do for homework.
- Since this is code-golf, shortest code in bytes wins!
Test Cases
pg. 546: 17-19, 22, 26, pg. 548: 35-67 odd, 79, 80-86 even -> 27
pg. 34: 1 -> 1
PG. 565: 2-5,PG.345:7 -> 5
pg. 343: 5,8,13 - 56 even,pg. 345: 34 - 78,80 -> 70
pg.492: 2-4 odd,7-9 even -> 2
12Can the professor give you a range of
2-4 odd
? It appears to cause some problems for simpler approaches. – Björn Lindqvist – 2015-06-03T03:06:29.2901^ I think this should be a test case, according to the current problem statement. – mbomb007 – 2015-06-03T15:10:49.707
2There should be this test case:
pg.492: 2-4 odd,7-9 even -> 2
– mbomb007 – 2015-06-03T15:40:19.9702Can the ranges overlap? E.g.
22-26,25-30
? – Reto Koradi – 2015-06-03T17:32:54.8571@RetoKoradi no. – Maltysen – 2015-06-03T23:18:17.997
1@BjörnLindqvist yes – Maltysen – 2015-06-03T23:18:47.640
Also, is there always a space before
odd
andeven
? – mbomb007 – 2015-06-04T02:34:22.013@mbomb007 yeah. – Maltysen – 2015-06-04T02:35:00.183