Swapping "Good" and "Bad"

16

8

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!

Ishaq Khan

Posted 2019-07-07T13:42:15.070

Reputation: 351

9May we write a function that takes input as argument instead of prompting for it? – Adám – 2019-07-07T14:01:39.150

Congratulations on your first challenge. I've removed the [tag:code-challenge] tag, as it is only to be used for indicating alternative scoring criteria (not [tag:code-golf]). I look forward to seeing interesting challenges from you, but consider using the sandbox to design your challenges, at least the first few times.

– Adám – 2019-07-07T14:08:42.867

8Please 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 – 2019-07-09T00:21:43.857

2asks 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 – 2019-07-09T17:05:35.150

1"Asks the user for input", should that be some explicit question? Because an empty CLI prompt isn't really asking for anything … – user0721090601 – 2019-07-10T13:23:22.457

5What is the purpose for this restriction? No function is allowed accepting the value and returning the result; User must interact with the program – mbomb007 – 2019-07-12T13:58:39.473

Answers

46

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

Jonathan Allan

Posted 2019-07-07T13:42:15.070

Reputation: 67 804

What a trick! Can't understand how this works. – Ishaq Khan – 2019-07-07T15:50:11.797

Can you use a lambda to shorten bytes? – MilkyWay90 – 2019-07-07T16:55:27.957

@MilkyWay90 As per the question it must be a program accepting input. – Jonathan Allan – 2019-07-07T17:11:14.093

@A__ by default yes, although there is a comment by OP which suggests it could be overruled here. – Jonathan Allan – 2019-07-08T07:01:20.050

@A__ OP has confirmed that printing to stderr is fine – Jonathan Allan – 2019-07-08T17:24:33.753

4Too bad that "Good" and "Bad" share a "d", or you could do 'GoodBad'.strip(input()) which is a byte shorter. – xnor – 2019-07-10T04:16:50.957

15

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

Adám

Posted 2019-07-07T13:42:15.070

Reputation: 37 779

5Why the downvote‽ – Adám – 2019-07-07T14:39:16.710

1Does the code have GooBad or GoodBad? – NoOneIsHere – 2019-07-08T01:58:21.013

I think it should have GooBad, as adding a character ```d`` will make this post 14 bytes. – None – 2019-07-08T02:20:16.710

@NoOneIsHere Thanks. Fixed. – Adám – 2019-07-08T04:33:17.600

12

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

MilkyWay90

Posted 2019-07-07T13:42:15.070

Reputation: 2 264

4"Turing-Machine-But-Way-Worse" is, without a doubt, my new favorite esolang. – MikeTheLiar – 2019-07-08T17:53:00.830

@MikeTheLiar Thanks! – MilkyWay90 – 2019-07-08T18:10:46.160

@A__ favorite/disliked/"Turing-Machine-But-Way-Worse" is, without a doubt, my new favorite esolang. – MilkyWay90 – 2019-07-09T15:55:47.150

"YOU HAVE BEEN TERMINATED" ArnoldC, is that you? – TemporalWolf – 2019-07-09T20:28:08.740

@TemporalWolf It is I, ArnoldC! – MilkyWay90 – 2019-07-09T20:36:16.267

@A__ It isn't actually ArnoldC; I just put the exit command as a comment as a joke – MilkyWay90 – 2019-07-10T15:41:38.780

9

bash, 20 bytes

sed s/$1//<<<GoodBad

Try it online!

Doorknob

Posted 2019-07-07T13:42:15.070

Reputation: 68 138

8

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$

640KB

Posted 2019-07-07T13:42:15.070

Reputation: 7 149

7

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

Jonathan Allan

Posted 2019-07-07T13:42:15.070

Reputation: 67 804

1Looks like OP responded, input isn't restricted to STDIN. – Erik the Outgolfer – 2019-07-09T05:44:04.803

6

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

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

2

34: print("C">input()and"Good"or"Bad")

– Adám – 2019-07-07T14:51:50.267

2exit(input()[3:]and"Bad"or"Good") also works for the same byte count. – Neil – 2019-07-08T09:14:33.627

6

C, 39 38 bytes

main(){puts("Good\0Bad"+getchar()%6);}

Try it online!

Saved one byte thanks to @tsh.

Leo Tenenbaum

Posted 2019-07-07T13:42:15.070

Reputation: 2 655

5main(){puts("Good\0Bad"+getchar()%6);} 38 bytes – tsh – 2019-07-08T01:47:24.900

Shouldn't you add #include<stdio.h>? – polfosol ఠ_ఠ – 2019-07-09T11:04:48.077

3

@polfosolఠ_ఠ If this were anything but code golf, you should, but in C89, you can implicitly declare functions.

– Leo Tenenbaum – 2019-07-09T11:11:32.037

Can you use a null byte instead of \0? – Hello Goodbye – 2019-12-19T14:18:11.883

5

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

Helena

Posted 2019-07-07T13:42:15.070

Reputation: 321

That's a nice solution. You can shorten it a little bit by not using a newline in the input.

,>+++++>,>,>,[<<<[-<->>---<]<.>>+.>>.>>]<[<<[-<+>>+++<]<.>>-..>.>]
 – Dorian  – 2019-07-09T08:29:52.913

yeah, I realized that there is something to optimise there, but I found it hard to interpret what is necessary to comply with rule 4 – Helena – 2019-07-09T17:11:07.840

4

Haskell, 36 34 bytes

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

Try it online!

Edit: -2 bytes thanks to @cole

nimi

Posted 2019-07-07T13:42:15.070

Reputation: 34 639

134 bytes – cole – 2019-07-07T17:01:33.017

4

R, 42 37 35 32 bytes

-10 thanks to Giuseppe and AkselA!

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

Try it online!

Robert S.

Posted 2019-07-07T13:42:15.070

Reputation: 1 253

@Giuseppe that was quick. Thanks! – Robert S. – 2019-07-08T20:34:51.573

1No problem. I recognize a lot of the other R golfers' names, so I often click on posts if I see their name as the most recent. :-) – Giuseppe – 2019-07-08T20:35:58.463

1

using "C" instead of the first "Bad" as in this answer will save another couple bytes.

– Giuseppe – 2019-07-08T20:50:28.667

1Just out of curiosity, would something like \if`(readline()>"C","Bad","Good")` be a valid answer? I'm new to this game and its rules. – AkselA – 2019-07-09T15:33:18.870

2

@AkselA yes, but I'd also suggest using scan(,"") instead of readline(). Feel free to come to golfR, the R golf chatroom if you have any R-specific questions :-)

– Giuseppe – 2019-07-09T19:44:41.187

2

@AkselA also see Tips for Golfing in R for some specific tips; there are hidden gems in there if you read them :-)

– Giuseppe – 2019-07-09T19:46:19.793

4

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.

GammaFunction

Posted 2019-07-07T13:42:15.070

Reputation: 2 838

2c offers a shorter solution – user41805 – 2019-08-27T16:10:39.853

1You can still save 3 more bytes using c – user41805 – 2019-08-28T05:03:04.373

Had to play around with it a bit, but I figured it out! – GammaFunction – 2019-08-28T05:24:36.340

3

Befunge-93, 20 18 bytes

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

Try it online!

-2 bytes thanks to Jo King

negative seven

Posted 2019-07-07T13:42:15.070

Reputation: 1 931

3

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

ADJenks

Posted 2019-07-07T13:42:15.070

Reputation: 151

3

Ruby, 22 bytes

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

Try it online!

G B

Posted 2019-07-07T13:42:15.070

Reputation: 11 099

The question does say "asks the user for input", but the shortest way to do that is replacing the lambda with p gets and so it's the same length. (my original comment said you could save 2 bytes, but I didn't account for printing the result) – DaveMongoose – 2019-07-08T10:09:56.190

3

If we're actually going to be talking about a full program asking user for input, using the -p flag would give the most efficient answer: $_=$_>?F?:Bad:"Good" is 20 bytes. Try it online!

– Value Ink – 2019-07-08T23:17:49.100

3

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

Kevin Cruijssen

Posted 2019-07-07T13:42:15.070

Reputation: 67 575

I can see many alternate variations on this, but they all end up at the same byte count :( – Emigna – 2019-07-08T09:49:58.323

1Actually, you can save a byte with á. – Emigna – 2019-07-08T09:52:39.587

@Emigna Ah of course, brilliant. Now that I see á I can't believe I hadn't thought about it, but at the same time I know I would have never thought about it. ;) Thanks! (And yeah, I had a few 10-byte alternatives as well.) – Kevin Cruijssen – 2019-07-08T09:54:53.657

1Don't even need á, ”‚¿Bad”IK is also a 9. – Grimmy – 2019-07-08T10:29:24.597

3

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!

DaveMongoose

Posted 2019-07-07T13:42:15.070

Reputation: 231

This prints "Good" or "Bad" (with quotes); I'm not sure that's allowed. – Jordan – 2019-07-08T16:29:14.593

1

Abuse the fact that puts prints each element of an array on a separate line. It's 3 bytes more expensive than p, but it evens out since you take out the [0] and then save 2 more bytes by no longer needing parens. Try it online!

– Value Ink – 2019-07-08T23:22:19.157

@ValueInk thanks! Jordan's issue also gets resolved by this change so it's a win-win. – DaveMongoose – 2019-07-09T11:20:44.067

3

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.

Felix Bohnacker

Posted 2019-07-07T13:42:15.070

Reputation: 31

2Welcome! Consider adding an explanation and/or a link to an online interpreter where you can run your code. (See other answers for examples.) Code-only answers tend to be automatically flagged as low-quality. – mbomb007 – 2019-07-08T21:38:46.450

4The length part could just be !="Bad" – Jo King – 2019-07-09T02:14:05.570

109 bytes – Olivier Grégoire – 2019-08-27T14:32:00.853

3

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.

Hello Goodbye

Posted 2019-07-07T13:42:15.070

Reputation: 442

2

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

recursive

Posted 2019-07-07T13:42:15.070

Reputation: 8 616

2

Jelly, 9 bytes

“GooBa”œ^

Try it online!

Explanation

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

Luis Mendo

Posted 2019-07-07T13:42:15.070

Reputation: 87 464

@JonathanAllan Thanks. Edited – Luis Mendo – 2019-07-07T16:53:43.047

I don't see any indication that the input has to come through STDIN... – Erik the Outgolfer – 2019-07-07T18:37:26.420

@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) – Jonathan Allan – 2019-07-07T20:29:50.597

Looks like OP responded, input isn't restricted to STDIN. – Erik the Outgolfer – 2019-07-09T05:43:38.290

@EriktheOutgolfer Thanks! Rolled back – Luis Mendo – 2019-07-09T06:25:59.770

2

Retina 0.8.2, 20 bytes

oo
o
T`G\oaB`Ro
o
oo

Try it online! Link includes test suite. Explanation:

oo
o

Turn Good into God.

T`G\oaB`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.

Neil

Posted 2019-07-07T13:42:15.070

Reputation: 95 035

17 bytes, but less creative – pbeentje – 2019-07-08T14:38:11.263

2

PowerShell, 22 20 bytes

'Good','Bad'-ne$args

Try it online!

-2 bytes thanks to mazzy

Andrei Odegov

Posted 2019-07-07T13:42:15.070

Reputation: 939

120 bytes – mazzy – 2019-07-07T19:57:56.540

2

Excel, 24 bytes

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

Using @MilkyWay90's <C suggestion.

Wernisch

Posted 2019-07-07T13:42:15.070

Reputation: 2 534

2

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!

640KB

Posted 2019-07-07T13:42:15.070

Reputation: 7 149

Judging by the phrasing of the question, readline() is likely more appropriate than $argn. – Progrock – 2019-10-14T15:55:24.857

2

Keg, 22 bytes

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

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

2

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

Jo King

Posted 2019-07-07T13:42:15.070

Reputation: 38 234

2

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"

Lyxal

Posted 2019-07-07T13:42:15.070

Reputation: 5 253

1Wonderful, I could not golf to that length... I have upvoted your answer. – None – 2019-07-12T11:08:11.907

@A__ just as i have up voted yours – Lyxal – 2019-07-12T11:29:57.107

My answer is a lot worse than yours. You should not have upvoted my answer... – None – 2019-07-12T11:40:36.703

Is there any up to date keg documentation? – EdgyNerd – 2019-10-11T07:09:43.377

@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

– Lyxal – 2019-10-11T07:12:30.807

@EdgyNerd a lot of things have changed recently: strings are now a thing, more data types and so much more – Lyxal – 2019-10-11T07:13:02.330

@EdgyNerd, also there is some information here, but note that some of it may be incorrect as a few things have changed since then

– Lyxal – 2019-10-11T07:36:51.073

2

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

Jo King

Posted 2019-07-07T13:42:15.070

Reputation: 38 234

2

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

Dorian

Posted 2019-07-07T13:42:15.070

Reputation: 1 521

1-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). – Kevin Cruijssen – 2020-01-28T16:09:40.567

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. – Dorian – 2020-01-29T08:04:37.483

2

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

Pseudo Nym

Posted 2019-07-07T13:42:15.070

Reputation: 181

2

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

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

1

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

Ishaq Khan

Posted 2019-07-07T13:42:15.070

Reputation: 351

1Normally, we recommend leaving challenges up for a while (I generally give it a week) before self-answering. – Adám – 2019-07-07T14:38:45.873

@Adám Good suggestion. – Ishaq Khan – 2019-07-07T14:40:23.920

1print({'G':'Bad','B':'Good'}[input()[0]]) works too for -2 bytes – MilkyWay90 – 2019-07-07T20:14:58.337

1print(['Bad','Good'][input()<'C']) works for 34 bytes (-9) – MilkyWay90 – 2019-07-07T20:17:24.063

@MilkyWay90 You're genius! – Ishaq Khan – 2019-07-07T23:39:57.793

You should edit the answer then if you feel as though it is similar enough to your answer to be golfed down to. – MilkyWay90 – 2019-07-07T23:42:12.570

@MilkyWay90 May I edit with your first suggestion or second? Second one is completely different solution. – Ishaq Khan – 2019-07-07T23:46:04.573

Probably my first one; the second one, as you said, is completely different – MilkyWay90 – 2019-07-07T23:46:58.657

You probably should put the shortest solution as the one solution without any alternative solutions – MilkyWay90 – 2019-07-08T00:17:06.183

1

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

Roman

Posted 2019-07-07T13:42:15.070

Reputation: 1 190

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)

– Jonathan Allan – 2019-07-07T17:27:48.080

@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. – Roman – 2019-07-07T18:04:14.387

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...? – Jonathan Allan – 2019-07-07T18:10:53.593

@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. – Roman – 2019-07-07T18:26:04.740

Nice. Maybe there are golfs to be had... :) – Jonathan Allan – 2019-07-07T18:27:35.003

1

Looks like you could use symbols for the output to save 4.

– Jonathan Allan – 2019-07-07T18:38:07.843

1

K (oK), 16 bytes

Solution:

$`Bad`Good"Bad"~

Try it online!

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

streetster

Posted 2019-07-07T13:42:15.070

Reputation: 3 635

15 bytes with loose constraints – streetster – 2019-07-07T20:17:33.287

1

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

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

Try it online!

Expired Data

Posted 2019-07-07T13:42:15.070

Reputation: 3 129

1

Java, 30 bytes

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

TIO

Benjamin Urquhart

Posted 2019-07-07T13:42:15.070

Reputation: 1 262

How does it take input from the user (e.g. by reading from stdin) and print the result (instead of just returning it)? – nimi – 2019-07-07T22:14:29.217

@nimi OP hasn't specified whether IO includes arguments and returns. By default, it is allowed – Benjamin Urquhart – 2019-07-07T22:52:33.593

"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. – nimi – 2019-07-07T22:59:06.077

@nimi I can argue a missing argument error is a prompt. As for output, you do have a point. – Benjamin Urquhart – 2019-07-07T23:04:41.437

1

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

Comrade SparklePony

Posted 2019-07-07T13:42:15.070

Reputation: 5 784

1

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

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

1I think you can drop the space before else but no other spaces as you noticed. – Neil – 2019-07-08T09:20:30.423

1

Perl 5 -p, 15 bytes

$_=/B/?Good:Bad

Try it online!

Xcali

Posted 2019-07-07T13:42:15.070

Reputation: 7 671

1

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

Sok

Posted 2019-07-07T13:42:15.070

Reputation: 5 592

1

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.

Draco18s no longer trusts SE

Posted 2019-07-07T13:42:15.070

Reputation: 3 053

1

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"

Shaun Bebbers

Posted 2019-07-07T13:42:15.070

Reputation: 1 814

1

Python 3, 37 bytes

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

Try it online!

Dat

Posted 2019-07-07T13:42:15.070

Reputation: 879

1

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!

EdgyNerd

Posted 2019-07-07T13:42:15.070

Reputation: 1 106

1

Racket, 38 bytes

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

Winny

Posted 2019-07-07T13:42:15.070

Reputation: 1 120

1

Boolfuck, 110 68 bytes

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

Thanks to Jo King for the massively improved solution!

Try it with Online!

EdgyNerd

Posted 2019-07-07T13:42:15.070

Reputation: 1 106

68 bytes. I think it can be better though – Jo King – 2019-07-15T00:51:00.243

Wow, how were you able to save so many bytes over my answer? – EdgyNerd – 2019-07-15T06:26:06.827

1

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

Sylwester

Posted 2019-07-07T13:42:15.070

Reputation: 3 678

@JoKing Yes. Thanks :) – Sylwester – 2019-08-03T12:33:39.753

1

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

GammaFunction

Posted 2019-07-07T13:42:15.070

Reputation: 2 838

1

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

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

1

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

FlipTack

Posted 2019-07-07T13:42:15.070

Reputation: 13 242

1

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

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

Try it online!

Jirka Picek

Posted 2019-07-07T13:42:15.070

Reputation: 171

1

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

sporeball

Posted 2019-07-07T13:42:15.070

Reputation: 461

0

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

Conor O'Brien

Posted 2019-07-07T13:42:15.070

Reputation: 36 228

0

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!

LSM07

Posted 2019-07-07T13:42:15.070

Reputation: 191

135 bytes – Expired Data – 2019-07-08T08:02:04.493

0

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.

ElPedro

Posted 2019-07-07T13:42:15.070

Reputation: 5 301

0

Python 3, 33 bytes

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

Try it online!

 

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

ruohola

Posted 2019-07-07T13:42:15.070

Reputation: 414

0

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

Oliver

Posted 2019-07-07T13:42:15.070

Reputation: 7 160

0

Dart, 77 bytes

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

Try it online!

Elcan

Posted 2019-07-07T13:42:15.070

Reputation: 913

0

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

RedClover

Posted 2019-07-07T13:42:15.070

Reputation: 719

0

Zozotez: 22

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

Sylwester

Posted 2019-07-07T13:42:15.070

Reputation: 3 678

0

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.

pfg

Posted 2019-07-07T13:42:15.070

Reputation: 735

0

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"

TheOnlyMrCat

Posted 2019-07-07T13:42:15.070

Reputation: 1 079

0

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

CuttingChipset

Posted 2019-07-07T13:42:15.070

Reputation: 99

1

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 – 2019-08-03T07:56:32.960

@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 – 2019-08-03T08:10:58.127

0

PHP, 31 bytes

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

Try it online!

Another way, 41 bytes

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

Try it online!

Micio Informatico

Posted 2019-07-07T13:42:15.070

Reputation: 53

Shorter: ['bad'=>'good'][readline()]??'bad'; – Progrock – 2019-10-13T18:08:50.703

0

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.

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

0

[PHP], 30 bytes

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

Best suppress notices.

Progrock

Posted 2019-07-07T13:42:15.070

Reputation: 131

There is already a shorter PHP answer: https://codegolf.stackexchange.com/a/187930/81663

– Night2 – 2019-10-14T12:13:24.737

1@Night2, reading the question as waiting on a prompt, a readline solution seemed more appropriate as an answer. – Progrock – 2019-10-14T15:47:43.167

1@Night2, but granted if they were to swap $argn for readline(), theirs would still be a shorter solution. – Progrock – 2019-10-14T15:51:22.280

0

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"

user85052

Posted 2019-07-07T13:42:15.070

Reputation:

0

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

Tau

Posted 2019-07-07T13:42:15.070

Reputation: 1 935