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

63 Answers 63

46
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ What a trick! Can't understand how this works. \$\endgroup\$ – Ishaq Khan Jul 7 at 15:50
  • \$\begingroup\$ Can you use a lambda to shorten bytes? \$\endgroup\$ – MilkyWay90 Jul 7 at 16:55
  • \$\begingroup\$ @MilkyWay90 As per the question it must be a program accepting input. \$\endgroup\$ – Jonathan Allan Jul 7 at 17:11
  • \$\begingroup\$ @A__ by default yes, although there is a comment by OP which suggests it could be overruled here. \$\endgroup\$ – Jonathan Allan Jul 8 at 7:01
  • 4
    \$\begingroup\$ Too bad that "Good" and "Bad" share a "d", or you could do 'GoodBad'.strip(input()) which is a byte shorter. \$\endgroup\$ – xnor Jul 10 at 4:16
13
\$\begingroup\$

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

\$\endgroup\$
  • 5
    \$\begingroup\$ Why the downvote‽ \$\endgroup\$ – Adám Jul 7 at 14:39
  • 1
    \$\begingroup\$ Does the code have GooBad or GoodBad? \$\endgroup\$ – NoOneIsHere Jul 8 at 1:58
  • \$\begingroup\$ I think it should have GooBad, as adding a character ```d`` will make this post 14 bytes. \$\endgroup\$ – A̲̲ Jul 8 at 2:20
  • \$\begingroup\$ @NoOneIsHere Thanks. Fixed. \$\endgroup\$ – Adám Jul 8 at 4:33
12
\$\begingroup\$

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
\$\endgroup\$
  • 4
    \$\begingroup\$ "Turing-Machine-But-Way-Worse" is, without a doubt, my new favorite esolang. \$\endgroup\$ – MikeTheLiar Jul 8 at 17:53
  • \$\begingroup\$ @MikeTheLiar Thanks! \$\endgroup\$ – MilkyWay90 Jul 8 at 18:10
  • \$\begingroup\$ @A__ favorite/disliked/"Turing-Machine-But-Way-Worse" is, without a doubt, my new favorite esolang. \$\endgroup\$ – MilkyWay90 Jul 9 at 15:55
  • \$\begingroup\$ "YOU HAVE BEEN TERMINATED" ArnoldC, is that you? \$\endgroup\$ – TemporalWolf Jul 9 at 20:28
  • \$\begingroup\$ @TemporalWolf It is I, ArnoldC! \$\endgroup\$ – MilkyWay90 Jul 9 at 20:36
9
\$\begingroup\$

bash, 20 bytes

sed s/$1//<<<GoodBad

Try it online!

\$\endgroup\$
8
\$\begingroup\$

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

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
\$\endgroup\$
  • 1
    \$\begingroup\$ Looks like OP responded, input isn't restricted to STDIN. \$\endgroup\$ – Erik the Outgolfer Jul 9 at 5:44
6
\$\begingroup\$

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

\$\endgroup\$
  • 2
    \$\begingroup\$ 34: print("C">input()and"Good"or"Bad") \$\endgroup\$ – Adám Jul 7 at 14:51
  • 2
    \$\begingroup\$ exit(input()[3:]and"Bad"or"Good") also works for the same byte count. \$\endgroup\$ – Neil Jul 8 at 9:14
6
\$\begingroup\$

C, 39 38 bytes

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

Try it online!

Saved one byte thanks to @tsh.

\$\endgroup\$
  • 5
    \$\begingroup\$ main(){puts("Good\0Bad"+getchar()%6);} 38 bytes \$\endgroup\$ – tsh Jul 8 at 1:47
  • \$\begingroup\$ Shouldn't you add #include<stdio.h>? \$\endgroup\$ – polfosol ఠ_ఠ Jul 9 at 11:04
  • 3
    \$\begingroup\$ @polfosolఠ_ఠ If this were anything but code golf, you should, but in C89, you can implicitly declare functions. \$\endgroup\$ – Leo Tenenbaum Jul 9 at 11:11
4
\$\begingroup\$

Haskell, 36 34 bytes

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

Try it online!

Edit: -2 bytes thanks to @cole

\$\endgroup\$
  • 1
    \$\begingroup\$ 34 bytes \$\endgroup\$ – cole Jul 7 at 17:01
4
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ That's a nice solution. You can shorten it a little bit by not using a newline in the input. ,>+++++>,>,>,[<<<[-<->>---<]<.>>+.>>.>>]<[<<[-<+>>+++<]<.>>-..>.>] \$\endgroup\$ – Dorian Jul 9 at 8:29
  • \$\begingroup\$ 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 \$\endgroup\$ – Helena Jul 9 at 17:11
4
\$\begingroup\$

R, 42 37 35 32 bytes

-10 thanks to Giuseppe and AkselA!

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

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ No 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. :-) \$\endgroup\$ – Giuseppe Jul 8 at 20:35
  • 1
    \$\begingroup\$ using "C" instead of the first "Bad" as in this answer will save another couple bytes. \$\endgroup\$ – Giuseppe Jul 8 at 20:50
  • 1
    \$\begingroup\$ Just out of curiosity, would something like `if`(readline()>"C","Bad","Good") be a valid answer? I'm new to this game and its rules. \$\endgroup\$ – AkselA Jul 9 at 15:33
  • 2
    \$\begingroup\$ @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 :-) \$\endgroup\$ – Giuseppe Jul 9 at 19:44
  • 2
    \$\begingroup\$ @AkselA also see Tips for Golfing in R for some specific tips; there are hidden gems in there if you read them :-) \$\endgroup\$ – Giuseppe Jul 9 at 19:46
4
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ c offers a shorter solution \$\endgroup\$ – Kritixi Lithos Aug 27 at 16:10
  • 1
    \$\begingroup\$ You can still save 3 more bytes using c \$\endgroup\$ – Kritixi Lithos Aug 28 at 5:03
  • \$\begingroup\$ Had to play around with it a bit, but I figured it out! \$\endgroup\$ – GammaFunction Aug 28 at 5:24
3
\$\begingroup\$

Befunge-93, 20 18 bytes

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

Try it online!

-2 bytes thanks to Jo King

\$\endgroup\$
3
\$\begingroup\$

Ruby, 22 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 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) \$\endgroup\$ – DaveMongoose Jul 8 at 10:09
  • 3
    \$\begingroup\$ 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! \$\endgroup\$ – Value Ink Jul 8 at 23:17
3
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ I can see many alternate variations on this, but they all end up at the same byte count :( \$\endgroup\$ – Emigna Jul 8 at 9:49
  • 1
    \$\begingroup\$ Actually, you can save a byte with á. \$\endgroup\$ – Emigna Jul 8 at 9:52
  • \$\begingroup\$ @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.) \$\endgroup\$ – Kevin Cruijssen Jul 8 at 9:54
  • 1
    \$\begingroup\$ Don't even need á, ”‚¿Bad”IK is also a 9. \$\endgroup\$ – Grimmy Jul 8 at 10:29
3
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome! 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. \$\endgroup\$ – mbomb007 Jul 8 at 21:38
  • 3
    \$\begingroup\$ The length part could just be !="Bad" \$\endgroup\$ – Jo King Jul 9 at 2:14
  • \$\begingroup\$ 109 bytes \$\endgroup\$ – Olivier Grégoire Aug 27 at 14:32
3
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ This prints "Good" or "Bad" (with quotes); I'm not sure that's allowed. \$\endgroup\$ – Jordan Jul 8 at 16:29
  • 1
    \$\begingroup\$ 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! \$\endgroup\$ – Value Ink Jul 8 at 23:22
  • \$\begingroup\$ @ValueInk thanks! Jordan's issue also gets resolved by this change so it's a win-win. \$\endgroup\$ – DaveMongoose Jul 9 at 11:20
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 17 bytes, but less creative \$\endgroup\$ – pbeentje Jul 8 at 14:38
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

Excel, 24 bytes

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

Using @MilkyWay90's <C suggestion.

\$\endgroup\$
2
\$\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\$
  • \$\begingroup\$ Judging by the phrasing of the question, readline() is likely more appropriate than $argn. \$\endgroup\$ – Progrock Oct 14 at 15:55
2
\$\begingroup\$

Jelly, 9 bytes

“GooBa”œ^

Try it online!

Explanation

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

\$\endgroup\$
  • \$\begingroup\$ @JonathanAllan Thanks. Edited \$\endgroup\$ – Luis Mendo Jul 7 at 16:53
  • \$\begingroup\$ I don't see any indication that the input has to come through STDIN... \$\endgroup\$ – Erik the Outgolfer Jul 7 at 18:37
  • \$\begingroup\$ @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) \$\endgroup\$ – Jonathan Allan Jul 7 at 20:29
  • \$\begingroup\$ Looks like OP responded, input isn't restricted to STDIN. \$\endgroup\$ – Erik the Outgolfer Jul 9 at 5:43
  • \$\begingroup\$ @EriktheOutgolfer Thanks! Rolled back \$\endgroup\$ – Luis Mendo Jul 9 at 6:25
2
\$\begingroup\$

PowerShell, 22 20 bytes

'Good','Bad'-ne$args

Try it online!

-2 bytes thanks to mazzy

\$\endgroup\$
  • 1
    \$\begingroup\$ 20 bytes \$\endgroup\$ – mazzy Jul 7 at 19:57
2
\$\begingroup\$

Keg, 22 bytes

?^_^_o=[^aB^_|^ooG^]
\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

Keg, 20 17 15 13 8 bytes (SBCS)

‘5ƳP↫‘᠀-

Try it online!

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.

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"
\$\endgroup\$
  • 1
    \$\begingroup\$ Wonderful, I could not golf to that length... I have upvoted your answer. \$\endgroup\$ – A̲̲ Jul 12 at 11:08
  • \$\begingroup\$ @A__ just as i have up voted yours \$\endgroup\$ – Jono 2906 Jul 12 at 11:29
  • \$\begingroup\$ My answer is a lot worse than yours. You should not have upvoted my answer... \$\endgroup\$ – A̲̲ Jul 12 at 11:40
  • \$\begingroup\$ Is there any up to date keg documentation? \$\endgroup\$ – EdgyNerd Oct 11 at 7:09
  • \$\begingroup\$ @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 \$\endgroup\$ – Jono 2906 Oct 11 at 7:12
1
\$\begingroup\$

K (oK), 16 bytes

Solution:

$`Bad`Good"Bad"~

Try it online!

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

\$\endgroup\$
  • \$\begingroup\$ 15 bytes with loose constraints \$\endgroup\$ – streetster Jul 7 at 20:17
1
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 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) \$\endgroup\$ – Jonathan Allan Jul 7 at 17:27
  • \$\begingroup\$ @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. \$\endgroup\$ – Roman Jul 7 at 18:04
  • \$\begingroup\$ 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...? \$\endgroup\$ – Jonathan Allan Jul 7 at 18:10
  • \$\begingroup\$ @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. \$\endgroup\$ – Roman Jul 7 at 18:26
  • 1
    \$\begingroup\$ Looks like you could use symbols for the output to save 4. \$\endgroup\$ – Jonathan Allan Jul 7 at 18:38

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.