24
\$\begingroup\$

This challenge is inspired by @LuisMendo's MATL answer to my "binary multiples" challenge.

Task

Pick a challenge that is open and that has been posted before this one; let me call it the "linked challenge". The linked challenge must be a challenge whose task involves producing output.

Write the shortest code possible that satisfies the following restrictions:

  • Your code must contain the characters b, u and g in your program, in this order and consecutively (case-insensitive, so "bug", "BUG", "Bug", "bUg", ... are all fair game.);
  • Your code must not contain the letters b, u and g more than once (case-insensitive);
  • Your code should be a valid submission for the linked challenge;
  • When any subset of the (case-insensitive) characters bug are removed, your program no longer fulfils the task of the linked challenge. This may happen because your program now produces the wrong output (i.e. fails test cases), because it halted with an error, because it runs indefinitely and never returns (if this is the case, be prepared to prove your program runs indefinitely), etc.
  • Your code should not be an integral copy - nor a trivial modification* - of a submission that already exists in the linked challenge (for example, you may not copy @LuisMendo's MATL answer to my "binary multiples" challenge);

Input

Your program takes input as per the specs of the linked challenge you choose.

Output

Your program, in its correct state (i.e. with a bug**), must abide by the output specs of the linked challenge you choose.

* This is subjective so I appeal to your common sense; any imaginative modification should be fair game, even if in retrospective it is "trivial". This "no trivial modifications" rule will be "enforced" by me downvoting answers I think disrespect this...

** Sit down, take a moment to let this sink in. Your program has a bug. And yet your program is correct.

Posting an answer

When you post your answer, please provide a link to your linked challenge.


This is so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it! If you dislike this challenge, please give me your written feedback. Happy golfing!

\$\endgroup\$
  • 2
    \$\begingroup\$ @a'_' I do not understand how that challenge presents a loophole; can you please clarify? \$\endgroup\$ – RGS Mar 17 at 15:34
  • 4
    \$\begingroup\$ @RGS Interesting challenge. I wonder if the challenge can be more focused by specifying just 1 linked challenge to solve. As of right now, my effort is divided between picking a linked challenge, and golfing/solving the linked challenge. \$\endgroup\$ – Surculose Sputum Mar 17 at 15:48
  • 1
    \$\begingroup\$ @ouflak nope, the three characters must be really really consecutive :) so that they spell "bug" :) \$\endgroup\$ – RGS Mar 17 at 15:55
  • 1
    \$\begingroup\$ It's impossible to do this in brainfuck... \$\endgroup\$ – S.S. Anne Mar 18 at 1:22
  • 2
    \$\begingroup\$ Python has a built-in constant called __debug__ which is True by default. Removing some of its bug will obviously be an error. Though I can't find a suitable challenge for that... \$\endgroup\$ – Bubbler Mar 18 at 1:49

23 Answers 23

15
\$\begingroup\$

Japt, 4 bytes

Challenge: Output with the same length as the code

BUG³

Test it

Explanation

B, U, and G are variables for 11, the input, and 16 respectively.

When applied to a number, ³ brings it to the third power.

In Japt, only the last expression is outputted, so only \$16^3 = 4096\$ is outputted, which is the same length as the code (4).

Since B and U are ignored, removing them have no effect on the output. However, their removal changes the length of the program, making it invalid. Removing G raises either the input (U) or 11 (B) to the third power. While \$11^3 = 1331\$ is 4 bytes, the program is only two bytes, making the output invalid. The variable U defaults to 0 when there is no input given, and \$0^3 = 0\$, which is only one byte long.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ This seems like a pretty clever answer. Why did you delete it? \$\endgroup\$ – ouflak Mar 17 at 20:19
  • 4
    \$\begingroup\$ @ouflak the first version had a bug, I deleted it to give me some time to edit it \$\endgroup\$ – Embodiment of Ignorance Mar 17 at 20:21
  • 5
    \$\begingroup\$ @EmbodimentofIgnorance ba-dum crash! \$\endgroup\$ – S.S. Anne Mar 18 at 1:37
8
\$\begingroup\$

JavaScript (ES7), 47 bytes

Linked challenge: How many petals around the rose

a=>a.map(n=>t+=n**3&parseInt('bug',35)%9,t=0)|t

Try it online!

How?

This is a port of my Python answer to the linked challenge. This answer requires a bitwise AND with a constant, which happens to be \$6\$.

This \$6\$ is obtained with the cumbersome parseInt('bug',35)%9 and removing any subset of characters from bug would produce a different (and therefore invalid) constant.

   s   | parseInt(s, 35) | mod 9
-------+-----------------+-------
 'bug' |      14541      |   6
 'ug'  |       1066      |   4
 'bg'  |        401      |   5
 'bu'  |        415      |   1
 'g'   |         16      |   7
 'b'   |         11      |   2
 'u'   |         30      |   3
 ''    |        NaN      |  NaN
|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ 'bug'.length*2 is an alternative \$\endgroup\$ – Surculose Sputum Mar 17 at 16:14
  • 4
    \$\begingroup\$ @SurculoseSputum That's actually not possible: there's a 'g' in 'length'. \$\endgroup\$ – Arnauld Mar 17 at 16:28
  • \$\begingroup\$ That's unfortunate :( I was thinking of Python when writing that comment. \$\endgroup\$ – Surculose Sputum Mar 17 at 16:30
  • \$\begingroup\$ a=>a.map(n=>t+=n**3&('bug'[2]&&6),t=0)|t for 40 bytes \$\endgroup\$ – Embodiment of Ignorance Mar 17 at 20:06
  • \$\begingroup\$ @EmbodimentofIgnorance There's also &!!'bug'[2]*6 for 39 bytes, but I think I'll stick with my sub-optimal version for this answer, so feel free to use it in another one! \$\endgroup\$ – Arnauld Mar 17 at 20:14
8
\$\begingroup\$

Polyglot, 31 bytes

Linked challenge: “Hello, World!”

This is a full program, as per the original challenge requirements.

print('Hello, World'+'bug!'[3])

Try it in JavaScript (V8)!

Try it in Python!

|improve this answer|||||
\$\endgroup\$
5
\$\begingroup\$

Triangular, 6 bytes

Linked to Challenge: Shortest code to produce infinite output

bug>%<

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Basically the same thing works in Hexagony, probably other layout languages, too. \$\endgroup\$ – FryAmTheEggman Mar 17 at 18:27
4
\$\begingroup\$

C (gcc), 156 bytes

Answer to 99 bugs in the code. Not competitive, but funny.

#define S"%d bugs in the code\n"
d;f(i){for(i=99;i;i=d)printf(S S"Take one down and patch it aro\x75nd\n"S"\n",i,i,d=(d=i+rand()%21-16)<0?0:d);printf(S,0);}

Also beats the C solution there.

Try it online!

|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ +1 for the "right" challenge to solve. \$\endgroup\$ – Bubbler Mar 18 at 2:41
3
\$\begingroup\$

APL (Dyalog Extended), 6 bytes

Solves Output with the same length as the code.

×'BUG'

Try it online!

Prints 1 1 1\n, 6 bytes in total.

In regular APL, monadic × is Signum for numbers (-1 if negative, 1 if positive, 0 if zero). Extended provides an extended (no pun intended) definition for characters (-1 for lowercase, 1 for uppercase).

Because numeric arrays are printed with a space between items, deleting one char out of BUG will remove two bytes (<space>1) from the output, thus failing to solve the challenge. Deleting two chars will remove four output bytes, and deleting all of them gives only a single newline.

|improve this answer|||||
\$\endgroup\$
3
\$\begingroup\$

Zsh/Bash/others, 15 bytes

Challenge: Output with same length as code

echo BUG{1..3}

Try it online (Zsh)! Try it online (Bash)!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ The second submission is invalid because the linked challenge should produce output! \$\endgroup\$ – RGS Mar 18 at 6:40
  • \$\begingroup\$ Argh, thanks. Fixed. \$\endgroup\$ – GammaFunction Mar 18 at 6:41
3
\$\begingroup\$

Python 3, 24 bytes

while __debug__:print(1)

Try it online!

Linked challenge: Shortest infinite loop producing output

Uses the fact pointed out by @Bubbler:

Python has a built-in constant called __debug__ which is True by default. Removing some of its bug will obviously be an error. Though I can't find a suitable challenge for that...

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Removing the bu from your answer still gives the correct answer -- the rules state that any subset of the characters in bug being removed should cause the problem to return something different, not just the bug as a whole!! \$\endgroup\$ – Value Ink Mar 17 at 21:49
  • \$\begingroup\$ @ValueInk I changed the language and used python instead. \$\endgroup\$ – Lyxal Mar 18 at 3:56
  • \$\begingroup\$ Quoting my spec, "The linked challenge must be a challenge whose task involves producing output." \$\endgroup\$ – RGS Mar 18 at 6:51
  • 1
    \$\begingroup\$ @RGS that's been fixed now. I've really lost the ability to read challenges today. :P \$\endgroup\$ – Lyxal Mar 18 at 6:57
  • 3
    \$\begingroup\$ I really like the use of __debug__, however simply using "bug"[2] should be shorter (and more boring). TIO. \$\endgroup\$ – Surculose Sputum Mar 18 at 10:16
3
\$\begingroup\$

Lua and perhaps a polyglot in concept, 25 28 32 bytes

Along the lines of Arnauld's answer, linked to challenge Output programming language name.

print('\076\117\097 5.'..#'bUg')

Try it online!

Added 3 bytes Thanks to @RGS spotting the 'u' in 'Lua'
Added 4 bytes Thanks to @MariaMiller for the 'L' and the 'a' as well

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ This is not a valid answer because the letter "u" appears twice in your code! \$\endgroup\$ – RGS Mar 17 at 18:16
  • \$\begingroup\$ @RGS, Oh my God. You're right! Let me fix this up. \$\endgroup\$ – ouflak Mar 17 at 18:19
  • 1
    \$\begingroup\$ @MariaMiller, Refresh your browser. Unless I'm misunderstanding your comment, RGS already pointed that out and I've already updated the answer. \$\endgroup\$ – ouflak Mar 17 at 18:58
  • 1
    \$\begingroup\$ According to the linked kata, your code cannot include any characters of the language's name, but case sensitive so it can be fixed: You can fix L and a with the same way you fixed u, and I just noticed that you can change bug to bUg or BUG or whatever and this will be alright. Sorry if I was confusing. \$\endgroup\$ – Maria Miller Mar 17 at 22:26
  • 1
    \$\begingroup\$ Didn't they realize that both l and A aren't banned in outputting the language name? 25 bytes \$\endgroup\$ – petStorm Mar 18 at 6:11
2
\$\begingroup\$

Create output twice the length of the code

MathGolf, 6 bytes

╘╘BUG]

Try it online!

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

CJam, 4 bytes

Challenge: Output with the same length as the code

It's working. But I still didn't manage a 3-byte solution.

BUG^

Try it online!

Why it works

B    "Constant for 11";
 U   "Constant for 0";
  G  "Constant for 16";
   ^ "Bitwise XOR";

0 XOR 16 is 16, therefore it outputs 1116.

Removing a single character

UG^

It just outputs 16 without other calculations.

BG^

It outputs 27 because 11 XOR 16 is 27.

BU^

It outputs 11 because 11 XOR 0 is 0.

Removing 2 characters

CJam doesn't have implicit input, so all these programs would throw an error.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Ruby, 24 bytes

Linked to Find the number of integers in the range from 1 to N that ends with 2

->n{(n+5+"bug".size)/10}

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ What is the challenge this problem is linked to? \$\endgroup\$ – RGS Mar 17 at 18:16
  • 1
    \$\begingroup\$ Sorry, I accidentally deleted it. Added. \$\endgroup\$ – Maria Miller Mar 17 at 18:17
1
\$\begingroup\$

Linked to challenge: Find the number of integers in the range from 1 to N that ends with 2

Python 2, 95 \$\cdots\$ 39 35 bytes

Saved a byte (in a previous version) thanks to Maria Miller!!!
Saved a byte (in an other previous version) thanks to Surculose Sputum!!!

def f(n):print((n+len("bug")+5)/10)

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ 74 bytes \$\endgroup\$ – Maria Miller Mar 17 at 18:15
  • \$\begingroup\$ @MariaMiller Nice one - thanks! :-) \$\endgroup\$ – Noodle9 Mar 17 at 18:19
  • \$\begingroup\$ 30 bytes \$\endgroup\$ – Maria Miller Mar 18 at 16:47
1
\$\begingroup\$

Linked to challenge: Find the number of integers in the range from 1 to N that ends with 2

C (gcc), 51 42 40 bytes

i;f(n){for(i=0;n+=2,"bug"[i++];);n/=10;}

Try it online!

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

JavaScript (Node.js), 39 bytes

Linked Challenge: How many petals around the rose

a=>a.map(n=>t+=n**3&!!'bug'[2]*6,t=0)|t

Try it online!

Originally posted as a golf to Arnauld's answer.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 4 bytes

Linked challenge: Output with same length as the code.

Port of Embodiment of Ignorance's Japt answer.

bug₄

Try it online!

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

W, 6 bytes

Challenge: Output the same length as code

BUG"2*

Repeats the string "BUG" multiple times.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Python 2, 13 bytes

Solves Output with the same length as the code.

print 'bug'*4

Try it online!

Prints bugbugbugbug\n.


Python 2, 27 bytes

Solves Hello, World!

print'bugHello, World!'[3:]

Try it online!

Removing some of bug will chop off characters from the beginning of 'Hello, World!'.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ The middle answer isn't valid because the linked challenge has to produce output! \$\endgroup\$ – RGS Mar 18 at 6:35
  • \$\begingroup\$ I mean in my spec :) you have to pick a challenge where you have to produce output "The linked challenge must be a challenge whose task involves producing output." \$\endgroup\$ – RGS Mar 18 at 6:43
  • 1
    \$\begingroup\$ @RGS Oops, sorry, I missed the restriction. \$\endgroup\$ – Bubbler Mar 18 at 6:43
1
\$\begingroup\$

J, 7 bytes

Solves I double the source, you double the output!

>:Debug

Try it online! Try it online!Try it online!

Prints 1 as given, 2 doubled.

How it works

Monadic >: is "increment" (add 1), dyadic >: is "greater or equal" (x >= y).

>:Debug    NB. increment 0; gives 1

>:Debug>:Debug
  Debug>:Debug    NB. 0 >= 0; gives 1
>:                NB. increment it; gives 2

J, 12 bytes

Solves Output with the same length as code.

echo 6#Debug

Try it online!

Somewhat similar to Python, J has a stdlib variable Debug which is initialized to the number 0. 6# replicates the zero 6 times, and echo prints it. The output formatting is identical to APL's (space-separated numbers), so the output is 0 0 0 0 0 0\n.

Being a terse language, I suspect there could be a more suitable challenge for J which gives a shorter solution using Debug.

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

C (gcc), 24 bytes

This one for real.

Answer to Swap the parity.

f(x){x=-(-x^!"bug"[3]);}

Try it online!

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

Io, 18 bytes

Challenge: Output programming language name

(Joke ruiner over here, never mind.)

This errors (outputting the language name) when the bug is inside, and it doesn't error when any part of the bug is removed.

If you think that this uses the i character (taken from the question):

Note that this is case sensitive. I can still use the char 'b' because it's different from 'B'.

if("bug"size>2,iO)

Try it online!

Explanation

        size       // Is the length of
   "bug"           // the string "bug"
            >2     // larger than 2?
if(           ,    // If so,
               iO  // Access an undefined variable
                 ) // Otherwise, do nothing

Io, 19 bytes

Challenge: Output with the same length as the code

"bug"at(2)cos print

Try it online!

Explanation

"bug"               // The sequence "bug"
     at(2)          // The 3rd index of that
                    // (Out-of-bounds indexing returns nil)
                    // This returns an integer for an in-bound index
          cos       // Find the cosine of that
                    // (Cosine over nil throws an error)
              print // Print that value to STDOUT. (WITHOUT a newline)

Io, 19 bytes

Challenge:Shortest infinite loop producing no output

while("bug"at(2),0)

Try it online!

Explanation

      "bug"         // Base string "Bug"
           at(2)    // Try to access the 3rd item of the string
                    // (Out-of-bounds returns nil)
while(          ,   // While that's true:
                    // (So a string is always true and nil is always false)
                 0) // No action needed
|improve this answer|||||
\$\endgroup\$
  • 1
    \$\begingroup\$ What does the last one solve? \$\endgroup\$ – user253751 Mar 18 at 16:04
1
\$\begingroup\$

C (gcc), 26 bytes

Answer to Shortest code to produce infinite output

f(){printf("bug"+2)&&f();}

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Maybe I'm missing something but your TIO link produces no output \$\endgroup\$ – RGS Mar 18 at 17:07
  • \$\begingroup\$ @RGS I forgot the footer. Hang on... \$\endgroup\$ – S.S. Anne Mar 18 at 17:08
  • \$\begingroup\$ Woops, I only noticed now... The character u shows up twice in your answer! \$\endgroup\$ – RGS Mar 20 at 15:39
  • 1
    \$\begingroup\$ @RGS Fixed..... \$\endgroup\$ – S.S. Anne Mar 20 at 15:43
1
\$\begingroup\$

Java 8, 88 bytes

Linked challenge: Is this number a prime?
Given a number, outputs truthy/falsey depending on whether it is a prime number.

n->{int i="bug ".charAt(3)-31;for(;n%++i%n>0;);System.console().printf("%s",""+(n==i));}

Try it online (Note: System.console() is System.out on TIO, since TIO doesn't support console).

Explanation:

n->{                // Method with integer parameter and no return-type
  int i=            //  Integer `i`, starting at:
    "bug ".charAt(3)//  Get the fourth character from String `"bug "` as unicode value
     -31;           //  and subtract 31 from it, so it'll become 1
  for(;n%++i        //  Increase `i` by 1 first before every iteration with `++i`
            %n>0;); //  And loop as long as `n` modulo-`i` is not 0
                    //  NOTE: The second `%n` is to stop the loop for input n=1
  System.console().printf("%s",
                    //  Print to STDOUT with String format:
    ""+(            //   Convert the following boolean to String:
        n==i));}    //   Check if `n` and `i` are equal

Prime checker credit goes to @SaraJ's answer here, which is rather ingenious.

Things I had to do to comply to the challenge:

  1. The challenge description mentions program (and technically the linked challenge as well), but this isn't possible in Java. I know five different ways of creating a full program in Java, but each of them requires at least one of the letters bgu. Usually I can get past source-restrictions by using \u-unicode escapes, but since u is one of the restricted characters that's also not an option here. Luckily OP allowed functions as well, which is (much) shorter anyway. EDIT: There is actually a sixth way, by using the same approach as the enum M{A;{}} but with a class M{A;{}} instead, but that would still leave the problem of getting input for the prime number check I wanted to do, which can only be done with java.util.Scanner(System.in).nextInt(), containing an u as well.
  2. I couldn't use return since it contains an u. And I also couldn't use System.out.print(...), since it contains an u as well. So instead, I use System.console().printf("format",...)
  3. Since I wanted to print a boolean, the format to use in the printf would be "%b". Unfortunately, b is blocked, so instead I use "%s" and convert the boolean to a string.
  4. And last thing to tackle was of course sneaking bug in, so it works with it, but doesn't work anymore without it. I've done this by changing the int i=1; to int i="bug ".charAt(3)-31;, which grabs the fourth character in the String (the space) as unicode value, and subtracts 31 from it to make it 1. If any of the b, u, and/or g is removed, the .charAt(3) will fail with a StringIndexOutOfBoundsException.
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Kevin, I fear you missed something very important: as soon as any part of "bug" is removed, your program should no longer work. So assigning it as variable somewhere doesn't really work, because having bu=0 still works... \$\endgroup\$ – RGS Mar 20 at 16:52
  • \$\begingroup\$ @RGS Should be fixed now. \$\endgroup\$ – Kevin Cruijssen Mar 20 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.