Skip to the content

The last night counts too

Problem

A member reads 30 pages a night, not one more, and before borrowing a book wants to know how many nights it will last. The night with only a few pages left is a night too: "Maps of Salt," at 340, lasts 12 nights and not 11. And "The Lighthouse," at exactly 210, lasts 7 and not 8. Show the title, the pages, and the nights for each book, in that order.

What it has to return

These rows, in any order

titlepagesnights
The Lighthouse2107
Maps of Salt34012
The Blue House1806
Three Winters42014
Loose Leaves954
The Train South2609
Long Night31011
Short Stories1204

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT title, pages,
  pages / 30 AS nights
FROM books;
Solve this challenge

It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.

More O(log n) challenges

See all challenges →