19
\$\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
  • 9
    \$\begingroup\$ May we write a function that takes input as argument instead of prompting for it? \$\endgroup\$ – Adám Jul 7 '19 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 '19 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 '19 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 '19 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 '19 at 13:58

74 Answers 74

1 2
3
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\$
1
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\$
1
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\$
2
  • 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 '19 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 '19 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\$
1
  • \$\begingroup\$ Shorter: ['bad'=>'good'][readline()]??'bad'; \$\endgroup\$ – Progrock Oct 13 '19 at 18:08
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\$
3
  • \$\begingroup\$ There is already a shorter PHP answer: codegolf.stackexchange.com/a/187930/81663 \$\endgroup\$ – Night2 Oct 14 '19 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 Oct 14 '19 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 Oct 14 '19 at 15:51
0
\$\begingroup\$

Wren, 30 bytes

Fn.new{|x|"GooBa".trim(x)+"d"}

Try it online!

Explanation

Fn.new{|x|                   } // New anonymous function with parameter x
                               // Sample input: "Bad"
          "GooBa"              // Define a string
                 .trim(x)      // Trim out all characters in the input string
                               // "GooBa" - "Bad" = "Goo"
                         +"d"  // Return the string joined with a "d": "Good"
\$\endgroup\$
0
\$\begingroup\$

TI-BASIC, 38 bytes

Input Str1:"GoodBad 
sub(Ans,abs(inString(Ans,Str1)-5)+1,4

Prompts the user to input the string, then prints the other string as specified in the challenge.

Explanation:

Input Str1                               ;get the input
"GoodBad "                               ;leave "GoodBad " in Ans. closing quote
                                         ;  is added for clarity (isn't in program)
            inString(Ans,Str1)           ;get the 1-indexed position of the input
                                         ;  in "GoodBad "
        abs(                  -5)+1      ;subtract 5, get the absolute value,
                                         ;  then add 1
sub(Ans, ...                       ,4    ;get the substring of "GoodBad " starting
                                         ;  at the position just calculated with
                                         ;  a length of 4.  leave the result in Ans
                                         ;implicit print of Ans
\$\endgroup\$
1 2
3

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.