Guest User

Untitled

a guest
Feb 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. ## How many pages have I torn out?
  2.  
  3. 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.
  4.  
  5. Now the library wants to know how many pages I have torn out for each book.
  6.  
  7. 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.
  8.  
  9. Example input:
  10. ```
  11. 7,8,100,101,222,223
  12. 2,3,88,89,90,103,177
  13. 2,3,6,7,10,11
  14. 1
  15. 1,2
  16. ```
  17. Example output:
  18.  
  19. 4/5
  20. 5/6
  21. 3/6
  22. 1/1
  23. 1/2
  24.  
  25. Your function should accept multiple books
  26. ```
  27. yourSolutionFunction([[7,8,100,101,222,223], [1,2]]) // [ [4,5], [1,2] ]
  28. ```
  29.  
  30. `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).
  31.  
  32. 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.
  33.  
  34. 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.
Add Comment
Please, Sign In to add comment