16
\$\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\$
  • 9
    \$\begingroup\$ May we write a function that takes input as argument instead of prompting for it? \$\endgroup\$ – Adám Jul 7 at 14:01
  • 8
    \$\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 Jul 9 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 Jul 9 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\$ – user0721090601 Jul 10 at 13:23
  • 5
    \$\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 Jul 12 at 13:58

60 Answers 60

1
\$\begingroup\$

Java, 30 bytes

s->s.charAt(0)>66?"Bad":"Good"

TIO

\$\endgroup\$
  • \$\begingroup\$ How does it take input from the user (e.g. by reading from stdin) and print the result (instead of just returning it)? \$\endgroup\$ – nimi Jul 7 at 22:14
  • \$\begingroup\$ @nimi OP hasn't specified whether IO includes arguments and returns. By default, it is allowed \$\endgroup\$ – Benjamin Urquhart Jul 7 at 22:52
  • \$\begingroup\$ "ask the user for input" sounds like reading the input from stdin (or equivalent) to me. "print" usually means print to stdout (or equivalent). To my understanding the IO defaults are overwritten. \$\endgroup\$ – nimi Jul 7 at 22:59
  • \$\begingroup\$ @nimi I can argue a missing argument error is a prompt. As for output, you do have a point. \$\endgroup\$ – Benjamin Urquhart Jul 7 at 23:04
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\$
  • 1
    \$\begingroup\$ Normally, we recommend leaving challenges up for a while (I generally give it a week) before self-answering. \$\endgroup\$ – Adám Jul 7 at 14:38
  • \$\begingroup\$ @Adám Good suggestion. \$\endgroup\$ – Ishaq Khan Jul 7 at 14:40
  • 1
    \$\begingroup\$ print({'G':'Bad','B':'Good'}[input()[0]]) works too for -2 bytes \$\endgroup\$ – MilkyWay90 Jul 7 at 20:14
  • 1
    \$\begingroup\$ print(['Bad','Good'][input()<'C']) works for 34 bytes (-9) \$\endgroup\$ – MilkyWay90 Jul 7 at 20:17
  • \$\begingroup\$ @MilkyWay90 You're genius! \$\endgroup\$ – Ishaq Khan Jul 7 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\$

Perl 5 -p, 15 bytes

$_=/B/?Good:Bad

Try it online!

\$\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
    \$\begingroup\$ I think you can drop the space before else but no other spaces as you noticed. \$\endgroup\$ – Neil Jul 8 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\$

PHP, 26 23 bytes

A ternary is just cheaper:

<?=$argn==Bad?Goo:Ba?>d

Try it online!

Original answer, 26 bytes

<?=[Ba,Goo][$argn==Bad]?>d

Try it online!

Or 21 bytes (but this is basically Arnauld's answer)

<?=$argn[3]?Ba:Goo?>d

Try it online!

\$\endgroup\$
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\$

Boolfuck, 110 68 bytes

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

Thanks to Jo King for the massively improved solution!

Try it with Online!

\$\endgroup\$
  • \$\begingroup\$ 68 bytes. I think it can be better though \$\endgroup\$ – Jo King Jul 15 at 0:51
  • \$\begingroup\$ Wow, how were you able to save so many bytes over my answer? \$\endgroup\$ – EdgyNerd Jul 15 at 6:26
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\$
  • \$\begingroup\$ @JoKing Yes. Thanks :) \$\endgroup\$ – Sylwester Aug 3 at 12:33
1
\$\begingroup\$

Zsh, 21 bytes

<<<${${:-GoodBad}/$1}

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
\$\begingroup\$

Whitespace, 114 104 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"

sssttl      push "d"
sssl        push 0
sls         dup
tlts        readc
ttt         retrieve
sssttl      push 2
tstt        mod
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\$
  • 1
    \$\begingroup\$ You have a trailing linefeed. I also suspect you could do much better by adding some constant in the printing loop \$\endgroup\$ – Jo King yesterday
0
\$\begingroup\$

Attache, 24 bytes

$Good'$Bad^^Stdin[]|Echo

Try it online!

Explanation

$Good'$Bad^^Stdin[]|Echo
$Good'$Bad                   an array of the strings "Good" and "Bad"
          ^^                 remove from this array
            Stdin[]          standard input
                             this leaves us with a singleton array of the swapped element
                   |Echo     pipe the Echo function to each member of this array
                             (in this case, only prints the one element)

Alternatives

25 bytes: $Good'$Bad⩓Stdin[]|Echo

26 bytes: [$Good,$Bad]^^Stdin[]|Echo

29 bytes: Echo@If[Stdin[]@3,$Bad,$Good]

29 bytes: Echo@[$Bad,$Good][Stdin[]<$G]

37 bytes: [4875396,32943]^^STN@Stdin[]|Echo@NTS

44 bytes: Good:=$Bad;Bad:=$Good;Print@EvalHere@Stdin[]

\$\endgroup\$
0
\$\begingroup\$

Python 2, 32 bytes

print('Good','Bad')['C'<input()]

Try it online!

Using exit requires extra brackets around the whole expression so in this case print is 1 byte shorter.

\$\endgroup\$
0
\$\begingroup\$

Python 3, 33 bytes

exit(['Bad','Good'][input()<'G'])

Try it online!

 

Prints to stderr, to save one byte over print().

\$\endgroup\$
0
\$\begingroup\$

Japt -P, 11 bytes

"GoodBad"qU

Try it

Explanation:

"GoodBad"qU     U = Input             "Good"        "Bad"
"GoodBad"       String literal        "GoodBad"     "GoodBad"
         qU     Split at U            ["","Bad"]    ["Good",""]
-P              Join into a string    "Bad"         "Good"

Alternative

"GoodBad"rU

r replaces U with ""

Try it

\$\endgroup\$
0
\$\begingroup\$

F# (.NET Core), 50 35 bytes

Down to 35 thanks to @Expired Data

 fun a->if a>"B"then"Bad"else"Good"

Try it online!

Original:

F# (.NET Core), 50 bytes

printf(if stdin.ReadLine()>"B"then"Bad"else"Good")

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python 3, 37 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Dart, 77 bytes

import'dart:io';main()=>print('BadGood'.replaceAll(stdin.readLineSync(),''));

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Pepe, 104 bytes

rEEeREeEeeeEEErrEEreeEeeeEEEreeEEeEEEEreeEEeEEEEreeEEeeEeeREerREEreeEeeeeEereeEEeeeeEreeEEeeEeeREeReEree

Try it online!

With comments

# Prepare stacks
rEEe        # r ← Input
REeEeeeEEE  # R ← 'G'

# Create label i (outputs "Good")
rrEE { reeEeeeEEE reeEEeEEEE reeEEeEEEE reeEEeeEee } REe 

# Create label 'G' (outputs "Bad")
rREE { reeEeeeeEe reeEEeeeeE reeEEeeEee } REe 

# Compare values
ReE  # If the first letter of input is 'G', go to label 'G'
ree  # Otherwise, go to label i
\$\endgroup\$
0
\$\begingroup\$

Zozotez: 22

(?(=(r)'Bad)'Good'Bad)
\$\endgroup\$
0
\$\begingroup\$

ScPL, 61 bytes

ChooseFromMenu''[Good Bad]
Case
Text'Bad'
Case
Text'Good'
End

Editor Link

The first argument to ChooseFromMenu is the title, which doesn't matter so we put an empty string. The second argument is the list of choices.

Cases do not require a label, they go based on order.

Seperators between things are only required when they are not seperated some other way, for example a b needs a space because ab is one argument, but a'b' does not because the ' starts another argument.

\$\endgroup\$
0
\$\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\$
0
\$\begingroup\$

Java (OpenJDK 8), 51 42 bytes

g->{if(g=="Bad")return"Good";return"Bad";}

Try it online!

Checks if input is Bad.

-9 to @JoKing

\$\endgroup\$
  • 1
    \$\begingroup\$ I mean, just comparing g to "Bad" saves 4 bytes. You can also remove the else for 5 more, or even use a ternary operator for 24 bytes \$\endgroup\$ – Jo King Aug 3 at 7:56
  • \$\begingroup\$ @JoKing I actually tried to do a ternary g.length()>3?, but it was throwing an error for invalid operator. Thanks for help either way. \$\endgroup\$ – CuttingChipset Aug 3 at 8:10
0
\$\begingroup\$

PHP, 31 bytes

readline()=="Bad"?"Good":"Bad";

Try it online!

Another way, 41 bytes

["Bad"=>"Good","Good"=>"Bad"][readline()];

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Shorter: ['bad'=>'good'][readline()]??'bad'; \$\endgroup\$ – Progrock 11 hours ago
0
\$\begingroup\$

GNU Smalltalk, 34B

Please forgive me for submitting a code snippet if Smalltalk does have input. I am a complete novice to Smalltalk.

i<'C'ifTrue:['Good']ifFalse:['Bad']

You replace the name i with the intended input.

\$\endgroup\$
0
\$\begingroup\$

[PHP], 30 bytes

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

Best suppress notices.

\$\endgroup\$

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.