首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASCII艺术反思

ASCII艺术反思
EN

Code Golf用户
提问于 2016-07-13 15:59:12
回答 19查看 4.1K关注 0票数 27

在这个挑战中,您将被赋予一个文本块,并且您需要对文本执行反射。

输入:

  1. 要反射的字符串。文本不能作为一个数组提供,数组的元素是文本的行。例如,允许使用"ab\ncd"['a','b','\n','c','d'],但不允许使用['ab','cd'][['a','b'],['c','d']]。您可以假设所有行都有相同数量的字符(在需要时填充空格)。
  2. 布尔值,其中True表示Y反射,False表示X反射

这两个输入可以以任何顺序传递。

输出:

反射的字符串。角色不会改变,只会改变自己的位置。生成的图像块应该对齐到左上角(第一行和第一列都必须包含一个非空白字符)。允许尾随空格(在任何行上)。

测试用例:

代码语言:javascript
复制
False
  o /
--|/
  |
 / \

/ o
 /|--
  |
 \ /
代码语言:javascript
复制
True
  o /
--|/
  |
 / \

 / \
  |
--|/
  o /
代码语言:javascript
复制
True
text

text
代码语言:javascript
复制
False
text

txet
代码语言:javascript
复制
True
P
P
C
G

G
C
P
P
代码语言:javascript
复制
False
P
P
C
G

P
P
C
G
代码语言:javascript
复制
True
abcde
fghij
kl mn
opqrs
tuvwx

tuvwx
opqrs
kl mn
fghij
abcde

这是一个密码-高尔夫,所以用你最喜欢的语言回答最短的答案!

EN

回答 19

Code Golf用户

发布于 2016-07-13 16:38:42

Pyke,7字节

代码语言:javascript
复制
!I_)ncX

在这里试试!

代码语言:javascript
复制
!I )    - if not boolean:
  _     -  input = reversed(input)
    nc  - input.split("\n")
      X - splat(input)
        -  (print lines backwards)
票数 10
EN

Code Golf用户

发布于 2016-07-14 17:05:14

32位x86机器代码,76字节

以六角表示:

代码语言:javascript
复制
31c031c9495789f7fcf2aef7d15192b00a89f7f2ae5829f7f7f787f95f4b89c3741287d94b534b8a041eaa75f95b01dea4e2f2c348f7e101c6b00a5651f3a4595e29ce4f4b0f44c3aa75f0c3

输入:EBX:方向标志(0/1),ESI:输入字符串,EDI:输出缓冲区。输入必须是矩形的。

代码语言:javascript
复制
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                 
票数 6
EN

Code Golf用户

发布于 2016-07-13 19:03:45

果冻,8 字节数

代码语言:javascript
复制
ṣ⁷ṚU⁴?j⁷

在这里试试。

代码语言:javascript
复制
ṣ⁷         Split over newlines.
  ṚU⁴?     If ⁴ (2nd argument), then Ṛ (reverse rank ∞), else U (reverse rank 1).
      j⁷   Join with newlines.
票数 5
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/85363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档