给定带有ascii艺术运算符和数字的多行字符串,解析表达式!
编号:(3x4)
/
/|
|
---
___
_|
|
---
___
_|
|
---
| |
|_|
|
|
___
|_
|
---
___
|_
| |
---
___
/
/
|
___
|_|
| |
---
___
|_|
|
---
___
| |
| |
---
操作员:(3x3)
|
-+-
|
---
\ /
x
/ \
.
---
.
支架:(1x4)
/
|
|
\
\
|
|
/
带有ascii艺术运算符和数字的多行字符串。测试用例中的示例。
解析表达式的字符串。
输入:
/ ___ ___ \ ___
| _| | / | . _|
| | -+- / | --- |
\ --- | | / . ---
输出:(2+7)/3
输入:
___ / ___
|_| /| \ / |_
| --- | x |
--- --- / \ ---
输出:9-1*5
发布于 2020-05-10 15:48:03
⭆⪪⭆θ§αI⭆⟦θηζε⟧÷⊖℅§λκ³²A℅⁺⁴⁰÷⌕”$⌈O⁴εΦa↙M∕³↧FωG↙σ⎇C(|?⊞¦﹪ω←2I0C⁻sⅉ”ι³
在网上试试!链接是详细的代码版本。假设4个输入字符串长度相等(必要时填充空格)。解释:
θ First input
⭆ Map over characters and join
⟦θηζε⟧ All four inputs as a list
⭆ Map over strings
λ Inner string
§ Indexed by
κ Outer index
℅ Take the ASCII code
⊖ Decrement
÷ ³² Integer divide by literal `32`
I Cast to integer
§α Index into uppercase alphabet
⪪ A Split on literal `A`
⭆ Map over substrings
⌕...ι Find their indices in compressed data
÷ ³ Integer divide by 3
⁺⁴⁰ Plus literal `40`
℅ Convert to ASCII
Implicitly print
压缩数据表示文字字符串GAARAATEYKBKAAAKKKAAAKHKRZRXFBDRNZRRYSFNRDRRDBIURRRNRR
,其中包含计算结果的模式,并填充A
s,将它们放置在适当的偏移位置以生成所需的ASCII字符。
发布于 2020-05-10 16:37:34
f=(s,i=0,a=s.split`
`,c=a[n=0][i],x=1)=>c?"*3-425()6+9/7081"[c=='/'?6:c=='\\'?7:[x=3,4,5,6,9].map(c=>n+=Buffer(a[c/3|0])[i+c%3]*c)|n%47%16]+f(s,i-~x):''
https://codegolf.stackexchange.com/questions/204560
复制相似问题