I'm making a page selector for my super cool terminal-based blog program. In order for it to fit correctly into the design, it has to have some constraints.
The page selector can only display a certain number of numbers at a time due to the constraints of the UI system. If there are more characters then can fit, they must be removed and replaced with an ellipsis (which itself counts as a number). The system will try to display up to three numbers around the selected one (which is displayed surrounded by square brackets) and distribute the rest of the numbers evenly at the ends.
Your task is to, given a number of pages, selector width (always more than or equal to 3, and always odd), and currently selected number, all of which are both required and positive, print to STDOUT the resulting page selector.
Examples
In: 5 5 1
Out: < [1] 2 3 4 5 >
In: 5 3 1
Out: < [1] ... 5 >
In: 7 5 3
Out: < 1 ... [3] ... 7 >
In: 11 7 4
Out: < 1 ... 3 [4] 5 ... 11 >
In: 11 7 7
Out: < 1 ... 6 [7] 8 ... 11 >
In: 11 9 7
Out: < 1 2 ... 6 [7] 8 ... 10 11 >
In: 7 3 3
Out: < ... [3] ... >
7 3 3
? And for7 4 3
? \$\endgroup\$7 3 3
and7 4 3
. The only current answer gives weird output for these inputs too (and those outputs cannot be correct). \$\endgroup\$