# Swapping “Good” and “Bad”

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!

• May we write a function that takes input as argument instead of prompting for it? – Adám Jul 7 '19 at 14:01
• 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) – Jo King Jul 9 '19 at 0:21
• 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 – MilkyWay90 Jul 9 '19 at 17:05
• "Asks the user for input", should that be some explicit question? Because an empty CLI prompt isn't really asking for anything … – user0721090601 Jul 10 '19 at 13:23
• What is the purpose for this restriction? No function is allowed accepting the value and returning the result; User must interact with the program – mbomb007 Jul 12 '19 at 13:58

# Python 3, 33 bytes

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


Try it online!

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

# 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

# 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!

# Dart, 77 bytes

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


Try it online!

# 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


# Zozotez: 22

(?(=(r)'Bad)'Good'Bad)


# 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.

# 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"


# 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

• 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 – Jo King Aug 3 '19 at 7:56
• @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. – CuttingChipset Aug 3 '19 at 8:10

# PHP, 31 bytes

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


Try it online!

## Another way, 41 bytes

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


Try it online!

• Shorter: ['bad'=>'good'][readline()]??'bad'; – Progrock Oct 13 '19 at 18:08

## 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.

# [PHP], 30 bytes

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


Best suppress notices.

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

# 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"


# 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