25
\$\begingroup\$

Challenge Description:

Write a program that asks the user for input. The user will enter Good or Bad. You do not have to support any other input. If the user enters Good, print Bad and vice versa (to stdout etc).

Notes:

1) You cannot use any other pair of two words.

2) Your program only has to ask and print once.

3) You do not need to display prompt string.

4) The output must appear separated from the input by any means.

5) No function is allowed accepting the value and returning the result; User must interact with the program.

Good luck!

\$\endgroup\$
6
  • 10
    \$\begingroup\$ May we write a function that takes input as argument instead of prompting for it? \$\endgroup\$
    – Adám
    Commented Jul 7, 2019 at 14:01
  • 9
    \$\begingroup\$ Please edit your question about whether a function is allowed or not. I would highly recommend not restricting input to STDIN, unless you have a very good reason to (and I can't see one) \$\endgroup\$
    – Jo King
    Commented Jul 9, 2019 at 0:21
  • 2
    \$\begingroup\$ asks the user for input (stdin etc) shows that only STDIN or interactive input is allowed. Please change this to all default I/O methods \$\endgroup\$
    – MilkyWay90
    Commented Jul 9, 2019 at 17:05
  • 1
    \$\begingroup\$ "Asks the user for input", should that be some explicit question? Because an empty CLI prompt isn't really asking for anything … \$\endgroup\$ Commented Jul 10, 2019 at 13:23
  • 7
    \$\begingroup\$ What is the purpose for this restriction? No function is allowed accepting the value and returning the result; User must interact with the program \$\endgroup\$
    – mbomb007
    Commented Jul 12, 2019 at 13:58

90 Answers 90

2
\$\begingroup\$

Jelly, 9 bytes

“GooBa”œ^

Try it online!

Explanation

Multiset symmetric difference between the input and the string “GooBa”.

\$\endgroup\$
5
  • \$\begingroup\$ @JonathanAllan Thanks. Edited \$\endgroup\$
    – Luis Mendo
    Commented Jul 7, 2019 at 16:53
  • \$\begingroup\$ I don't see any indication that the input has to come through STDIN... \$\endgroup\$ Commented Jul 7, 2019 at 18:37
  • \$\begingroup\$ @EriktheOutgolfer Unfortunately the whole way the question is written implies we must have a program which, when run, asks for input (even though no prompt must be displayed). See the OPs own answer too. If you want to get them to change it go for it (although do note that they haven't answered the first, similar although slightly different, question in the comments) \$\endgroup\$ Commented Jul 7, 2019 at 20:29
  • \$\begingroup\$ Looks like OP responded, input isn't restricted to STDIN. \$\endgroup\$ Commented Jul 9, 2019 at 5:43
  • \$\begingroup\$ @EriktheOutgolfer Thanks! Rolled back \$\endgroup\$
    – Luis Mendo
    Commented Jul 9, 2019 at 6:25
2
\$\begingroup\$

PowerShell, 22 20 bytes

'Good','Bad'-ne$args

Try it online!

-2 bytes thanks to mazzy

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 20 bytes \$\endgroup\$
    – mazzy
    Commented Jul 7, 2019 at 19:57
2
\$\begingroup\$

Keg, 22 bytes

?^_^_o=[^aB^_|^ooG^]
\$\endgroup\$
2
\$\begingroup\$

brainfuck, 52 bytes

,>,,<<,[>-----.<---.+++.<<]>[+++++.+[-<-->]<-..>>.>]

Try it online!

Relies on Bad being one letter shorter than Good, so the last input is empty.

Explanation:

,>,,<<,       Get input into the first three cells
[             If the last letter was not empty (i.e. Good)
 >-----.      Decrement 'G' to 'B' and print
 <---.        Decrement 'd' to 'a' and print
 +++.         Increment back to 'd' and print
>>]           End loop
>[            If it is Bad instead
 +++++.       Increment 'B' to 'G' and print
 +[-<-->]<-.. Manipulate into  'o' and print twice
 >>.          Print 'd'
>]            End loop

\$\endgroup\$
2
\$\begingroup\$

Boolfuck, 47 bytes

+>,+;>,;,+;>;;;+;+;+[;<;;;,;+;;+;<];;+;+;;+;;+;

Try it online!

Uses the fact that you can basically just take in the input as bits and then invert certain bits to turn it into the opposite letter.

Explanation:

+>,+;>,;,+;>;;;+;+;+    Print the first letter by inverting the first and third bits of the input
                        'B' = 01000010
                        'G' = 11100010
                        This leaves the tape as
                            1 1 1 1' in the case of Bad
                            1 0 0 1' in the case of Good
                        By making the center cells the inverted bits
[;<;;;,;+;;+;<]         Print the center letters by looping over the two pairs of cells
                        0 1' results in 'a' = 10000110
                        1 1' results in 'o' = 11110110 by printing the 1 in the 2-4th places
                        1 1 1 1' loops twice, while 1 0 0 1' only loops once
;;+;+;;+;;+;            Finally print 'd' = 00100110

\$\endgroup\$
2
\$\begingroup\$

Boolfuck, 110 68 bytes

,+;+[;+;;;;+;+;+;<;]>+;;[+;;;+;+;+;;;;+;+;;+;+;;;;+];+;;+;;;+;+;;+;;

Thanks to Jo King for the massively improved solution!

Try it with Online!

\$\endgroup\$
2
  • \$\begingroup\$ 68 bytes. I think it can be better though \$\endgroup\$
    – Jo King
    Commented Jul 15, 2019 at 0:51
  • \$\begingroup\$ Wow, how were you able to save so many bytes over my answer? \$\endgroup\$
    – EdgyNerd
    Commented Jul 15, 2019 at 6:26
2
\$\begingroup\$

Keg, -rt 20 17 15 13 8 7 bytes (SBCS)

-᠀‘5ƳP↫

Transpiles to:

from KegLib import *
from Stackd import Stack
stack = Stack()
printed = False
iterable(stack, 'GoodBad')
string_input(stack)
maths(stack, '-')

if not printed:
    printing = ""
    for item in stack:
        if type(item) in [str, Stack]:
            printing += str(item)
        elif type(item) == Coherse.char:
            printing += item.v

        elif item < 10 or item > 256:
            printing += str(item)
        else:
            printing += chr(item)
    print(printing)

It's a port of the 05AB1E answer. Essentially, it:

  • Pushes the string "GoodBad"
  • Takes input as a string
  • Subtracts the input from the pushed string. This works by replacing the first instance of the input within GoodBad with nothing.
  • Implicitly prints the resulting string.
  • The -rt flag tells Keg to read tokens from right to left.

Answer History

?G=[øBad|ø‘5Ƴ

Transpiles to the following:

from KegLib import *
from Stackd import Stack
stack = Stack()
printed = False
Input(stack)
character(stack, 'G')
comparative(stack, '=')
if bool(stack.pop()):
    empty(stack)
    character(stack, 'B')
    character(stack, 'a')
    character(stack, 'd')

else:
    empty(stack)
    iterable(stack, 'Good')

if not printed:
    printing = ""
    for item in stack:
        if type(item) is Stack:
            printing += str(item)

        elif type(item) is str:
            printing += custom_format(item)
        elif type(item) == Coherse.char:
            printing += item.v

        elif item < 10 or item > 256:
            printing += str(item)
        else:
            printing += chr(item)
    print(printing)

Explanation

?G=[øBad|ø‘5Ƴ

?            #Get input from user
 G=          #If the first letter is "G"
   [øBad     #Clear the stack and push "Bad"
        |    #Else,
         ø‘5Ƴ#Clear the stack and push the compressed string "Good"
\$\endgroup\$
7
  • 1
    \$\begingroup\$ Wonderful, I could not golf to that length... I have upvoted your answer. \$\endgroup\$
    – user85052
    Commented Jul 12, 2019 at 11:08
  • \$\begingroup\$ @A__ just as i have up voted yours \$\endgroup\$
    – lyxal
    Commented Jul 12, 2019 at 11:29
  • \$\begingroup\$ My answer is a lot worse than yours. You should not have upvoted my answer... \$\endgroup\$
    – user85052
    Commented Jul 12, 2019 at 11:40
  • \$\begingroup\$ Is there any up to date keg documentation? \$\endgroup\$
    – EdgyNerd
    Commented Oct 11, 2019 at 7:09
  • \$\begingroup\$ @EdgyNerd not really. It's been a while since I updated the docs. Most information about new things can be found in the chat/here \$\endgroup\$
    – lyxal
    Commented Oct 11, 2019 at 7:12
2
\$\begingroup\$

C# (Visual C# Interactive Compiler), 30 bytes

Write(Read()>'B'?"Bad":"Good")

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Whitespace, 114 104 103 bytes

(much whitespace)

Try it online!

-5 bytes thanks to Jo King.

-5 bytes by determining if the input is odd or even instead of subtracting "B"

-1 byte thanks to Kevin Cruijssen by using the initial 3 as address for reading characters

sssttl      push "d"
sls         dup (address for "retrieve")
sls         dup (address for "readc")
tlts        readc
ttt         retrieve
ssstsl      push 2
tstt        mod (determine if input is even or odd)
ltssl       jz good
sssl        push "a"
ssttttttl   push "B"
lsll        jmp print
lsssl       lbl good
ssstttsl    push "o"
sls         dup
sstttstsl   push "G"

lssl        lbl print
sssttsssstl 97
tsss        add
tlss        printc
lsll        jmp print
\$\endgroup\$
2
  • 1
    \$\begingroup\$ -1 byte by replacing the sssl (push 0) with sls (dupe the 3 that's used to print "d"). Also a minor error in your explanation: the sssttl - push 2 should be either sssttl - push 3 or ssstsl - push 2 (both result in 0 for B, and either 1 or 2 for G, so the program would be correct in both cases). Alternatively for sssttl - push 3, you could dupe the initial 3 a third time and use a swap after retrieving the input, but that unfortunately results in the same byte-count (repushing 3 or duplicating + swapping are both 6 bytes). \$\endgroup\$ Commented Jan 28, 2020 at 16:09
  • \$\begingroup\$ Thank you. I didn't have the idea to use the 3 as address for the readc-retrieve command. The push 2 was really intended to be a push 2. I wanted to determine if the first input character was even or odd, so I was just lucky it also worked with sssttl. \$\endgroup\$
    – Dorian
    Commented Jan 29, 2020 at 8:04
2
\$\begingroup\$

Kotlin, 52 bytes

fun main()=print("GoodBad".replace(readLine()!!,""))

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ What does the !! operator do? \$\endgroup\$
    – xigoi
    Commented Jul 27, 2021 at 22:45
  • 1
    \$\begingroup\$ !! asserts that a nullable value is not null, effectively casting it down from T? to T or throwing a runtime error if it's null. replace doesn't accept String? but that's what readLine() returns so I have to assert it's not null (since it never will be per the challenge.) \$\endgroup\$
    – snail_
    Commented Jul 27, 2021 at 23:23
2
\$\begingroup\$

MAWP, 59 bytes

%|~88W7MA{88W7M;99W65WM!;;25W25WW;}<88W2M;99W44WM;25W25WW;>

Try it!

\$\endgroup\$
2
\$\begingroup\$

Javascript 50 bytes

alert((305786-parseInt(prompt(),26)).toString(26))

\$\endgroup\$
1
  • \$\begingroup\$ Please add what language you answer uses and a short description of how it functions \$\endgroup\$ Commented Aug 13, 2020 at 11:25
2
\$\begingroup\$

Vyxal r, 7 bytes

`ƛ⁋«Ṫ`-

Try it Online!

This is irony in a nutshell.

Explained

`...`-
`...`  # the string "GoodBad"
     - # ^ - input (removes it)

In the spirit of my Keg answer, here's the compiled code:

global stack, register, printed, output, MAP_START, MAP_OFFSET, _join, _vertical_join, use_encoding, input_level, raw_strings, retain_items, reverse_args, this_function
stack.append("GoodBad")

rhs, lhs = pop(stack, 2); stack.append(subtract(lhs, rhs))
\$\endgroup\$
2
\$\begingroup\$

Zsh, 21 20 bytes

-1 by just defining a variable first instead of using an empty fallback

x=GoodBad
<<<${x/$1}

Try it online! Try it online!

<<<${${[implicit parameter]:-fallback}/pattern[/implicit empty replacement]}

No coreutils, and nearly as good as the Bash+coreutils answer (which is compatible with Zsh).

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Why not x=GoodBad;<<<${x/$1}? \$\endgroup\$
    – pxeger
    Commented Jun 16, 2022 at 11:52
2
\$\begingroup\$

.COM, 31 bytes

org 0x100
mov dx, 0x100
mov eax, 0xA20 + '$$'*0x10000
int 0x21
inc dx
inc dx
xor dword [0x102], 'Good' xor ('Bad'+0x0d000000)
mov al, 0x20
int 0x29     ; Avoid "Badd"
mov ah, 9
int 0x21
ret
\$\endgroup\$
2
\$\begingroup\$

PHP, 30 bytes

<?=strtok(BaGoo,readline()).d;

Best suppress notices.

\$\endgroup\$
3
  • \$\begingroup\$ There is already a shorter PHP answer: codegolf.stackexchange.com/a/187930/81663 \$\endgroup\$
    – Night2
    Commented Oct 14, 2019 at 12:13
  • 1
    \$\begingroup\$ @Night2, reading the question as waiting on a prompt, a readline solution seemed more appropriate as an answer. \$\endgroup\$
    – Progrock
    Commented Oct 14, 2019 at 15:47
  • 1
    \$\begingroup\$ @Night2, but granted if they were to swap $argn for readline(), theirs would still be a shorter solution. \$\endgroup\$
    – Progrock
    Commented Oct 14, 2019 at 15:51
1
\$\begingroup\$

K (oK), 16 bytes

Solution:

$`Bad`Good"Bad"~

Try it online!

Returns "Good" if input is "Bad" otherwise returns "Bad" for all other inputs.

\$\endgroup\$
1
  • \$\begingroup\$ 15 bytes with loose constraints \$\endgroup\$
    – mkst
    Commented Jul 7, 2019 at 20:17
1
\$\begingroup\$

Wolfram Language (Mathematica), 48 44 38 bytes

If[$ScriptInputString=="Bad",Good,Bad]

Try it online!

-4 bytes thanks to Jonathan Allan: using symbols instead of strings as output

-6 bytes by removing Print@, which is implicit in the command-line version of WolframScript and can be simulated on TIO with the -print argument

\$\endgroup\$
6
  • \$\begingroup\$ I don't think it's only the I/O that's wrong (I don't know Mathematica very well though) - adding a Print exposes a problem with the strings I think: TIO (the ? is, no doubt the prompt for input) \$\endgroup\$ Commented Jul 7, 2019 at 17:27
  • \$\begingroup\$ @JonathanAllan I couldn't make it work with TIO either; what I've given runs fine in Mathematica though. Note that there are no strings involved: Good and Bad are symbols here. \$\endgroup\$
    – Roman
    Commented Jul 7, 2019 at 18:04
  • \$\begingroup\$ Ah symbols, right. Is it a full program, or just a snippet which can only run in a REPL (read–eval–print loop) (which is, I guess what you're running the code in)? I see no output command and I don't imagine Mathematica does any by default at the end of a program. Maybe a Mathematica expert can chime in...? \$\endgroup\$ Commented Jul 7, 2019 at 18:10
  • \$\begingroup\$ @JonathanAllan The previous version was a REPL tool for Mathematica. Now I've rewritten it as a command-line tool for wolframscript, using the proper i/o channels. This makes the code a lot longer though. \$\endgroup\$
    – Roman
    Commented Jul 7, 2019 at 18:26
  • 1
    \$\begingroup\$ Looks like you could use symbols for the output to save 4. \$\endgroup\$ Commented Jul 7, 2019 at 18:38
1
\$\begingroup\$

C# (Visual C# Interactive Compiler), 23 bytes

a=>a[0]>66?"Bad":"Good"

Try it online!

\$\endgroup\$
1
\$\begingroup\$

My shortest possible solution in Python (43 bytes)

print({'Good':'Bad','Bad':'Good'}[input()])

And MilkyWay90 further golfed version (-2 bytes)

print({'G':'Bad','B':'Good'}[input()[0]])
\$\endgroup\$
9
  • 1
    \$\begingroup\$ Normally, we recommend leaving challenges up for a while (I generally give it a week) before self-answering. \$\endgroup\$
    – Adám
    Commented Jul 7, 2019 at 14:38
  • \$\begingroup\$ @Adám Good suggestion. \$\endgroup\$
    – Ishaq Khan
    Commented Jul 7, 2019 at 14:40
  • 1
    \$\begingroup\$ print({'G':'Bad','B':'Good'}[input()[0]]) works too for -2 bytes \$\endgroup\$
    – MilkyWay90
    Commented Jul 7, 2019 at 20:14
  • 1
    \$\begingroup\$ print(['Bad','Good'][input()<'C']) works for 34 bytes (-9) \$\endgroup\$
    – MilkyWay90
    Commented Jul 7, 2019 at 20:17
  • \$\begingroup\$ @MilkyWay90 You're genius! \$\endgroup\$
    – Ishaq Khan
    Commented Jul 7, 2019 at 23:39
1
\$\begingroup\$

///, 23 bytes

/#Good/Bad//#Bad/Good/#

Try it online!

There is no other way to take input in /// so it is hard-coded:

/#Good/Bad//#Bad/Good/#<INPUT HERE>
\$\endgroup\$
1
\$\begingroup\$

Pyth, 12 bytes

+-"GooBa"z\d

Try it online!

+-"GooBa"z\d   Implicit: z=input()
 -"GooBa"z     Keep letters in "GooBa" which do not appear in z
+         \d   Append "d", implicit print
\$\endgroup\$
1
\$\begingroup\$

Windows batch, 53 48 47 bytes

-1 bytes, thanks to @Neil for noticing the trivialness of the space before else.

set/pa=
if %a%==Bad (echo Good)else (echo Bad)

set/pa= prompt for input and set a to that input

if %a%==Bad (echo Good)else (echo Bad) antonym for Good and Bad. Unfortunately Windows batch requires whitespace...

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think you can drop the space before else but no other spaces as you noticed. \$\endgroup\$
    – Neil
    Commented Jul 8, 2019 at 9:20
1
\$\begingroup\$

Runic Enchantments, 21 bytes

"Bad":i≠7*?~"Good"@

Try it online!

Prints Good when the input is Bad and prints Bad for all other inputs.

\$\endgroup\$
1
\$\begingroup\$

Sinclair ZX80 BASIC (4K ROM) - 46 tokenized BASIC bytes

 1 INPUT A$
 2 IF A$="GOOD" THEN PRINT "BAD"
 3 IF A$="BAD" THEN PRINT "GOOD"

Sinclair ZX81 BASIC (Also Timex TS 1000/1500 or ZX80 with 8K ROM upgrade) - 45 tokenized BASIC bytes

 1 INPUT A$
 2 PRINT "GOOD" AND A$="BAD";"BAD" AND A$="GOOD"
\$\endgroup\$
1
\$\begingroup\$

Python 3, 37 bytes

print(['Bad','Good'][input()=='Bad'])

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ -3 bytes by replacing input()=='Bad' with input()<'G' \$\endgroup\$
    – Peter
    Commented Jan 22, 2023 at 14:28
1
\$\begingroup\$

Underload, 26 25 16 bytes

(Bad)(Good)Bad^S

Since Underload has no input instructions, input is hard-coded (The ‘Bad’ on the right).

Really proud of this one: Underload has no way to check strings, so I had to go off of the fact the ‘Bad’ contains an a, which is an instruction that puts brackets around the top thing in the stack.

Edit: Saved 9 bytes over my old one by getting rid of 2 pairs of brackets, only using one S and getting rid of some !s and ^s

Try it with Bad!

Try it with Good!

\$\endgroup\$
1
\$\begingroup\$

Racket, 38 bytes

(write(match(read)['Bad'Good][_'Bad]))
\$\endgroup\$
1
\$\begingroup\$

33, 20 bytes

Itj71m"Good"'Bad'ntp

I don't have it on TIO yet, I'll update this when I do.

Explanation:

It                   | Get input
  j71m           n   | If the first character is 'G'
      "Good"       p | - Print "Good"
            'Bad' tp | Else, print "Bad"
\$\endgroup\$
1
1
\$\begingroup\$

Extended BrainFuck: 29 28

,>,,,[>|"Bad">>]<[>|"Good">]

-1 bytes thanks to @JoKing

The compiled bf code can run on an interpreter that expects stream end after the last letter and a interpreter that uses 0 as the EOF value. eg. bf -n or beef. eg

> bf ebf.bf < GoodBad.ebf > GoodBad.bf
> echo Bad | bf -n GoodBad.bf
Good
> echo Good | bf -n GoodBad.bf
Bad
\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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