挑战说明:
编写一个要求用户输入的程序。用户将输入Good
或Bad
。您不必支持任何其他输入。如果用户输入Good
,则打印Bad
,反之亦然(到标准输出等)。
笔记:
1)您不能使用其他两个单词对。
2)您的程序只需要询问并打印一次。
3)您不需要显示提示字符串。
4)无论如何,输出必须看起来与输入分开。
5)不允许函数接受值并返回结果;用户必须与该程序进行交互。
祝好运!
挑战说明:
编写一个要求用户输入的程序。用户将输入Good
或Bad
。您不必支持任何其他输入。如果用户输入Good
,则打印Bad
,反之亦然(到标准输出等)。
笔记:
1)您不能使用其他两个单词对。
2)您的程序只需要询问并打印一次。
3)您不需要显示提示字符串。
4)无论如何,输出必须看起来与输入分开。
5)不允许函数接受值并返回结果;用户必须与该程序进行交互。
祝好运!
Answers:
exit('GBoaodd'['G'<input()::2])
测试输入是否'Good'
通过比较'G'<input()
。
使用以下事实:在Python中False==0
,True==1
将结果用作undefined 和of的with start
的切片的索引。'GBoaodd'
stop
step
2
'GBoaodd'[start:stop:step]
打印到STDERR(用exit
代替保存一个字节print
)。
'GoodBad'.strip(input())
一个短一点的字节。
完整的程序,提示从stdin输入并打印到stdout。
'GooBad'~¯1↓⍞
⍞
提示从stdin输入信息;Good
要么Bad
¯1↓
删除最后一个字符(d
); Goo
要么Ba
'GooBad'~
多集从这些字符中减去那些字符;Bad
要么Good
GooBad
或GoodBad
?
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
好吧,这花了一段时间。
未完成的说明:
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
favorite/disliked/"Turing-Machine-But-Way-Worse" is, without a doubt, my new favorite esolang.
未组装:
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$'
说明:
查看DOS存储在内存地址处的输入字符串的长度(加上前导空格),80H
并将其添加到AL
(最初0
是DOS)。如果1
字符串长度的二进制表示中的位数为奇数,则CPU奇偶校验标志设置为奇数,反之亦然。因此,输入字符串的' Bad'
长度4
(0000 0100
)是奇偶校验,输入字符串的' Good'
长度5
(0000 0101
)是偶校验。
DX
最初设置为指向字符串'Good$Bad$'
,并且如果奇偶校验为偶数(表示输入是' Good'
),则将字符串指针提前该长度(5
),因此现在指向'Bad$'
。如果奇偶校验是奇数,则不做任何事情,因为它已经指向'Good$'
。然后使用DOS API显示$
终止字符串以进行控制台。
例:
下载并测试GOODBAD.COM或从xxd
转储进行构建:
0000000: ba10 01d1 ee02 047b 0202 d0b4 09cd 21c3 .......{......!.
0000010: 476f 6f64 2442 6164 24 Good$Bad$
“Ċ³ṫ³»œṣ
一个完整的程序,需要使用Python格式的字符串作为参数
“Ċ³ṫ³»œṣ - 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
exit("C">input()and"Good"or"Bad")
exit()
:返回退出代码作为输出
"C">input()
:检查输入是否大于C
字母顺序的字符串
and"Good"
:如果结果为True
,则返回Good
or"Bad"
:否则,返回 Bad
exit(input()[3:]and"Bad"or"Good")
也适用于相同的字节数。
main(){puts("Good\0Bad"+getchar()%6);}
38字节
#include<stdio.h>
吗?
\0
吗?
,>+++++>,>,>,>,[<<<<[-<->>---<]<.>>+.>>.>>>]<[<<<[-<+>>+++<]<.>>-..>.>>]
说明:,> +++++>,>,>,>,
读取:“ G”,5,“ o”,“ o”,“ d”或“ B”,5,“ a”,“ d”,0
[<<<< [-<->> --- <] <。>> +。>>。>>>]如果最后一个字符不为零:
从第一个单元格减去5,从第三个单元格减去三次。增量单元格3
输出单元1、3、5
<[<<< [-<+ >> +++ <] <。>>-..>。>>]
否则,将5一次添加到第一个单元格,三次添加到第三个单元格。
递减单元格3
输出单元格1、3、3、4
”‚¿‰±”áIK
-1个字节感谢@Emigna。
说明:
”‚¿‰±” # Push dictionary string "Good Bad"
á # Only keep letters (to remove the space)
IK # Remove the input
# (output the result implicitly)
见矿(部此次05AB1E提示如何使用字典?),了解为什么”‚¿‰±”
是"Good Bad"
。
á
。
á
我不敢相信自己没有考虑过,但与此同时,我知道我永远也不会想到。;) 谢谢!(是的,我也有一些10字节的替代方案。)
”‚¿Bad”IK
它也是
interface G{static void main(String[]a){System.out.print(new java.util.Scanner(System.in).next().length()>3?"Bad":"Good");}}
最有可能的是,仍有一些改进的空间,但是我完全不喜欢打高尔夫球。
!="Bad"
(添加了空格以提高可读性)
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.
我得到输入的第一个字母Open mind
。然后,我需要确定它是什么。在B
= 66到G
= 71 之间的所有数字中,我的蛮力说66是最短的写(the sum ofa big cat the cube ofa big big cat
),因此我将输入的第一个字母与66进行了比较。场景我继续打印Good
,或者场景V打印Bad
。
?^_^_o=[^aB^_|^ooG^]
,>,,<<,[>-----.<---.+++.<<]>[+++++.+[-<-->]<-..>>.>]
由于Bad的字母比Good的字母短,因此最后一个输入为空。
,>,,<<, 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
+>,+;>,;,+;>;;;+;+;+[;<;;;,;+;;+;<];;+;+;;+;;+;
使用以下事实:您基本上可以将输入作为位,然后反转某些位以将其转换为相反的字母。
+>,+;>,;,+;>;;;+;+;+ 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
-rt
-᠀‘5ƳP↫
转译至:
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)
这是05AB1E答案的端口。本质上,它:
"GoodBad"
GoodBad
。-rt
标志告诉Keg从右到左读取令牌。?G=[øBad|ø‘5Ƴ
转换为以下内容:
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"