AnswerBun.com

Swapping "Good" and "Bad"

Code Golf Asked by Ishaq Khan on October 15, 2020

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!

74 Answers

Javascript 50 bytes

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

Answered by Yaroslav Gaponov on October 15, 2020

Retina, 10 bytes

:`GoodBad

Try it online!

: swaps the input and the regex, so this computes 'GoodBad'.replace(input, '').

Answered by ovs on October 15, 2020

MAWP, 59 bytes

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

Try it!

Answered by Razetime on October 15, 2020

Kotlin, 52 bytes

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

Try it online!

Answered by snail_ on October 15, 2020

W j, 8 bytes

Still doesn't tie with Keg. Help!

♥d←╖←I¡%

Uncompressed:

G'%Av%?S,

Explanation

           % Implcitly start a compressed string
G'         % "good" in the dictionary
  %        % Capitalize
   Av      % "bad" in the dictionary
     %     % Capitalize
      ?    % End compressed string
       S   % Swap so that the input comes to the top
        ,  % Split the string on the input

Flag:j     % Implicit smash on output list
```

Answered by user92069 on October 15, 2020

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

Answered by Tau on October 15, 2020

naz, 66 bytes

9a7m4a2x1v1x1f1r3x1v2l5s1o2d3m2s1o3a1o0x1x2f5a1o2d3m6a2o9s2s1o0x1f

Explanation (with 0x commands removed)

9a7m4a2x1v                   # Set variable 1 equal to 67 ("C")
1x1f                         # Function 1
    1r3x1v2l                 # Read the first byte of input
                             # Jump to function 2 if it's less than variable 1 
            5s1o2d3m2s1o3a1o # Otherwise, output "Bad"

1x2f5a1o2d3m6a2o9s2s1o       # Function 2
                             # Output "Good"
1f                           # Call function 1

Answered by sporeball on October 15, 2020

GolfScript, 11 bytes

"GoodBad"/

Try it online!

Explanation

"GoodBad"   # Define the lookup table "GoodBad"
           # Swap the input so that it can be used by /
          / # Split the lookup table by occurences of the input
            # Implicit print, smashing

Answered by user85052 on October 15, 2020

Charcoal, 13 bytes

¿⁻LS³Ba¦Goo¦d

Try it online!

Explanation:

¿⁻LS³          If length of input minus 3 is truthy:
      Ba¦         print Ba
         Goo¦       else print Goo
             d        print d

Answered by Pseudo Nym on October 15, 2020

Shakespeare Programming Language, 582 bytes

(Whitespace added for readability)

G.Ajax,.Puck,.Act I:.Scene I:.[Enter Ajax and Puck]Ajax:
Open mind.Be you nicer the sum ofa big cat the cube ofa big big cat?If solet usScene V.
You is the sum ofthe sum ofyou a big big cat a cat.Speak thy.You is the sum ofyou twice twice twice the sum ofa big big cat a cat.Speak thy.Speak thy.You is the square oftwice the sum ofa big big cat a cat.Let usScene X.
Scene V:.Ajax:
You is the sum ofthe sum ofyou a big big pig a pig.Speak thy.You is the sum ofyou the sum ofa big big big big big cat a pig.Speak thy.You is the sum ofyou the sum ofa big cat a cat.
Scene X:.Ajax:Speak thy.

Try it online!

I get the first letter of the input with Open mind. Then I need to determine what it is. Of all the numbers between B=66 and G=71, my brute forcer says 66 is the shortest to write (the sum ofa big cat the cube ofa big big cat), so I compare the first letter of the input to 66. Scene I continues to print Good, or Scene V prints Bad.

Answered by Hello Goodbye on October 15, 2020

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

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

Try it online!

Answered by Jirka Picek on October 15, 2020

Pushy, 17 bytes

.F`Goo`x?c`Ba`;H"

Try it online!

Explanation:

                   Implicit: input on main stack.
.F                 Pop last letter, and move to auxiliary stack.
  `Goo`            Push 'Goo' to main stack.
       x?     ;    If the stacks are equal:
         c`Ba`        Replace 'Goo' with 'Ba'
               H   Push 'd', as char(d) = 100 = H
                "  Print stack

Answered by FlipTack on October 15, 2020

W d, 12 11 9 bytes

Realized that I could use the implicit quote system. Still can't beat Keg with the decompression. (Alternative 9-byter:§D⑺y⒁v⑼z¬; but that's the same bytecount)

☺DΩy±v∞z↓

Explanation

% Sample input: "Bad"
% Implicitly prepend a quote for this string
GooBa"     % Stack: ["Bad","GooBa"]
      S    % Stack: ["GooBa","Bad"]
       t   % "GooBa".trim("Bad"), which is "Goo"
        'd % Stack: ["Goo","d"]
           % Stack: ["Good"]

% Implicit output
```

Answered by user85052 on October 15, 2020

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"

Answered by user85052 on October 15, 2020

[PHP], 30 bytes

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

Best suppress notices.

Answered by Progrock on October 15, 2020

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

Answered by Dorian on October 15, 2020

sed, 21 16 13 bytes

Thanks @Cowsquack for the hints.

/B/cGood
cBad

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

TIL c will short-circuit the current line's parsing.

Answered by GammaFunction on October 15, 2020

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

Answered by GammaFunction on October 15, 2020

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.

Answered by user85052 on October 15, 2020

PHP, 31 bytes

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

Try it online!

Another way, 41 bytes

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

Try it online!

Answered by Micio Informatico on October 15, 2020

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

Answered by CuttingChipset on October 15, 2020

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"

Answered by TheOnlyMrCat on October 15, 2020

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.

Answered by pfg on October 15, 2020

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

Answered by Jo King on October 15, 2020

Zozotez: 22

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

Answered by Sylwester on October 15, 2020

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

Answered by Sylwester on October 15, 2020

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

Answered by RedClover on October 15, 2020

Boolfuck, 110 68 bytes

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

Thanks to Jo King for the massively improved solution!

Try it with Online!

Answered by EdgyNerd on October 15, 2020

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"

Answered by Lyxal on October 15, 2020

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

Answered by Jo King on October 15, 2020

Racket, 38 bytes

(write(match(read)['Bad'Good][_'Bad]))

Answered by Winny on October 15, 2020

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!

Answered by EdgyNerd on October 15, 2020

Keg, 22 bytes

?^_^_o=[^aB^_|^ooG^]

Answered by user85052 on October 15, 2020

Dart, 77 bytes

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

Try it online!

Answered by Elcan on October 15, 2020

Python 3, 37 bytes

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

Try it online!

Answered by Dat on October 15, 2020

R, 42 37 35 32 bytes

-10 thanks to Giuseppe and AkselA!

`if`(scan(,'')>'C','Bad','Good')

Try it online!

Answered by Robert S. on October 15, 2020

brainfuck, 72 bytes

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

Try it online!

Explanation: ,>+++++>,>,>,>,

Read either: "G", 5, "o", "o", "d" or "B", 5, "a", "d", 0

[<<<<[-<->>---<]<.>>+.>>.>>>] If the last character is not zero:

Substract 5 from the first cell once and from the third cell thrice. Increment cell 3

Output cells 1, 3, 5.

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

Otherwise add 5 to the first cell once and to the third cell thrice.

Decrement cell 3

Output cells 1, 3, 3, 4

Answered by Helena on October 15, 2020

Java (JDK), 124 bytes

interface G{static void main(String[]a){System.out.print(new java.util.Scanner(System.in).next().length()>3?"Bad":"Good");}}

Try it online!

Most likely, there‘s still some room for improvement, but I‘m entirely new to code golfing.

Answered by Felix Bohnacker on October 15, 2020

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!

Answered by 640KB on October 15, 2020

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"

Answered by Shaun Bebbers on October 15, 2020

8088 Assembly, IBM PC DOS, 25 bytes

Unassembled:

BA 0110     MOV  DX, OFFSET GB  ; point DX to 'Good','Bad' string 
D1 EE       SHR  SI, 1          ; point SI to DOS PSP (80H) 
02 04       ADD  AL, [SI]       ; add input string length to AL, set parity flag 
7B 02       JNP  DISP           ; if odd parity, input was 'Bad' so jump to display 'Good'
02 D0       ADD  DL, AL         ; otherwise add string length as offset for 'Bad' string 
        DISP: 
B4 09       MOV  AH, 9          ; DOS display string function 
CD 21       INT  21H            ; call DOS API, write string to console 
C3          RET                 ; return to DOS 
        GB  DB  'Good$','Bad$'

Explanation:

Looks at the length of input string (plus leading space) that DOS stores at memory address 80H, and adds it to AL (initially 0 by DOS). If there is an odd number of 1 bits in the binary representation of the string length, the CPU parity flag is set to odd, and vice-versa. So input string ' Bad' length 4 (0000 0100), is odd parity and input string ' Good' is 5 (0000 0101) is even parity.

DX is initially set to point to the string 'Good$Bad$', and if parity is even (meaning input was ' Good') advance the string pointer by that length (5) so it now points to 'Bad$'. If parity is odd, do nothing since it already points to 'Good$'. Then use DOS API to display a $ terminated string to console.

Example:

enter image description here

Download and test GOODBAD.COM or build from xxd dump:

0000000: ba10 01d1 ee02 047b 0202 d0b4 09cd 21c3  .......{......!.
0000010: 476f 6f64 2442 6164 24                   Good$Bad$

Answered by 640KB on October 15, 2020

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.

Answered by Draco18s no longer trusts SE on October 15, 2020

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

Answered by Oliver on October 15, 2020

Ruby, 30 28 bytes

puts %w|Good Bad|-gets.split

Not the golf-iest, but I like the abuse of split to remove the trailing newline and convert to an array in one call.

EDIT -2 bytes thanks to Value Ink's suggestion!

Answered by DaveMongoose on October 15, 2020

Pyth, 12 bytes

+-"GooBa"zd

Try it online!

+-"GooBa"zd   Implicit: z=input()
 -"GooBa"z     Keep letters in "GooBa" which do not appear in z
+         d   Append "d", implicit print

Answered by Sok on October 15, 2020

Excel, 24 bytes

=IF(A1>"C","Bad","Good")

Using @MilkyWay90's <C suggestion.

Answered by Wernisch on October 15, 2020

05AB1E, 10 9 bytes

”‚¿‰±”áIK

-1 byte thanks to @Emigna.

Try it online or verify both test cases.

Explanation:

”‚¿‰±”     # Push dictionary string "Good Bad"
      á    # Only keep letters (to remove the space)
       IK  # Remove the input
           # (output the result implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?), to understand why ”‚¿‰±” is "Good Bad".

Answered by Kevin Cruijssen on October 15, 2020

Ruby, 22 bytes

->n{n>?F?"Bad":"Good"}

Try it online!

Answered by G B on October 15, 2020

Python 3, 33 bytes

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

Try it online!

 

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

Answered by ruohola on October 15, 2020

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.

Answered by ElPedro on October 15, 2020

JavaScript 31 bytes

I like Arnauld's answer, but I would like it to accept user input and be runnable on StackExchange like so:

alert(prompt()[3]?'Bad':'Good')

Answered by ADJenks on October 15, 2020

Perl 5 -p, 15 bytes

$_=/B/?Good:Bad

Try it online!

Answered by Xcali on October 15, 2020

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

Answered by user85052 on October 15, 2020

C, 39 38 bytes

main(){puts("GoodBad"+getchar()%6);}

Try it online!

Saved one byte thanks to @tsh.

Answered by pommicket on October 15, 2020

///, 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>

Answered by Comrade SparklePony on October 15, 2020

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!

Answered by LSM07 on October 15, 2020

Java, 30 bytes

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

TIO

Answered by Benjamin Urquhart on October 15, 2020

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: [email protected][Stdin[]@3,$Bad,$Good]

29 bytes: [email protected][$Bad,$Good][Stdin[]<$G]

37 bytes: [4875396,32943]^^[email protected][]|[email protected]

44 bytes: Good:=$Bad;Bad:=$Good;[email protected]@Stdin[]

Answered by Conor O'Brien on October 15, 2020

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

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

Try it online!

Answered by Expired Data on October 15, 2020

PowerShell, 22 20 bytes

'Good','Bad'-ne$args

Try it online!

-2 bytes thanks to mazzy

Answered by Andrei Odegov on October 15, 2020

Turing Machine But Way Worse, 405 bytes

0 0 0 1 1 0 0
1 1 1 1 2 0 0
0 2 0 1 3 0 0
0 3 0 1 4 0 0
0 4 0 1 5 0 0
1 5 0 1 6 0 0
0 5 1 1 h 0 0
1 6 1 1 7 0 0
1 7 0 1 8 1 0
0 8 0 1 9 0 0
1 9 1 1 9 0 0
0 9 0 1 a 0 0
1 a 0 1 a 0 0
0 a 0 0 b 0 0
0 b 1 1 c 1 0
0 c 0 0 d 0 0
1 d 0 0 e 0 0
0 e 0 0 f 0 0
0 f 1 1 g 1 1
1 h 1 1 i 0 0
0 i 1 1 j 1 0
0 j 0 1 k 0 0
1 k 1 1 k 0 0
0 k 0 1 l 0 0
0 l 1 1 l 0 0
1 l 1 0 m 1 0
1 m 1 1 n 1 0
1 n 1 1 o 0 0
0 o 0 1 p 1 1

Try it online!

Well, this took a while.

UNFINISHED EXPLANATION:

0 0 0 1 1 0 0 Start going to the sixth bit
1 1 1 1 2 0 0
0 2 0 1 3 0 0
0 3 0 1 4 0 0
0 4 0 1 5 0 0 End going to the sixth bit
1 5 0 1 6 0 0 If the sixth bit is 1, then it is Good. Start transforming "G" to "B" and go to state 6
0 5 1 1 h 0 0 Else, it is Bad. Start transforming "B" to "G" and go to state h
1 6 1 1 7 0 0 Keep on transforming "G" to "B"
1 7 0 1 8 1 0 End transforming and print "B"
0 8 0 1 9 0 0 We are in the first "o" in "Good". Start moving into the 5th bit.
1 9 1 1 9 0 0
0 9 0 1 a 0 0
1 a 0 1 a 0 0 Do some looping magic and start transforming "o" to "a"
0 a 0 0 b 0 0 End looping magic
0 b 1 1 c 1 0 End transforming and print "a"
0 c 0 0 d 0 0 
1 d 0 0 e 0 0 Start transforming "a" to "d"
0 e 0 0 f 0 0 
0 f 1 1 g 1 1 Stop transforming, print "d", and terminate
1 h 1 1 i 0 0 Continue transforming "B" to "G"
0 i 1 1 j 1 0 Stop transforming and print out "G"
0 j 0 1 k 0 0 Start going into position to print out "oo"
1 k 1 1 k 0 0
0 k 0 1 l 0 0 Move more efficiently using LOOPING MAGIC1!1111111 
0 l 1 1 l 0 0 looping magic end, start transforming
1 l 1 0 m 1 0 end transforming and print out out "o"
1 m 1 1 n 1 0 print out "o" again
1 n 1 1 o 0 0 get into the "d" byte
0 o 0 1 p 1 1 print "d" and execute YOU HAVE BEEN TERMINATED

Answered by MilkyWay90 on October 15, 2020

K (oK), 16 bytes

Solution:

$`Bad`Good"Bad"~

Try it online!

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

Answered by streetster on October 15, 2020

Haskell, 36 34 bytes

interact g
g"Bad"="Good"
g _="Bad"

Try it online!

Edit: -2 bytes thanks to @cole

Answered by nimi on October 15, 2020

bash, 20 bytes

sed s/$1//<<<GoodBad

Try it online!

Answered by Doorknob on October 15, 2020

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 [email protected], which is implicit in the command-line version of WolframScript and can be simulated on TIO with the -print argument

Answered by Roman on October 15, 2020

Retina 0.8.2, 20 bytes

oo
o
T`GoaB`Ro
o
oo

Try it online! Link includes test suite. Explanation:

oo
o

Turn Good into God.

T`GoaB`Ro

Transpose the letters GoaB with the reverse of that list, thus exchanging G with B and o with a, i.e. exchanging God with Bad.

o
oo

Turn God into Good.

Answered by Neil on October 15, 2020

Befunge-93, 20 18 bytes

"BadooGB"~-_#@,,<,

Try it online!

-2 bytes thanks to Jo King

Answered by negative seven on October 15, 2020

Jelly, 9 bytes

“GooBa”œ^

Try it online!

Explanation

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

Answered by Luis Mendo on October 15, 2020

Stax, 9 8 bytes

çEF♫a║▬h

Run and debug it

Essentially replace("BadGood", input, "").

Multiset xor with "GooBa". Algorithm copied verbatim from Luis Mendo

Answered by recursive on October 15, 2020

Jelly, 8 bytes

“Ċ³ṫ³»œṣ

Try it online!

A full program expecting a Python formatted string as an argument

How?

“Ċ³ṫ³»œṣ - Main Link: list of characters, S
“Ċ³ṫ³»   - compression of dictionary words "Good"+"Bad" = ['G','o','o','d','B','a','d']
      œṣ - split on sublists equal to S
         - implicit, smashing print

Answered by Jonathan Allan on October 15, 2020

Python 3,  32  31 bytes

exit('GBoaodd'['G'<input()::2])

Try it online!

How?

Tests if input is 'Good' by comparing 'G'<input().

Uses the fact that in Python False==0 and True==1 to use the result as the start index of a slice of 'GBoaodd' using an undefined stop and a step of 2 with 'GBoaodd'[start:stop:step].

Prints to STDERR (saving a byte with exit in place of print).

Answered by Jonathan Allan on October 15, 2020

Python 3, 38 37 34 33 bytes

exit("C">input()and"Good"or"Bad")

Try it online!

exit() : returns an exit code as output

"C">input() : Checks whether the input is larger than the string C in the alphabetical order

and"Good" : If the result is True, then returns with Good

or"Bad" : Otherwise, returns with Bad

Answered by user85052 on October 15, 2020

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]])

Answered by Ishaq Khan on October 15, 2020

APL (Dyalog Unicode), 13 bytesSBCS

Full program that prompts for input from stdin and prints to stdout.

'GooBad'~¯1↓⍞

Try it online!

 prompt for input from stdin; Good or Bad

¯1↓ drop the last character (d); Goo or Ba

'GooBad'~ multiset subtract those characters from these; Bad or Good

Answered by Adám on October 15, 2020

Add your own answers!

Related Questions

Draw the arc of a ball

33  Asked on January 30, 2021 by xnor

     

Loading… Forever

92  Asked on January 20, 2021 by fliptack

       

Output the Partial Products

17  Asked on January 20, 2021 by downgoat

   

What’s the file extension?

92  Asked on January 15, 2021 by programmer5000

   

Adding fractions

25  Asked on January 13, 2021 by user65167

     

Hexadecimal Counter

39  Asked on December 31, 2020 by phase

   

The Rien Number

39  Asked on December 21, 2020 by conor-obrien

         

How many threes?

24  Asked on December 21, 2020

   

Fibonacci Exponents

24  Asked on December 20, 2020 by anthony-pham

     

Mountain range numbers

25  Asked on December 15, 2020 by rgs

   

Calculate pi to 5 decimals

30  Asked on December 14, 2020 by nos

   

Add a language to a polyglot

296  Asked on December 12, 2020 by user62131

   

ASCII art Bresenham line drawing

5  Asked on December 6, 2020 by keith-randall

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir