26
\$\begingroup\$

Challenge Description:

Write a program that asks the user for input. The user will enter Good or Bad. You do not have to support any other input. If the user enters Good, print Bad and vice versa (to stdout etc).

Notes:

1) You cannot use any other pair of two words.

2) Your program only has to ask and print once.

3) You do not need to display prompt string.

4) The output must appear separated from the input by any means.

5) No function is allowed accepting the value and returning the result; User must interact with the program.

Good luck!

\$\endgroup\$
6
  • 10
    \$\begingroup\$ May we write a function that takes input as argument instead of prompting for it? \$\endgroup\$
    – Adám
    Commented Jul 7, 2019 at 14:01
  • 9
    \$\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
    Commented Jul 9, 2019 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
    Commented Jul 9, 2019 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\$ Commented Jul 10, 2019 at 13:23
  • 7
    \$\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
    Commented Jul 12, 2019 at 13:58

88 Answers 88

53
\$\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\$
6
  • \$\begingroup\$ What a trick! Can't understand how this works. \$\endgroup\$
    – Ishaq Khan
    Commented Jul 7, 2019 at 15:50
  • \$\begingroup\$ Can you use a lambda to shorten bytes? \$\endgroup\$
    – MilkyWay90
    Commented Jul 7, 2019 at 16:55
  • \$\begingroup\$ @MilkyWay90 As per the question it must be a program accepting input. \$\endgroup\$ Commented Jul 7, 2019 at 17:11
  • \$\begingroup\$ @A__ by default yes, although there is a comment by OP which suggests it could be overruled here. \$\endgroup\$ Commented Jul 8, 2019 at 7:01
  • 7
    \$\begingroup\$ Too bad that "Good" and "Bad" share a "d", or you could do 'GoodBad'.strip(input()) which is a byte shorter. \$\endgroup\$
    – xnor
    Commented Jul 10, 2019 at 4:16
20
\$\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\$
4
  • 7
    \$\begingroup\$ Why the downvote‽ \$\endgroup\$
    – Adám
    Commented Jul 7, 2019 at 14:39
  • 1
    \$\begingroup\$ Does the code have GooBad or GoodBad? \$\endgroup\$ Commented Jul 8, 2019 at 1:58
  • \$\begingroup\$ I think it should have GooBad, as adding a character ```d`` will make this post 14 bytes. \$\endgroup\$
    – user85052
    Commented Jul 8, 2019 at 2:20
  • \$\begingroup\$ @NoOneIsHere Thanks. Fixed. \$\endgroup\$
    – Adám
    Commented Jul 8, 2019 at 4:33
13
\$\begingroup\$

bash, 20 bytes

sed s/$1//<<<GoodBad

Try it online!

\$\endgroup\$
11
\$\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\$
5
  • 5
    \$\begingroup\$ "Turing-Machine-But-Way-Worse" is, without a doubt, my new favorite esolang. \$\endgroup\$ Commented Jul 8, 2019 at 17:53
  • \$\begingroup\$ @MikeTheLiar Thanks! \$\endgroup\$
    – MilkyWay90
    Commented Jul 8, 2019 at 18:10
  • \$\begingroup\$ "YOU HAVE BEEN TERMINATED" ArnoldC, is that you? \$\endgroup\$ Commented Jul 9, 2019 at 20:28
  • \$\begingroup\$ @TemporalWolf It is I, ArnoldC! \$\endgroup\$
    – MilkyWay90
    Commented Jul 9, 2019 at 20:36
  • \$\begingroup\$ @A__ It isn't actually ArnoldC; I just put the exit command as a comment as a joke \$\endgroup\$
    – MilkyWay90
    Commented Jul 10, 2019 at 15:41
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\$

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
  • 2
    \$\begingroup\$ 34: print("C">input()and"Good"or"Bad") \$\endgroup\$
    – Adám
    Commented Jul 7, 2019 at 14:51
  • 2
    \$\begingroup\$ exit(input()[3:]and"Bad"or"Good") also works for the same byte count. \$\endgroup\$
    – Neil
    Commented Jul 8, 2019 at 9:14
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
  • 1
    \$\begingroup\$ Looks like OP responded, input isn't restricted to STDIN. \$\endgroup\$ Commented Jul 9, 2019 at 5:44
6
\$\begingroup\$

C, 39 38 bytes

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

Try it online!

Saved one byte thanks to @tsh.

\$\endgroup\$
4
  • 5
    \$\begingroup\$ main(){puts("Good\0Bad"+getchar()%6);} 38 bytes \$\endgroup\$
    – tsh
    Commented Jul 8, 2019 at 1:47
  • \$\begingroup\$ Shouldn't you add #include<stdio.h>? \$\endgroup\$ Commented Jul 9, 2019 at 11:04
  • 4
    \$\begingroup\$ @polfosolఠ_ఠ If this were anything but code golf, you should, but in C89, you can implicitly declare functions. \$\endgroup\$
    – pommicket
    Commented Jul 9, 2019 at 11:11
  • \$\begingroup\$ Can you use a null byte instead of \0? \$\endgroup\$ Commented Dec 19, 2019 at 14:18
6
\$\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\$
2
  • \$\begingroup\$ That's a nice solution. You can shorten it a little bit by not using a newline in the input. ,>+++++>,>,>,[<<<[-<->>---<]<.>>+.>>.>>]<[<<[-<+>>+++<]<.>>-..>.>] \$\endgroup\$
    – Dorian
    Commented Jul 9, 2019 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
    Commented Jul 9, 2019 at 17:11
5
\$\begingroup\$

R, 42 37 35 32 bytes

-10 thanks to Giuseppe and AkselA!

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

Try it online!

\$\endgroup\$
6
  • 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
    Commented Jul 8, 2019 at 20:35
  • 1
    \$\begingroup\$ using "C" instead of the first "Bad" as in this answer will save another couple bytes. \$\endgroup\$
    – Giuseppe
    Commented Jul 8, 2019 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
    Commented Jul 9, 2019 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
    Commented Jul 9, 2019 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
    Commented Jul 9, 2019 at 19:46
5
\$\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\$
3
  • 2
    \$\begingroup\$ c offers a shorter solution \$\endgroup\$
    – user41805
    Commented Aug 27, 2019 at 16:10
  • 1
    \$\begingroup\$ You can still save 3 more bytes using c \$\endgroup\$
    – user41805
    Commented Aug 28, 2019 at 5:03
  • 1
    \$\begingroup\$ Had to play around with it a bit, but I figured it out! \$\endgroup\$ Commented Aug 28, 2019 at 5:24
5
\$\begingroup\$

Retina, 10 bytes

:`GoodBad

Try it online!

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

\$\endgroup\$
4
\$\begingroup\$

Haskell, 36 34 bytes

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

Try it online!

Edit: -2 bytes thanks to @cole

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 34 bytes \$\endgroup\$
    – cole
    Commented Jul 7, 2019 at 17:01
4
\$\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\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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

Befunge-93, 20 18 bytes

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

Try it online!

-2 bytes thanks to Jo King

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

Ruby, 22 bytes

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

Try it online!

\$\endgroup\$
2
  • \$\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\$ Commented Jul 8, 2019 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
    Commented Jul 8, 2019 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\$
4
  • \$\begingroup\$ I can see many alternate variations on this, but they all end up at the same byte count :( \$\endgroup\$
    – Emigna
    Commented Jul 8, 2019 at 9:49
  • 1
    \$\begingroup\$ Actually, you can save a byte with á. \$\endgroup\$
    – Emigna
    Commented Jul 8, 2019 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\$ Commented Jul 8, 2019 at 9:54
  • 1
    \$\begingroup\$ Don't even need á, ”‚¿Bad”IK is also a 9. \$\endgroup\$
    – Grimmy
    Commented Jul 8, 2019 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\$
3
  • 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
    Commented Jul 8, 2019 at 21:38
  • 4
    \$\begingroup\$ The length part could just be !="Bad" \$\endgroup\$
    – Jo King
    Commented Jul 9, 2019 at 2:14
  • \$\begingroup\$ 109 bytes \$\endgroup\$ Commented Aug 27, 2019 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\$
3
  • \$\begingroup\$ This prints "Good" or "Bad" (with quotes); I'm not sure that's allowed. \$\endgroup\$
    – Jordan
    Commented Jul 8, 2019 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
    Commented Jul 8, 2019 at 23:22
  • \$\begingroup\$ @ValueInk thanks! Jordan's issue also gets resolved by this change so it's a win-win. \$\endgroup\$ Commented Jul 9, 2019 at 11:20
3
\$\begingroup\$

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

C (gcc), 48 bytes

main(){puts(getchar()-66?"Bad":"Good");}

Try It Online!

The program only actually takes one character as input, although getchar reads until a newline is found unlike getch which only lets you input a single character. It checks if there's a difference between that character and the ascii code for 'B' (66), printing "Bad" if there is and "Good" if there isn't.

\$\endgroup\$
2
  • \$\begingroup\$ Taking just one character as input is perfectly valid, and is in fact what most other answers are doing \$\endgroup\$
    – mousetail
    Commented Jan 19, 2023 at 10:13
  • \$\begingroup\$ @mousetail Thanks, I edited my answer to remove the question :) \$\endgroup\$
    – Peter
    Commented Jan 19, 2023 at 12:06
3
\$\begingroup\$

JavaScript, 35 32 31 bytes

-3 bytes thanks to @xigoi

-1 byte thanks to @l4m2

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

\$\endgroup\$
2
  • 2
    \$\begingroup\$ -3 bytes: prompt()<'G' \$\endgroup\$
    – xigoi
    Commented Jul 27, 2021 at 22:48
  • 1
    \$\begingroup\$ prompt()[3] enough \$\endgroup\$
    – l4m2
    Commented Jan 18, 2023 at 14:47
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\$
1
  • 1
    \$\begingroup\$ 17 bytes, but less creative \$\endgroup\$
    – pbeentje
    Commented Jul 8, 2019 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\$

Java, 30 bytes

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

TIO

\$\endgroup\$
5
  • \$\begingroup\$ How does it take input from the user (e.g. by reading from stdin) and print the result (instead of just returning it)? \$\endgroup\$
    – nimi
    Commented Jul 7, 2019 at 22:14
  • \$\begingroup\$ @nimi OP hasn't specified whether IO includes arguments and returns. By default, it is allowed \$\endgroup\$ Commented Jul 7, 2019 at 22:52
  • \$\begingroup\$ "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. \$\endgroup\$
    – nimi
    Commented Jul 7, 2019 at 22:59
  • \$\begingroup\$ @nimi I can argue a missing argument error is a prompt. As for output, you do have a point. \$\endgroup\$ Commented Jul 7, 2019 at 23:04
  • \$\begingroup\$ You can take the inputs as character-arrays, which is allowed by default for strings, to change s.charAt(0) to s[0]: 23 bytes. \$\endgroup\$ Commented Mar 4, 2022 at 15:31
2
\$\begingroup\$

Perl 5 -p, 15 bytes

$_=/B/?Good:Bad

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Just revisited this. Abusing flags as usual -0144l, you can save the ds! Try it online! \$\endgroup\$ Commented Jun 21, 2022 at 21:17
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\$
1
  • \$\begingroup\$ Judging by the phrasing of the question, readline() is likely more appropriate than $argn. \$\endgroup\$
    – Progrock
    Commented Oct 14, 2019 at 15:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.