Skip to content

Instantly share code, notes, and snippets.

@MicFin
Last active February 8, 2018 14:03
Show Gist options
  • Save MicFin/61c0630a20fca354ec37b5f2943eb396 to your computer and use it in GitHub Desktop.
Save MicFin/61c0630a20fca354ec37b5f2943eb396 to your computer and use it in GitHub Desktop.

How many pages have I torn out?

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

Your function should accept multiple books

yourSolutionFunction([[7,8,100,101,222,223], [1,2]]) // [ [4,5], [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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment