Last month I borrowed a plenty of books from the library. They all were good books, packed with emotions and plot-twists. Unfortunately, at some points I got very angry/sad/disappointed, so I tore some pages out.
Now the library wants to know how many pages I have torn out for each book.
Your goal is to write a program, which takes a sorted, comma-delimited list of numbers as input and prints the minimum and maximum possible page count I could have torn out. Each line represents a book, each number represents a missing page from the book.
Example input:
7,8,100,101,222,223
2,3,88,89,90,103,177
2,3,6,7,10,11
1
1,2
Example output:
4/5
5/6
3/6
1/1
1/2
4/5
means, that I may have torn out either 4 or 5 pages, depending on which side the book's page numbering starts. One could have torn out page 6/7, page 8/9, page 100/101, and page 222/223 (4 pages). Alternatively, one could have torn out page 7/8, page 99/100, page 101/102, page 221/222, and page 223/224 (5 pages).
Remember that a book page always has a front and a back side. Also the page numbering differs from book to book. Some books have even page numbers on the left page; some on the right page. All books are read from left to right.
Shortest code in bytes win. Strict I/O format is not required. Your programs must be able to take one or more books as input. Have fun.
4/5
and5/4
) \$\endgroup\$min/max
or allmax/min
. (Although, personally, I'd prefer that not to be part of the spec!) \$\endgroup\$programs must be able to take one or more books as input
rule? Most (if not all) will just wrap the code to verify a single book into a loop or something. IMHO it just add an overhead to the answer with little to no gains to the challenge. This questions already got lots of answers, so it's better to keep this as is, but keep this in mind for you future challenges. \$\endgroup\$1,3,5,7,9,11,13,15,17,18
- for the benefit of languages whose built-insort
method sorts lexicographically by default (assuming the requirement of consistently sorted output is added to the spec). \$\endgroup\$