11
A counterstring is some sort of self-describing test data that is used in software testing. Not sure it was actually invented by James Bach, but I know it from there.
The idea is as follows: the test data contains many asterisk (*
). The number in front of the asterisk tells you how long the test data is at that point. If you need to know a position in the test data that is not an asterisk, find the last asterisk, look at the number before and add the number of digits that follow.
The sequence starts like this:
2*4*6*8*11*14*17*20*23*
^
As you can see, the marked asterisk is at position 14.
If a file happens to be truncated as follows
[...]2045*20
then you can derive that there is a limit of 2047 characters somewhere (2045 where the asterisk is plus 2 for 2
and 0
).
It's your task to create the shortest (this is code-golf) program that outputs (std::out or file or whatever) an arbitrary long test string of that format. The length in characters is given as argument. The program shall support up to 2 GB test data (input value 2147483647 characters).
"Dangerous" positions in the 2 GB file:
8*11*
98*102*
998*1003*
9998*10004*
99998*100005*
999995*1000003*
9999995*10000004*
99999995*100000005*
999999995*1000000006*
This should answer @Leaky Nun's question if there is a decision to make between 995*999* and 995*1000* or similar: no.
The end of the 2 GB file with input value 2147483647 is:
2147483640*2147483
If it does not halt then how do you test it? – Leaky Nun – 2016-08-23T21:24:42.527
You can interrupt at any time I'd say. Plus you could stop at 2 GB if you like. Just thought the code is shorter if the while loop does not need a condition – Thomas Weller – 2016-08-23T21:25:46.167
2Is that length in characters? – TheBikingViking – 2016-08-23T21:31:14.300
4Can you prove that we would never have to choose between
995*999*
and995*1000*
or anything like that? – Leaky Nun – 2016-08-23T21:36:59.783Are both of those acceptable then? – ThreeFx – 2016-08-23T21:49:21.560
If you're only creating the 2GB version for yourself, why don't you remove that line and only tell us to create the string up to a length as input? – Leaky Nun – 2016-08-23T21:53:05.890
@DJMcMayhem It is an input parameter tacked at the end of the challenge. – Leaky Nun – 2016-08-23T21:53:17.667
Is an unlimited answer still viable? – ThreeFx – 2016-08-23T22:00:13.020
1
In the future, please use the Sandbox to iron out kinks in your challenges before posting them.
– Mego – 2016-08-23T22:05:39.143@Mego: agreed, especially because I'm not always active on PCG. – Thomas Weller – 2016-08-23T22:14:39.870
@LeakyNun: no, there's no decision to be made like 995999 and 9951000. I have added the dangerous positions into the question – Thomas Weller – 2016-08-23T22:40:11.583
>
1000
, would998*1003*
be acceptable output, or must it only be998*10
?@TimmyD: IMHO it's ok to create a longer output, since it doesn't matter for the designed real-world use (testing). – Thomas Weller – 2016-08-24T05:07:56.373
1@ThomasWeller If we can create a longer output, can we take no input and just produce the 2GB string? – xnor – 2016-08-24T07:43:31.097