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

77 Answers 77

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

Boolfuck, 110 68 bytes

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

Thanks to Jo King for the massively improved solution!

Try it with Online!

\$\endgroup\$
2
  • \$\begingroup\$ 68 bytes. I think it can be better though \$\endgroup\$
    – Jo King
    Jul 15 '19 at 0:51
  • \$\begingroup\$ Wow, how were you able to save so many bytes over my answer? \$\endgroup\$
    – EdgyNerd
    Jul 15 '19 at 6:26
2
\$\begingroup\$

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

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

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

Try it online!

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

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ -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). \$\endgroup\$ Jan 28 '20 at 16:09
  • \$\begingroup\$ 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. \$\endgroup\$
    – Dorian
    Jan 29 '20 at 8:04
2
\$\begingroup\$

Kotlin, 52 bytes

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

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ What does the !! operator do? \$\endgroup\$
    – xigoi
    Jul 27 at 22:45
  • 1
    \$\begingroup\$ !! asserts that a nullable value is not null, effectively casting it down from T? to T or throwing a runtime error if it's null. replace doesn't accept String? but that's what readLine() returns so I have to assert it's not null (since it never will be per the challenge.) \$\endgroup\$
    – snail_
    Jul 27 at 23:23
2
\$\begingroup\$

MAWP, 59 bytes

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

Try it!

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

Vyxal r, 7 bytes

`ƛ⁋«Ṫ`-

Try it Online!

This is irony in a nutshell.

Explained

`...`-
`...`  # the string "GoodBad"
     - # ^ - input (removes it)

In the spirit of my Keg answer, here's the compiled code:

global stack, register, printed, output, MAP_START, MAP_OFFSET, _join, _vertical_join, use_encoding, input_level, raw_strings, retain_items, reverse_args, this_function
stack.append("GoodBad")

rhs, lhs = pop(stack, 2); stack.append(subtract(lhs, rhs))
\$\endgroup\$
2
\$\begingroup\$

JavaScript, 35 32 bytes

-3 bytes thanks to @xigoi

alert(prompt()<'G'?'Good':'Bad')

\$\endgroup\$
1
  • 1
    \$\begingroup\$ -3 bytes: prompt()<'G' \$\endgroup\$
    – xigoi
    Jul 27 at 22:48
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\$
1
  • \$\begingroup\$ 15 bytes with loose constraints \$\endgroup\$
    – mkst
    Jul 7 '19 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\$
6
  • \$\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\$ Jul 7 '19 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 '19 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\$ Jul 7 '19 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 '19 at 18:26
  • 1
    \$\begingroup\$ Looks like you could use symbols for the output to save 4. \$\endgroup\$ Jul 7 '19 at 18:38
1
\$\begingroup\$

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

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

Try it online!

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

Java, 30 bytes

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

TIO

\$\endgroup\$
4
  • \$\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
    Jul 7 '19 at 22:14
  • \$\begingroup\$ @nimi OP hasn't specified whether IO includes arguments and returns. By default, it is allowed \$\endgroup\$ Jul 7 '19 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
    Jul 7 '19 at 22:59
  • \$\begingroup\$ @nimi I can argue a missing argument error is a prompt. As for output, you do have a point. \$\endgroup\$ Jul 7 '19 at 23:04
1
\$\begingroup\$

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]])
\$\endgroup\$
9
  • 1
    \$\begingroup\$ Normally, we recommend leaving challenges up for a while (I generally give it a week) before self-answering. \$\endgroup\$
    – Adám
    Jul 7 '19 at 14:38
  • \$\begingroup\$ @Adám Good suggestion. \$\endgroup\$
    – Ishaq Khan
    Jul 7 '19 at 14:40
  • 1
    \$\begingroup\$ print({'G':'Bad','B':'Good'}[input()[0]]) works too for -2 bytes \$\endgroup\$
    – MilkyWay90
    Jul 7 '19 at 20:14
  • 1
    \$\begingroup\$ print(['Bad','Good'][input()<'C']) works for 34 bytes (-9) \$\endgroup\$
    – MilkyWay90
    Jul 7 '19 at 20:17
  • \$\begingroup\$ @MilkyWay90 You're genius! \$\endgroup\$
    – Ishaq Khan
    Jul 7 '19 at 23:39
1
\$\begingroup\$

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

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

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think you can drop the space before else but no other spaces as you noticed. \$\endgroup\$
    – Neil
    Jul 8 '19 at 9:20
1
\$\begingroup\$

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.

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

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

Python 3, 37 bytes

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

Try it online!

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

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!

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

Racket, 38 bytes

(write(match(read)['Bad'Good][_'Bad]))
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ @JoKing Yes. Thanks :) \$\endgroup\$
    – Sylwester
    Aug 3 '19 at 12:33
1
\$\begingroup\$

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

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

Javascript 50 bytes

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

\$\endgroup\$
1
  • \$\begingroup\$ Please add what language you answer uses and a short description of how it functions \$\endgroup\$ Aug 13 '20 at 11:25

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.