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
    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
    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
    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\$ 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
    Jul 12, 2019 at 13:58

88 Answers 88

1 2
3
1
\$\begingroup\$

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

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

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

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

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

FALSE, 23 bytes

^'B=$["Good"]?~["Bad"]?

Try it online!

Explanation

The program gets an input character and checks if it is equal to 'B'. If it is, it prints 'Good', and if it isn't it prints 'Bad'. This makes use of the fact that 'Good' and 'Bad' are easily differentiable based on simply the first character of each word.

^                  {Get input character}
'B=                {See if input char is equal to 'B'}
["Good"]?~["Bad"]? {If top of stack is TRUE, print "Good", else print "Bad"}

Note: Curly brackets denote comments in FALSE. In the past I've used '//' to comment FALSE code in my explanations, but since it isn't syntactically valid I'm now trying to use FALSE's comment syntax.

\$\endgroup\$
1
\$\begingroup\$

APOL, 32 bytes

Just checks if the input starts with "G".

g(["Good" "Bad"] I(=(g(i) "G")))

\$\endgroup\$
1
\$\begingroup\$

(e-)TeX, 48 bytes

\read0to~\expanded{\def\##1~{#1}}\#Good Bad \bye

Output is to dvi/pdf file.

\$\endgroup\$
1
\$\begingroup\$

Pip, 12 bytes

"GoodBad"RMq

Attempt This Online!

Explanation

           q  ; Read a line of input from stdin
         RM   ; Remove that substring from
"GoodBad"     ; This literal string
\$\endgroup\$
1
\$\begingroup\$

QBasic, 37 bytes

INPUT s$
IF"C"<s$THEN?"Bad"ELSE?"Good

Try it at Archive.org

Explanation

Uses string comparison to separate the two cases. Ungolfed:

INPUT s$
IF "C" < s$ THEN PRINT "Bad" ELSE PRINT "Good"
\$\endgroup\$
1
\$\begingroup\$

Python 3, 30 Bytes

exit({'Good','Bad'}-{input()})

Uses the same exit trick as the other python 3 solution. It's unclear to me if this solution is necessarily allowed by the problem, but the output is certainly separated from the input, so I think it counts.

\$\endgroup\$
1
\$\begingroup\$

Factor, 29 bytes

read1 66 = "Good""Bad"? print

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Acc!!, 105 bytes

N
Count i while _/71 {
Write 66
Write 97
0
}
Count i while _ {
Write 71
Write 111
Write 111
0
}
Write 100

Try it online!

Explanation

# Read a character from stdin (user must enter a full line)
N
# Loop while the character code int-divided by 71 is nonzero (i.e. G was entered)
Count i while _ / 71 {
  # Write Ba
  Write 66
  Write 97
  # Set accumulator to 0 to exit the loop
  0
}
# Loop while the accumulator is nonzero (i.e. previous loop did not run)
Count i while _ {
  # Write Goo
  Write 71
  Write 111
  Write 111
  # Set accumulator to 0 to exit the loop
  0
}
# Write d
Write 100
\$\endgroup\$
1
\$\begingroup\$

Thunno, \$15\log_{256}(96)\approx\$ 12.35 bytes

"Bad"Dz0=?"Good

Attempt This Online!

"Bad"Dz0=?"Good  # Implicit input
"Bad"D           # Push the string bad and duplicate           (STACK: "Bad", "Bad")
      z0         # Push the input                              (STACK: "Bad", "Bad", input)
        =?"Good  # If they are equal, push the string "Good"   (STACK: "Bad", "Good") IF input == "Bad"
                 # Otherwise, the stack is left as-is          (STACK: "Bad") IF input != "Bad"
                 # Implicit output of top of stack
\$\endgroup\$
0
\$\begingroup\$

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

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

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.

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

Python 3, 33 bytes

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

Try it online!

 

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

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

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

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

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!

\$\endgroup\$
1
0
\$\begingroup\$

Dart, 77 bytes

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

Try it online!

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

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

Zozotez: 22

(?(=(r)'Bad)'Good'Bad)
\$\endgroup\$
0
\$\begingroup\$

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.

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

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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 \$\endgroup\$
    – Jo King
    Aug 3, 2019 at 7:56
  • \$\begingroup\$ @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. \$\endgroup\$ Aug 3, 2019 at 8:10
0
\$\begingroup\$

PHP, 31 bytes

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

Try it online!

Another way, 41 bytes

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

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Shorter: ['bad'=>'good'][readline()]??'bad'; \$\endgroup\$
    – Progrock
    Oct 13, 2019 at 18:08
0
\$\begingroup\$

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.

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

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

Thunno 2, 9 bytes

’⁽ȯBad’$o

Attempt This Online!

Explanation

’⁽ȯBad’$o  # Implicit input
’⁽ȯBad’    # Compressed string "GoodBad"
       $o  # Remove the input
           # Implicit output
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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