Factor, 488 bytes: USING: arrays ascii kernel math math.parser math.ranges pcre sequences ; IN: examples.golf.homework : c ( a -- b ) >lower "(?:[,:]|^) *(\\d+) *(?:- *(\\d+) *(e|o)?)?" findall [ rest [ second dup string>number swap or ] map dup length 1 = [ drop 1 ] [ dup length 2 = [ first2 swap - 1 + ] [ first3 "o" = [ [a,b] [ odd? ] count ] [ [a,b] [ even? ] count ] if ] if ] if ] map sum ;