How many pages have I torn out?

05AB1E, 13 bytes


Try it online!

Thanks to Emigna for the heads-up on spec changes.


εD>)ÅÈε€θγg}{ – Full program.
ε             – For each book...
 D            – Push two copies of it.
  >           – Increment all the elements of the second copy.
   )          – Wrap the whole stack into a list.
    ÅÈ        – Produces the lists of even natural numbers lower or equal to each element.
      ε       – For each (the modified copies of the book):
       €θ     – Get the last item of each.
         γg   – And split into chunks of equal adjacent elements.
           }  – Close the loop.
            { – Sort the resulting list.

Python 2, 72 56 68 67 bytes

lambda b:[map(len,map(set,zip(*[[p/2,-p/2]for p in t])))for t in b]

Try it online!

JavaScript, 104 93 92 85 80 79 74 bytes

Would be 57 bytes if not for the unnecessary (in my opinion) requirement that each pair of numbers in the output be consistently sorted, or 47 bytes if we only needed to take one book as input.

Input and output are both an array of arrays.

a=>>[0,1].map(n=>new Set(>y+n>>1)).size).sort((x,y)=>x-y))
  • Initially inspired by Olivier's Java solution and my own (currently deleted) Japt solution.
  • 2 bytes saved thanks to Arnauld (plus another 3 we both spotted at the same time) and 10 bytes added thanks to him spotting the broken sorting I'd hoped nobody would notice while that requirement was still under discussion!

Test cases

Test cases are split into individual books for better readability with the last case (which includes the [1,2] edge case) serving to illustrate that this solution supports multiple books in the input.

a=>>[0,1].map(n=>new Set(>y+n>>1)).size).sort((x,y)=>x-y))
o.innerText=` Input                         | Output\n${`-`.repeat(31)}|${`-`.repeat(21)}\n`+[[[7,8,100,101,222,223]],[[2,3,88,89,90,103,177]],[[2,3,6,7,10,11]],[[1,3,5,7,9,11,13,15,17,18]],[[1],[1,2],[8,10]]].map(b=>` `+JSON.stringify(b).padEnd(30)+"| "+JSON.stringify(f(b))).join`\n`
<pre id=o></pre>


a=>>>b.add(y/2|0)&c.add(++y/2|0),b=new Set,c=new Set)&&[b.size,c.size].sort((x,y)=>x-y)))
// 93
a=>>[new Set(>y/2|0)).size,new Set(>++y/2|0)).size].sort((x,y)=>x-y)))
// 92
a=>>[(g=z=>new Set(z).size)(>y/2|0)),g(>++y/2|0))].sort((x,y)=>x-y))
// 85
a=>>[(g=h=>new Set(>y/2|0),g(y=>++y/2|0)].sort((x,y)=>x-y))
// 80
a=>>[(g=n=>new Set(>(y+n)/2|0)).size)(0),g(1)].sort((x,y)=>x-y))
// 79
a=>>[(g=n=>new Set(>y/2+n|0)).size)(0),g(.5)].sort((x,y)=>x-y))
// 76
a=>>[0,.5].map(n=>new Set(>y/2+n|0)).size).sort((x,y)=>x-y))


Code Golf