在这个挑战中,您将被赋予一个文本块,并且您需要对文本执行反射。
"ab\ncd"和['a','b','\n','c','d'],但不允许使用['ab','cd']或[['a','b'],['c','d']]。您可以假设所有行都有相同数量的字符(在需要时填充空格)。True表示Y反射,False表示X反射这两个输入可以以任何顺序传递。
反射的字符串。角色不会改变,只会改变自己的位置。生成的图像块应该对齐到左上角(第一行和第一列都必须包含一个非空白字符)。允许尾随空格(在任何行上)。
False
o /
--|/
|
/ \
/ o
/|--
|
\ /True
o /
--|/
|
/ \
/ \
|
--|/
o /True
text
textFalse
text
txetTrue
P
P
C
G
G
C
P
PFalse
P
P
C
G
P
P
C
GTrue
abcde
fghij
kl mn
opqrs
tuvwx
tuvwx
opqrs
kl mn
fghij
abcde这是一个密码-高尔夫,所以用你最喜欢的语言回答最短的答案!
发布于 2016-07-13 16:38:42
!I_)ncX在这里试试!
!I ) - if not boolean:
_ - input = reversed(input)
nc - input.split("\n")
X - splat(input)
- (print lines backwards)发布于 2016-07-14 17:05:14
以六角表示:
31c031c9495789f7fcf2aef7d15192b00a89f7f2ae5829f7f7f787f95f4b89c3741287d94b534b8a041eaa75f95b01dea4e2f2c348f7e101c6b00a5651f3a4595e29ce4f4b0f44c3aa75f0c3输入:EBX:方向标志(0/1),ESI:输入字符串,EDI:输出缓冲区。输入必须是矩形的。
0: 31 c0 xor eax,eax ;EAX=0
2: 31 c9 xor ecx,ecx
4: 49 dec ecx ;ECX=(uint)-1
5: 57 push edi
6: 89 f7 mov edi,esi
8: fc cld
9: f2 ae repne scasb ;Scan input string for terminating NULL
b: f7 d1 not ecx ;ECX==<input string length (including NULL)>
d: 51 push ecx
e: 92 xchg edx,eax ;EDX=0
f: b0 0a mov al,0x0a ;'\n'
11: 89 f7 mov edi,esi
13: f2 ae repne scasb ;Scan input string for the first newline
15: 58 pop eax ;EAX==<input string length (including NULL)>
16: 29 f7 sub edi,esi ;EDI==<single line length (including '\n')>
18: f7 f7 div edi ;EAX==<# of lines>
1a: 87 f9 xchg ecx,edi ;ECX=EDI
1c: 5f pop edi ;EDI=<dest buffer>
1d: 4b dec ebx ;Test input flag (0/1)
1e: 89 c3 mov ebx,eax ;EBX=<# of lines>
20: 74 12 je _vertical
22: 87 d9 xchg ecx,ebx ;Horisontal flip, exchange ECX & EBX so we can use LOOP
24: 4b dec ebx ;EBX=<single line length (excluding '\n')>
_hfouter:
25: 53 push ebx
_hfinner:
26: 4b dec ebx ;Decrement inner loop counter
27: 8a 04 1e mov al,[esi+ebx] ;AL=ESI[EBX]
2a: aa stosb ;*EDI++=AL
2b: 75 f9 jne _hfinner ;EBX==0 => break
2d: 5b pop ebx
2e: 01 de add esi,ebx ;*ESI=='\n' (\0 on the last line)
30: a4 movsb ;*EDI++=*ESI++, ESI now points to the next line
31: e2 f2 loop _hfouter ;--ECX==0 => break
33: c3 ret ;Nothing more to do here
_vertical:
34: 48 dec eax ;# of strings less one
35: f7 e1 mul ecx ;Line length (including '\n')
37: 01 c6 add esi,eax ;ESI+=ECX*(EAX-1), ESI now points to the beginning of the last line
39: b0 0a mov al,0x0a ;'\n'
_vfloop:
3b: 56 push esi
3c: 51 push ecx
3d: f3 a4 rep movsb ;Copy the whole line to the output including newline/NULL at the end
3f: 59 pop ecx
40: 5e pop esi
41: 29 ce sub esi,ecx ;Set ESI to the beginning of the previous line
43: 4f dec edi ;*EDI=='\n' (0 on the first iteration), should overwrite it with correct value
44: 4b dec ebx ;Decrement loop counter
45: 0f 44 c3 cmove eax,ebx ;if (EBX==0) EAX=EBX, this clears EAX on the last iteration
48: aa stosb ;*EDI++=EBX?'\n':0
49: 75 f0 jne _vfloop ;EBX==0 => break
4b: c3 ret https://codegolf.stackexchange.com/questions/85363
复制相似问题