# Parse ascii art math!

Given a multiline string with ascii art operators and numbers, parse the expression!

# Possible symbols

Numbers: (3x4)

 /
/|
|
---

___
_|
|
---

___
_|
|
---

| |
|_|
|
|

___
|_
|
---

___
|_
| |
---

___
/
/
|

___
|_|
| |
---

___
|_|
|
---

___
| |
| |
---


Operators: (3x3)

 |
-+-
|

---

\ /
x
/ \

.
---
.



Braces: (1x4)

/
|
|
\

\
|
|
/


# Input

A multiline string with ascii art operators and numbers. Examples in the test cases.

# Output

The string of the parsed expression.

# Test cases

Input:


/ ___     ___ \     ___
|  _|  |    / |  .   _|
| |   -+-  /  | ---   |
\ ---  |  |   /  .  ---



Output: (2+7)/3

Input:

___      /      ___
|_|     /|  \ / |_
| ---  |   x    |
---     --- / \ ---



Output: 9-1*5

# Rules

1. Numbers will always be single-digit
2. Since operators are one symbol shorter than numbers, they are placed one symbol lower than numbers, leaving whitespace on top.
3. All symbols have a column of whitespace between them
4. This is a code-golf challenge, so lowest byte count wins!
• May we assume the lines of text are all of the same length (filled with spaces on the right when necessary to do so)? May 10, 2020 at 14:58
• @JonathanAllan yes
– Dion
May 10, 2020 at 15:10
• Would have been funnier to ouput the result :) May 11, 2020 at 11:14
• @OliverGrégoire that was the og post, but it was quickly agreed that evaluating the expression was a useless part
– Dion
May 11, 2020 at 12:29
• @Dion But printing calculated result as ASCII would make evaluation less useless I think? May 11, 2020 at 13:29

# APL (Dyalog Unicode), 46 44 bytes

'/(80-)63+92145*7'[16|43|25⊥¨(×⊆⊢)2⊥' .\'⍳⎕]


Try it online!

⎕ evaluated input, must be a character matrix

' .\'⍳ replace spaces with 0, .s with 1, \s with 2, and everything else with 3

2⊥ base-2 decode the columns

(×⊆⊢) split on zeroes

25⊥¨ base-25 decode each group

16|43| mod 43, mod 16

'/(80-)63+92145*7'[ ] use as indices in the given string

# Python 2, 154 139 bytes

s=zip(*input().split('\n'))
i=0
while s[i:]:d=3**(max((s+[' '])[i+1])>' ')+i;print'+/5(_41_7802*6__-9)3'[hash(tuple(s[i:d]))*3%67%21];i=1+d


Try it online!

# APL (Dyalog Unicode), 69 61 bytes

Anonymous tacit prefix function. Requires ⎕IO←0.

{('+-*/()',⎕D)['∆JV⍺TgucKmre3Ha'⍳⎕AV[94|2⊥¨,⌿⍵⊆⍨∨⌿32≠⍵]]}⎕UCS


Try it online!

⎕UCS convert characters to code points

{} "dfn"; argument is ⍵

('+-*/()',⎕D) the involved symbols followed by the Digits

[] index into that using the following indices:

'∆JV⍺TgucKmre3Ha'⍳ indices in this string (missing elements get index=length) of

⎕AV[] index into the Atomic Vector (the character set) using the following:

94| the division remainder when divided by 94 of

2⊥¨ the base-2 evaluation of each of

,⌿ the vertically joined and flattened

⍵⊆⍨ segments of the argument, as indicated by trues in

∨⌿ the vertical OR-reduction of

32≠⍵ the Boolean mask indicating where the argument is different from 32 (space)

⭆⪪⭆θ§αＩ⭆⟦θηζε⟧÷⊖℅§λκ³²A℅⁺⁴⁰÷⌕”$⌈O⁴εΦa↙M∕³↧ＦωＧ↙σ⎇C(｜？⊞¦﹪ω←2Ｉ0C⁻sⅉ”ι³  Try it online! Link is to verbose version of code. Assumes 4 input strings of equal length (space padded if necessary). Explanation:  θ 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 Ｉ 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  The compressed data represents the literal string GAARAATEYKBKAAAKKKAAAKHKRZRXFBDRNZRRYSFNRDRRDBIURRRNRR which contains the pattens that result from the calculation, padded with As to place them at the appropriate offset to generate the desired ASCII character. # JavaScript (Node.js), 152 bytes 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):''  Try it online! # Jelly, 36 bytes ỴZ⁶=ẠƊ€œp$“¢Ọ/’,“642-*+)9(8/17035”ḥⱮ


A monadic Link accepting a list of characters which yields a list of characters.

Try it online!

### How?

ỴZ⁶=ẠƊ€œp$“¢Ọ/’,“642-*+)9(8/17035”ḥⱮ - Link: list of characters, I Ỵ - split at newline characters Z - transpose$                           - last two links as a monad - i.e. f(X):
⁶                                  -     the space character
=                                 -     equals? (vectorises)
Ạ                                -     all?
œp                            -   split (X) at truthy indices of (that)
-     (...call the result A)
“¢Ọ/’                      - base 250 int = 170548 (salt)
“642-*+)9(8/17035”   - list of characters "642-*+)9(8/17035" (domain)
,                     - pair -> [salt, domain]
Ɱ - map across A with:
ḥ  -   Jelly's hash function with salt and domain


# 05AB1E, 5440 39 bytes

"2(-1 0/ 9 6*)+"Ž´Š«|€SøJð4×¡JÇ2δβŽ4w%è


Can definitely be golfed some more with smarter magical integers (including changing the ā‡ to for example Åβ or changing the order of the charcters in the strings), but I'm pretty bad at those kind of challenges personally, so this will do for now.
-14 bytes thanks to @ovs, because he is skilled in these kind of magic integer challenges. ^_^

Explanation:

"2(-1 0/ 9 6*)+"      # Push this string
Ž´Š   # Push compressed integer 45783
«  # Append it to the string: "2(-1 0/ 9 6*)+45783"
|                     # Push all input-lines as list
€S                   # Convert each line to a list of characters
ø                  # Zip/transpose; swapping rows/columns
J                 # Join each inner list (column) together to a string
ð4×              # Push a string of 4 space characters: "    "
¡             # Split the list on that
J            # Join each inner list of strings to a single string
Ç           # Convert each string to a list of codepoint integers
δ         # For each list of integers:
2 β        #  Convert from a base-2 list to a base-10 integer
Ž4w%    # Modulo-1078 on each value
è                     # And then (modulair 0-based) index them into the string
# (after which the result is output implicitly)


See this 05AB1E tips of mine (section How to compress large integers?) to understand why Ž´Š is 45783 and Ž4w is 1078.

• 40 bytes by using code points and base conversion to convert strings to integers. I haven't tried other bases than 2, so there is probably still something shorter.
– ovs
Sep 23, 2020 at 8:22
• @ovs Thanks! That's indeed a lot better. And in your approach I can remove the map for another -1, since most of the builtins vectorize. Sep 23, 2020 at 8:47