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"