[Community Puzzle] Table of Contents

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @burdanas,validated by @papyjo,@odaxav and @FredericLocquet.
If you have any issues, feel free to ping them.

All test cases seem to be working fine for me, except validator 02 Numbers. I’m sure I’m most likely making a small mistake, but I can’t see why, since the validator doesn’t show me the input and expected output. Maybe there could be an extra test case that’s similar to 02 Numbers?

Does your code works if the title (or a subtitle) number is 10 ? It happens only in validator 2.

2 Likes

You can try that :

20
15
A 1
B 2
C 3
D 4
E 5
F 6
G 7
H 8
I 9
J 10
K 11
L 12
M 13
N 14
O 15
2 Likes

I think indeed I have a silly issue with the number 10 :slight_smile: at least the test case you provided fails my code, so I can continue debugging :smiley: Thank you!

as Remi suggested, be prepared to handle cases where the chapter “index” and the page number becomes multiple digits
i.e.
1 Title1…4
… some filler …
20 Title2…10 – make sure you handle this case by correspondingly reducing the number of “.” characters

I don’t understand what “section” means. Translating it into my native language has not helped me understand it. The output in the first example does not make sense to me either.

How do I know what integer to put in front of the title?

I don’t understand what “section” means. Translating it into my native language has not helped me understand it. The output in the first example does not make sense to me either.

Yeah, “section” may seem a weird word to use here. Just consider it a line in the table of contents, and every heading and sub-heading gets its own line.

How do I know what integer to put in front of the title?

First, bear in mind that the number of ">"s in front of the title represents the level. So:

  • All titles without “>” in front are level 0. They are numbered 1, 2, 3 (of level 0)…

  • Then under each of the level 0 titles, the titles with one “>” are level 1. They are numbered 1, 2, 3 (of level 1)… Take care that the level 1 titles under one level 0 title are numbered separately from the level 1 titles under another level 0 title.

  • Then under each of the level 1 titles, the titles with two ">"s are level 2. They are numbered 1, 2, 3 (of level 2)… Again take care that each group of level 2 titles is numbered independently.

  • And so on and so forth.

Oh, now it makes sense! Similar to the table of contents in Word.

1 Title1...............................4
    1 Subtitle1........................5
        1 Subsubtitle1.................5
    2 Subtitle2........................6

Instead of separate sentences it would be
1 Heading…
1.1
1.1.1
2

Thanks for the explanation!

1 Like