给定一个只包含字母和数字的输入字符串,编写一个程序或函数,打印可能的可打印的ASCII字符(十六进制20-7E),这些字符与字符串的值以8、10和16 (如果可能的话)对应。字符必须按照它们对应的基(基数8,第一,等等)的顺序增加。输出可以是数组格式(如[& . F]),也可以像示例一样由空格或换行符分隔(尾尾换行符是可选的)。
如果没有一个可能的可打印的ASCII字符可以形成,程序必须没有任何输出。
31
==> 1
47
==> ' / G
69
==> E i
7A
==> z
100
==> @ d
156
==> n
189
==> <empty>
potaTO
==> <empty>
5G
==> <empty>
19
==> <empty>这是密码-高尔夫,所以用最少字节的答案获胜。适用标准规则。
发布于 2016-02-16 22:36:40
s=>[for(b of'o0x')if((c=+(0+b+s))>31&c<127)String.fromCharCode(c)].join` `发布于 2016-02-16 22:51:27
在这里试试! 测试套件
fΜ‘Ci8iΗi’dpAHdh sH"[ -~] fΜ‘Ci8iΗi’dpAHdh sH"[ -~]
‘ ’ array containing
Ci8 input as base 8
i input as base 10
Ηi input as base 16
Μ d mapped
pAH with from char code
_f d filtered
_sH"[ -~] with strings matching that.发布于 2016-02-16 22:52:29
不确定是否允许使用ascii实用程序。输入作为命令行参数。
ascii $1|tac|grep -Po '(?<=s as `).'ascii可以用sudo apt-get install ascii安装在Ubuntu上。
https://codegolf.stackexchange.com/questions/73329
复制相似问题