Code Golf Asked by Ishaq Khan on October 15, 2020
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!
Javascript 50 bytes
alert((305786-parseInt(prompt(),26)).toString(26))
Answered by Yaroslav Gaponov on October 15, 2020
:`GoodBad
:
swaps the input and the regex, so this computes 'GoodBad'.replace(input, '')
.
Answered by ovs on October 15, 2020
Answered by Razetime on October 15, 2020
Answered by snail_ on October 15, 2020
j
, 8 bytesStill doesn't tie with Keg. Help!
♥d←╖←I¡%
Uncompressed:
G'%Av%?S,
% 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
```
Answered by user92069 on October 15, 2020
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
Answered by Tau on October 15, 2020
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
Answered by sporeball on October 15, 2020
"GoodBad"/
"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
Answered by user85052 on October 15, 2020
¿⁻LS³Ba¦Goo¦d
¿⁻LS³ If length of input minus 3 is truthy:
Ba¦ print Ba
Goo¦ else print Goo
d print d
Answered by Pseudo Nym on October 15, 2020
(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.
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
.
Answered by Hello Goodbye on October 15, 2020
Answered by Jirka Picek on October 15, 2020
.F`Goo`x?c`Ba`;H"
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
Answered by FlipTack on October 15, 2020
d
, 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↓
% 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
```
Answered by user85052 on October 15, 2020
Fn.new{|x|"GooBa".trim(x)+"d"}
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"
Answered by user85052 on October 15, 2020
<?=strtok(BaGoo,readline()).d;
Best suppress notices.
Answered by Progrock on October 15, 2020
(much whitespace)
-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
Answered by Dorian on October 15, 2020
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.
Answered by GammaFunction on October 15, 2020
<<<${${:-GoodBad}/$1}
<<<${${[implicit parameter]:-fallback}/pattern[/implicit empty replacement]}
No coreutils, and nearly as good as the Bash+coreutils answer (which is compatible with Zsh).
Answered by GammaFunction on October 15, 2020
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.
Answered by user85052 on October 15, 2020
readline()=="Bad"?"Good":"Bad";
["Bad"=>"Good","Good"=>"Bad"][readline()];
Answered by Micio Informatico on October 15, 2020
g->{if(g=="Bad")return"Good";return"Bad";}
Checks if input is Bad
.
-9 to @JoKing
Answered by CuttingChipset on October 15, 2020
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"
Answered by TheOnlyMrCat on October 15, 2020
ChooseFromMenu''[Good Bad]
Case
Text'Bad'
Case
Text'Good'
End
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.
Answered by pfg on October 15, 2020
+>,+;>,;,+;>;;;+;+;+[;<;;;,;+;;+;<];;+;+;;+;;+;
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.
+>,+;>,;,+;>;;;+;+;+ 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
Answered by Jo King on October 15, 2020
(?(=(r)'Bad)'Good'Bad)
Answered by Sylwester on October 15, 2020
,>,,,[>|"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
Answered by Sylwester on October 15, 2020
rEEeREeEeeeEEErrEEreeEeeeEEEreeEEeEEEEreeEEeEEEEreeEEeeEeeREerREEreeEeeeeEereeEEeeeeEreeEEeeEeeREeReEree
# 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
Answered by RedClover on October 15, 2020
,+;+[;+;;;;+;+;+;<;]>+;;[+;;;+;+;+;;;;+;+;;+;+;;;;+];+;;+;;;+;+;;+;;
Thanks to Jo King for the massively improved solution!
Answered by EdgyNerd on October 15, 2020
-rt
-᠀‘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:
"GoodBad"
GoodBad
with nothing. -rt
flag tells Keg to read tokens from right to left.?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)
?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"
Answered by Lyxal on October 15, 2020
,>,,<<,[>-----.<---.+++.<<]>[+++++.+[-<-->]<-..>>.>]
Relies on Bad being one letter shorter than Good, so the last input is empty.
,>,,<<, 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
Answered by Jo King on October 15, 2020
(write(match(read)['Bad'Good][_'Bad]))
Answered by Winny on October 15, 2020
(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
Answered by EdgyNerd on October 15, 2020
?^_^_o=[^aB^_|^ooG^]
Answered by user85052 on October 15, 2020
import'dart:io';main()=>print('BadGood'.replaceAll(stdin.readLineSync(),''));
Answered by Elcan on October 15, 2020
Answered by Dat on October 15, 2020
Answered by Robert S. on October 15, 2020
,>+++++>,>,>,>,[<<<<[-<->>---<]<.>>+.>>.>>>]<[<<<[-<+>>+++<]<.>>-..>.>>]
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
Answered by Helena on October 15, 2020
interface G{static void main(String[]a){System.out.print(new java.util.Scanner(System.in).next().length()>3?"Bad":"Good");}}
Most likely, there‘s still some room for improvement, but I‘m entirely new to code golfing.
Answered by Felix Bohnacker on October 15, 2020
A ternary is just cheaper:
<?=$argn==Bad?Goo:Ba?>d
Original answer, 26 bytes
<?=[Ba,Goo][$argn==Bad]?>d
Or 21 bytes (but this is basically Arnauld's answer)
<?=$argn[3]?Ba:Goo?>d
Answered by 640KB on October 15, 2020
1 INPUT A$
2 IF A$="GOOD" THEN PRINT "BAD"
3 IF A$="BAD" THEN PRINT "GOOD"
1 INPUT A$
2 PRINT "GOOD" AND A$="BAD";"BAD" AND A$="GOOD"
Answered by Shaun Bebbers on October 15, 2020
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:
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$
Answered by 640KB on October 15, 2020
"Bad":i≠7*?~"Good"@
Prints Good
when the input is Bad
and prints Bad
for all other inputs.
Answered by Draco18s no longer trusts SE on October 15, 2020
-P
, 11 bytes"GoodBad"qU
"GoodBad"qU U = Input "Good" "Bad"
"GoodBad" String literal "GoodBad" "GoodBad"
qU Split at U ["","Bad"] ["Good",""]
-P Join into a string "Bad" "Good"
"GoodBad"rU
r
replaces U
with ""
Answered by Oliver on October 15, 2020
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!
Answered by DaveMongoose on October 15, 2020
+-"GooBa"zd
+-"GooBa"zd Implicit: z=input()
-"GooBa"z Keep letters in "GooBa" which do not appear in z
+ d Append "d", implicit print
Answered by Sok on October 15, 2020
=IF(A1>"C","Bad","Good")
Using @MilkyWay90's <C
suggestion.
Answered by Wernisch on October 15, 2020
”‚¿‰±”á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"
.
Answered by Kevin Cruijssen on October 15, 2020
Answered by G B on October 15, 2020
exit(['Bad','Good'][input()<'G'])
Prints to stderr, to save one byte over print()
.
Answered by ruohola on October 15, 2020
print('Good','Bad')['C'<input()]
Using exit
requires extra brackets around the whole expression so in this case print
is 1 byte shorter.
Answered by ElPedro on October 15, 2020
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')
Answered by ADJenks on October 15, 2020
Answered by Xcali on October 15, 2020
-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...
Answered by user85052 on October 15, 2020
Answered by pommicket on October 15, 2020
/#Good/Bad//#Bad/Good/#
There is no other way to take input in /// so it is hard-coded:
/#Good/Bad//#Bad/Good/#<INPUT HERE>
Answered by Comrade SparklePony on October 15, 2020
Down to 35 thanks to @Expired Data
fun a->if a>"B"then"Bad"else"Good"
Original:
F# (.NET Core), 50 bytes
printf(if stdin.ReadLine()>"B"then"Bad"else"Good")
Answered by LSM07 on October 15, 2020
Answered by Benjamin Urquhart on October 15, 2020
$Good'$Bad^^Stdin[]|Echo
$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)
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[]
Answered by Conor O'Brien on October 15, 2020
Answered by Expired Data on October 15, 2020
Answered by Andrei Odegov on October 15, 2020
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
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
Answered by MilkyWay90 on October 15, 2020
Solution:
$`Bad`Good"Bad"~
Returns "Good"
if input is "Bad"
otherwise returns "Bad"
for all other inputs.
Answered by streetster on October 15, 2020
interact g
g"Bad"="Good"
g _="Bad"
Edit: -2 bytes thanks to @cole
Answered by nimi on October 15, 2020
Answered by Doorknob on October 15, 2020
If[$ScriptInputString=="Bad",Good,Bad]
-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
Answered by Roman on October 15, 2020
oo
o
T`GoaB`Ro
o
oo
Try it online! Link includes test suite. Explanation:
oo
o
Turn Good
into God
.
T`GoaB`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
.
Answered by Neil on October 15, 2020
Answered by negative seven on October 15, 2020
“GooBa”œ^
Multiset symmetric difference between the input and the string “GooBa”
.
Answered by Luis Mendo on October 15, 2020
çEF♫a║▬h
Essentially replace("BadGood", input, "")
.
Multiset xor with "GooBa". Algorithm copied verbatim from Luis Mendo
Answered by recursive on October 15, 2020
“Ċ³ṫ³»œṣ
A full program expecting a Python formatted string as an argument
“Ċ³ṫ³»œṣ - 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
Answered by Jonathan Allan on October 15, 2020
exit('GBoaodd'['G'<input()::2])
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
).
Answered by Jonathan Allan on October 15, 2020
exit("C">input()and"Good"or"Bad")
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
Answered by user85052 on October 15, 2020
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]])
Answered by Ishaq Khan on October 15, 2020
Full program that prompts for input from stdin and prints to stdout.
'GooBad'~¯1↓⍞
⍞
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
Answered by Adám on October 15, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP