47
7
99 bugs in the code
The adaption of "99 bottles of beer on the wall" for computer science where the bugs increase instead of the bottles decreasing is often re-posted around the internet. Example T-Shirt Here.
I think it'll be interesting to see potential recursion and random number generation across a huge variety of languages and finding the most efficient ways to do it.
There's a fair few other challenges to do with 99 bottles of beer but none seem to have an increasing and decreasing number!
Challenge
Your program or function should take no input and then print
99 bugs in the code
99 bugs in the code
Take one down and patch it around
X bugs in the code
(blank line)
Where X is the previous integer minus 1 plus a random integer in the range [-15,5].
You can merge the minus 1 into the random integer, hence allowing the range [-16,4].
Ranges can be exclusive, so minus one plus (-16,6) or (-17,5).
The random integers don't have to be evenly distributed they just have to all be possible.
The program always starts with 99 bugs.
You can ignore the grammatical error of "1 bugs".
The program should stop when the number of bugs is 0 or negative and print
0 bugs in the code
There should never be a negative number of bugs. The ending should look like
Y bugs in the code
Y bugs in the code
Take one down and patch it around
0 bugs in the code
(blank line)
0 bugs in the code
A trailing new line is acceptable.
- Your code can be a full program or a function.
- There is no input.
- The output should be to stdout or returned.
- Warnings/errors in logs/STDERR are okay as long as STDOUT has the required text. See here for more info.
This is code-golf so the shortest code in bytes wins.
1
Related: 1 2 (difference: in this challenge the output can be arbitrarily long).
– user202729 – 2018-05-29T14:16:06.983why is merging the 1 in the random only allowed if the random distribution is uniform? It makes no difference (AFAICT), as
rand(-15,5)-1
could get simplified torand()*21 - 15 - 1 = rand()*21 - 16
for any random number generation implementation. – dzaima – 2018-05-29T14:23:26.883We always will start at 99 correct ? – Muhammad Salman – 2018-05-29T14:26:15.933
@dzaima that's exactly what i assumed – The random guy – 2018-05-29T14:33:58.770
@dzaima yes you're right. I'd got it in my head that it would affect the averages or something. I'll change it – Sam Dean – 2018-05-29T14:43:07.053
@MuhammadSalman yep always starts at 99 – Sam Dean – 2018-05-29T14:44:21.497
16A more realistic scenario would be if the sign of the random number was flipped! – Stewie Griffin – 2018-05-29T15:21:03.373
9I am disappointed, that the requirements don't include that the program must have a bug once a negative number is encountered, like crashing, overflowing to max int or similar ;). – allo – 2018-05-30T09:58:49.020
@allo I guess in theory all the answers will crash if the random number keeps being positive! – Sam Dean – 2018-05-30T10:26:59.847
3
"The random integers don't have to be evenly distributed they just have to all be possible." reminded me of https://xkcd.com/221/
– Ivo Beckers – 2018-05-30T12:33:30.2331Is the fact that the output isn't to match the metre of the original bugging anyone else, or is it just me? – Baldrickk – 2018-05-30T12:52:50.127
2
It's a shame 99 has no random number generation.
– Jonathan Allan – 2018-05-30T21:07:48.5471Are trailing newlines allowed? – Giuseppe – 2018-05-31T11:24:18.470
Title should be "Quantum Bugs in the Code" – Magic Octopus Urn – 2018-06-01T00:55:29.613
Is the "continuously print" an actual requirement? (Some answers actually produce the whole string.) – Jonathan Allan – 2018-06-01T15:40:39.803
"Warnings in logs are okay." Does this mean warnings (or errors) in stderr are acceptable? – Reinstate Monica -- notmaynard – 2018-06-01T16:15:22.790
How strict is the output format? In QBasic, it's WAY easier if the numbers are allowed to have a leading space. – DLosc – 2018-06-01T19:49:06.093
@JonathanAllan I would prefer the whole string not all be printed at the end but I think it's a little late to enforce that now – Sam Dean – 2018-06-04T09:10:09.823
1Agreed - maybe edit the challenge to just say "print" then. – Jonathan Allan – 2018-06-04T09:11:14.170
@DLosc That output format is HIGHLY preferred but I have allowed COBOL to have signs before numbers because formatting adds so many characters so I'll allow it in general for languages that struggle formatting numbers. – Sam Dean – 2018-06-04T09:13:19.397
1
RE: @iamnotmaynard's question: I believe that the default is that if the chosen output is somewhere other than STDERR then any coincident STDERR may simply be ignored (This is along with the fact that we may choose to output to STDERR or as the top of the stack etc, and ignore other coincident output(s)) - I would suggest actually removing the requirement "The output should be to stdout or returned" (use defaults)
– Jonathan Allan – 2018-06-04T09:22:34.7231...also your comment "so for now I'm going to say they're not okay" would invalidate my Python 2 answer since it adhere's to the spec as written - it outputs to stdout - but performs a divide by zero to force an early exit. – Jonathan Allan – 2018-06-04T09:41:23.637
As per @Giuseppe's question, are trailing newlines (plural) allowed? – JayCe – 2018-06-04T14:53:38.560
@JayCe a single trailing new line is allowed – Sam Dean – 2018-06-04T15:24:55.080
a single trailing new line is allowed
: That would make the recent javascript and C# entries invalid judging from the TIO links. – JayCe – 2018-06-08T19:02:03.373@JayCe Yes they are invalid. The above wasn't a rule change, the main post always said "A trailing new line". – Sam Dean – 2018-06-11T09:33:55.060