# How many pages have issues? [duplicate]

At work I've been acting as quality control on our public documents, to make sure that they are WCAG 2.0 compliant. Given the length of some of these documents there tend to be issues, and so I record the issues and the pages they occur on.

# The challenge: Given a string input, output a count of all distinct pages within the string.

## Rules:

• Input will consist of of a non-empty string containing the pages, page ranges, and the issue. Multiple pages and page ranges are guaranteed to be separated by commas ,.
pgs 810-812, 897, 1043, 1047, 1219, 1308, 1317, 1323 restructure reading boxes

pgs 810-812,897,1043, 1047,1219, 1308, 1317, 1323 restructure reading boxes


Both of the above are possible valid inputs.

• This input can be multiple lines, with each line representing a different issue.
pgs 810-812, 897, 1043, 1047, 1219, 1308, 1317, 1323 restructure reading boxes
pgs 816, 819, 826, 827, 829, 853, 861, 866, 885, 1043, 1142, 1143, 1164 table needs to be read as table or figure


You can take a multiline input as a list of strings, with each item in the list being a line. The output is still based on the entirety of the list.

• The input format is not necessarily pgs <page numbers> <issue>.

Both pg 1324 read all and Read all are valid inputs.

If the string consists of only <Issue>, this represents that the document is a single page, and thus the output would be 1 (no matter how many lines of input there are). If there is more than one page, you are guaranteed to not have this format as a line of the input.

## Test Cases:

Input:
------
pgs 810-812, 897, 1043, 1047, 1219, 1308, 1317, 1323 restructure reading boxes

Output:
-------
10

Input:
------
pgs 587,897, 936, 939,946, 1308 single figure
pgs 810-812, 897, 1043, 1047, 1219,1308,1317, 1323 restructure reading boxes

Output:
-------
14

Input:
------
pgs 824, 873, 941-943, 1032, 1034, 1036-1040, 1055, 1071, 1153, 1154, 1228 figures as figures
pgs 1036-1040 Color Contrast for negative balance numbers does not meet WGAC 2.0 guidelines

Output:
-------
18

Input:
------

Output:
-------
1

Input:
------
Pg 1 Read Table as Table
Pgs 1 Color Contrast for negative balance numbers does not meet WGAC 2.0 guidelines

Output:
-------
1



This is , so shortest answer in bytes wins.

## marked as duplicate by Sriotchilism O'Zaic code-golf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jul 20 at 18:02

• Inverse of this? – Veskah Jul 19 at 14:19
• @Veskah Not really an inverse. That one condenses pages into page ranges, the inverse would take page ranges, and output a list of pages. Mine is just a count of involved pages. – william porter Jul 19 at 14:25
• Possible duplicate – Giuseppe Jul 19 at 16:09
• Definitely strongly related, but I'd say the difference in input and output make it not a duplicate. – william porter Jul 19 at 16:16
• @williamporter the core of the challenge is still parsing a format like a,b-c,d; adding a count unique and removing the other characters does not, in my estimation, make it different enough, but the community is welcome to override that. – Giuseppe Jul 19 at 16:37

# 05AB1E, 51 38 bytes

-13 bytes thanks to Kevin Cruijssen!

',ð:#ʒ'-м€.ïß}D.ï≠ÅÏ'-¡¤LsнUʒX<›]˜Ùg1M


Try it online!

### Explanation

                                      // Implicitly Read in multiline string
',ð:#                                //Swap commas with spaces and split on spaces
ʒ'-м€.ïß}                       //Filter list to only those with - removed are numbers
D                      //Duplicate
.ï≠ÅÏ                 //For all the ones that aren't numbers (so the ranges)
'-¡               //Split on dashes
¤L             //Generate list from 1 to the highest number
sнU          //Stick the lower number in the variable U
ʒ®<›]                                //Filter out numbers less than the lower number
˜                               //deep flatten
Ùg                            //Uniquify and count
1M                          //Push 1 then output the largest number in the stack

• 39 bytes. Summary of changes: input as a multi-line string, so |» can be removed. '  has a builtin: ð. The {н can be ß (minimum). '-' :# can simply be a split: '-¡. The D is unnecessary by using ¤ instead of θ (both get the last item, but ¤ doesn't pop, and θ does pop). The ©, ® can be U/X (or alternatively V/Y) so the s can be removed before the filter; these pop and store, whereas © stores without popping. ï can be removed (I think); and D>i1 can be simplified to 1‚à (pair with 1, and then pop+push maximum). – Kevin Cruijssen Aug 1 at 7:55
• Thanks @KevinCruijssen I'll update when I get a chance, some excellent ideas I can use in the future in there too! – Expired Data Aug 1 at 7:59
• Yep, that's why I tried to explain my changes instead of just giving the 39 byter, so you can learn from it for future challenges. :) Nice answer though. That initial ',' :# had me confused for a bit when I changed it to ',¡ like the split on - later on. It will leave leading spaces before the numbers, causing all kind of issues later on in the first filter.. And the € before the .ï is to also filter out the 2.0 I noticed. Nice work-around! :) – Kevin Cruijssen Aug 1 at 8:03
• Too bad ʒ'-мDþQ} also leaves the empty items, which is how I usually only leave numbers. ;) – Kevin Cruijssen Aug 1 at 8:06
• oh, one last byte to golf (for now ;p), so it becomes 38: my suggestion of 1‚à can be 1M (push 1, push largest number on the stack). – Kevin Cruijssen Aug 1 at 8:08

# Perl 5 (-p), 63 bytes

s/-/../g;s/^pgs?|[^., \d].*//g;map$h{$_}=1,eval}{\$\=(keys%h)||1


TIO