Motivation: Sometimes you need to know where you are in a string. You want to be able to look at any part of a string and know exactly where you are, as far as possible.
Challenge: write a program to output a tape measure string of a given length. A tape measure string self describes its length-so-far as often as possible along it's own length.
Rules:
- Your program must take one positive integer parameter, for the total length of the tape measure string
- For each contiguous string of digits in the output, these digits must accurately report the length of the output so far - inclusive!
- Lengths are measured from the start of the string to the end of each number
- As many length numbers as possible should be included in the string
- Avoid ambiguity. Separators/delimiters can be used to avoid numbers being juxtaposed, i.e.
12says twelve not one, two. - The string must always accurately report its total length at its end, with no trailing separators
- You may need multiple separators to keep the lengths accurate, e.g. here's an example tape measure string of length 4:
1--4
Non prescriptive/exhaustive examples:
- tape measure string of length 1:
1 - tape measure string of length 2:
-2 - tape measure string of length 3:
1-3 - tape measure string of length 4:
1--4or-2-4(both report lengths as often as possible, i.e. twice, and end with the correct total length) - tape measure string of length 10:
1-3-5-7-10 - tape measure string of length 11:
1-3-5-7--11or1-3-5--8-11or1-3--6-8-11or1--4-6-8-11or-2-4-6-8-11(all have as many length numbers as possible, and finish with the total string length)
-, and you need to have as many length marks as you possibly can in the string? \$\endgroup\$0. \$\endgroup\$