Skip to content

Commit 7312ab0

Browse files
committed
1 parent 9648002 commit 7312ab0

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
title="Views statistics +1 👀">
77
</a>
88
<a href="https://www.codewars.com">
9-
<img src="https://img.shields.io/badge/solved%20kata-1174-red.svg"
9+
<img src="https://img.shields.io/badge/solved%20kata-1175-red.svg"
1010
title="Solved kata 👌">
1111
</a>
1212
<a href="https://github.com/ParanoidUser/codewars-handbook">
@@ -91,7 +91,7 @@ repository.
9191
title="- Complex language features (closures, scopes, monads, etc)&#13;- Complex OOP/Functional concepts&#13;- Basic Design Patterns&#13;- Complex Regular Expressions">6th kyū
9292
</a>
9393
</td>
94-
<td>359</td>
94+
<td>360</td>
9595
</tr>
9696
<tr>
9797
<td>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [How many pages in a book?](https://www.codewars.com/kata/how-many-pages-in-a-book "https://www.codewars.com/kata/622de76d28bf330057cd6af8")
2+
3+
Every book has `n` pages with page numbers `1` to `n`. The `summary` is made by adding up the **
4+
number of digits** of all page numbers.
5+
6+
Task: Given the `summary`, find the number of pages `n` the book has.
7+
8+
### Example
9+
10+
If the input is `summary=25`, then the output must be `n=17`: The numbers 1 to 17 have 25 digits in
11+
total: `1234567891011121314151617`.
12+
13+
Be aware that you'll get enormous books having up to 100.000 pages.
14+
15+
All inputs will be valid.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface HowManyPagesInABook {
2+
static int amountOfPages(int s) {
3+
return s > 38889 ? 9999 + (s - 38889) / 5 :
4+
s > 2889 ? 999 + (s - 2889) / 4 :
5+
s > 189 ? 99 + (s - 189) / 3 :
6+
s > 9 ? 9 + (s - 9) / 2 : s;
7+
}
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
class TestHowManyPagesInABook {
6+
@Test
7+
void sample() {
8+
assertEquals(5, HowManyPagesInABook.amountOfPages(5));
9+
assertEquals(17, HowManyPagesInABook.amountOfPages(25));
10+
assertEquals(97, HowManyPagesInABook.amountOfPages(185));
11+
assertEquals(256, HowManyPagesInABook.amountOfPages(660));
12+
assertEquals(401, HowManyPagesInABook.amountOfPages(1095));
13+
assertEquals(8365, HowManyPagesInABook.amountOfPages(32353));
14+
assertEquals(34902, HowManyPagesInABook.amountOfPages(163404));
15+
}
16+
}

kata/6-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
- [Hidden "Cubic" numbers](hidden-cubic-numbers)
162162
- [Highest Scoring Word](highest-scoring-word)
163163
- [How Many Numbers?](how-many-numbers)
164+
- [How many pages in a book?](how-many-pages-in-a-book)
164165
- [How Much?](how-much)
165166
- [HTML Complementary Color](html-complementary-color)
166167
- [HTML dynamic color string generation](html-dynamic-color-string-generation)

0 commit comments

Comments
 (0)