[Question]
  [
**Closed**. This question needs [details or clarity](/help/closed-questions). It is not currently accepting answers.
 
 
---
**Want to improve this question?** Add details and clarify the problem by [editing this post](/posts/189537/edit).
Closed 4 years ago.
[Improve this question](/posts/189537/edit) 
We've all done it, well, maybe not, but making your own alien language and numbering system is a staple of especially fantasy writing, but is mostly just a fun activity.
The task is simple, take two inputs:
1. An ordered list input of 10 [ten] unique 'numerals' (any printable
ASCII character) and interpret them, in order, as the values 0, 1,
2, 3,...,9
+There are exceptions to what can be a numeral here. Arithmetic operators (+, -, \*, /), Parentheses, and spaces cannot be used as one of the numerals.
2. An arithmetic problem using only those 'numerals'
And output the equivalent integer result in the given form.
Here's an example:
```
INPUT
abcdefghij
bcd + efg + hij
```
```
OUTPUT
bdgi
```
In the example, the input list (you may choose which form the list comes in) of 'abcdefghij' corresponds to '0123456789' just as 'hjkloiwdfp' would also correspond 1 to 1 with '0123456789' where instead of 'a' associating with zero, 'h' does. The arithmetic following 'translates' to 123 + 456 + 789, which equals 1368. This must then be outputted in the form we gave it, so b (which represents 1) d (for 2) g (for 6) and i (for 8).
**TEST CASES**
```
abcdefghij
abc + def - ghij
-gedc
```
```
qwertyuiop
qwerty / uiop
e
```
```
%y83l;[=9|
(83l * 9) + 8%
y9|8
```
***MORE RULES***
* [Standard
Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default)
are forbidden!
* This is code golf, so shortest answers in bytes wins.
* Must be a full program or function taking the inputs and outputs in whatever format works best for you. (Just cannot add additioal information in the inputs, just 'numerals' and the expression.
* Use any language you'd like (as long as it complies with other rules)
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~10~~ 9 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
žh‡.Eò¹Åв
```
(Now) outputs as a list of characters.
[Try it online](https://tio.run/##yy9OTMpM/f//6L6MRw0L9VwPbzq083DrhU3//ycmJaekpqVnZGZxAVkK2gpADpAE8gE) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfWVC8aGV/4/uy3jUsFDP9fCmQ@sOt17Y9F/nf3S0UmJSckpqWnpGZpaSjhKQraCtAOQCSZBIrI4CmgogBygH5CvoKqTDlRSWpxaVVJZm5hcAlUA4CvoKYD5YXrXSwjjHOtrWsgYorwFkK2gpWGoCDbJQxWGHlgKI1FVIAdoQCwA).
**Explanation:**
```
  ‡        # Transliterate the second (implicit) input, replacing every character of 
           # the first (implicit) input with:
žh         # The builtin "0123456789"
   .E      # Then evaluate it as Elixir code
     ò     # Round it to the nearest integer
      ¹Åв  # And change it back by using a custom base-conversion with the first input as
           # base (which results in a character list)
           # (after which that result is output implicitly)
```
The new version of 05AB1E is build is build in [Elixir](https://elixir-lang.org/). The `.E` function will call `call_unary(fn x -> {result, _} = Code.eval_string(to_string(x)); result end, a)`, where the [`Code.eval_string` is an Elixir builtin](https://hexdocs.pm/elixir/Code.html#eval_string/3).
Note that the legacy version of 05AB1E won't work for this, because it is build in Python. The numbers with leading 0s won't be evaluated:  
[See all test cases in the legacy version](https://tio.run/##MzBNTDJM/V9Waa@k8KhtkoKSfWVC8aGV/4/uy3jUsFDP9fAmIOvQOiD7v87/6GilxKTklNS09IzMLCUdJSBbQVsByAWSIJFYHQU0FUAOUA7IV9BVSIcrKSxPLSqpLM3MLwAqgXAU9BXAfLC8aqWFcY51tK1lDVBeA8hW0FKw1AQaZKGKww4tBRCpq5ACtCEWAA) (which uses the 10-byte version because the `Åв` builtin is new).
[Answer]
# [R](https://www.r-project.org/), 58 bytes
```
function(d,s,`[`=chartr)'0-9'[d,eval(parse(t=d['0-9',s]))]
```
[Try it online!](https://tio.run/##HchLCoAgEADQqwxtVBqhbZAnESFztA9hodb17bN8L9UAg4QarujKekROmHHUo3KLTSUJ1smeaUJ/252fNmXPiyL9N2YjhKmBN3Zy5MO8rFuDH6CF1yDhL1Ef "R – Try It Online")
Uses character translation `chartr` to swap the digits, `parse`s and `eval`s the expression, and then `chartr`s back to the original digits.
If rounding to nearest integer is required, this is
# [R](https://www.r-project.org/), 65 bytes
```
function(d,s,`[`=chartr)'0-9'[d,round(eval(parse(t=d['0-9',s])))]
```
[Try it online!](https://tio.run/##JYzvCoIwFEe/9xQXQdxqomV/HOWTDMHlNjVEbc5C6N3XWt/u@Z3D1VbBLQarlqE23TggQWZSsaqoW66NxlEa04gJosdlEEi@eI8mrmeJTCGYl2QuMcalVSjg91pI1bTdIyA/gB04hhj8hDcueb6lNuvSjZNL/gAJePY@XPOsv7KCfpxH7oYtUOwe5aEL0v0hO56S8yWn9gs "R – Try It Online")
[Answer]
# T-SQL, 117 bytes
```
DECLARE @ CHAR(99)
SELECT @='SELECT TRANSLATE('+TRANSLATE(e,c,'0123456789')+',''0123456789'','''+c+''')'FROM t
EXEC(@)
```
Line breaks are for readability only.
Input is via a pre-existing table **t** with text columns **c** (characters) and **e** (equation), [per our IO rules](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/5341#5341).
Uses the SQL 2017 function [`TRANSLATE`](https://docs.microsoft.com/en-us/sql/t-sql/functions/translate-transact-sql?view=sql-server-2017) to switch between characters and generate a string that contains not only the equation, but the code to translate back to the original characters:
```
SELECT TRANSLATE(123 + 456 + 789,'0123456789','abcdefghij') 
```
This string is then evaluated using `EXEC()`.
There may be some characters (such as a single quote `'`) that would break this code; I haven't tested all possible ASCII characters.
Per the challenge, I am evaluating the expression as given, subject to how my language interprets those operators. As such, the second test case returns 1 (`w`), and not 2 (`e`), due to integer division.
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 38 bytes
```
{*.trans($_=>^10).EVAL.trans(^10=>$_)}
```
[Try it online!](https://tio.run/##LYtBC4IwAEbP7Vd8hxmbpRVBKDGhQ7fOXYJi1laGqakRw/zta4i39x68StX5xr7MVEPYzg/bWhYNoxeRnFdLHu6Pu8PYnIuEXnhvdVmD5VmhGo4gAZVz0BQdmTTSQDMqOaMpJ72V6fWm9P2RPYlDzOAMAYbw/qq6NZ@srEbEAoN5Jlrn25OIf4Q5go@YuzXy/g "Perl 6 – Try It Online")
I'm not sure how the rounding is supposed to work. If it rounds at the end then I can add `.round` for [+6 bytes](https://tio.run/##LYtBC4IwAEbP7Vd8hxmbpRVBKDGhQ7fOXYJippZhalOJYf72NcTbe@/jq1NV7MxbzzMI07t@q2TZMHoT0XWz5v7xfDj5qurKZFpsFRG98cFklQIr8jJtOLwIVC5BY/Rk1kiNjFHJGY05GYyM70maPZ75i1jEAtbgYQyfb6pa3eVVPSFWGM3RwbbYX0T4I8wSXITcXgPnDw). If the behaviour of `/` should be different then it may be longer. Takes input curried like `f(arithmetic)(numerals)(arithmetic)`.
### Explanation:
```
{                                    }  # Anonymous codeblock
 *                                      # Returning a whatever lambda
  .trans($_=>^10)       # That translates the numerals to digits
                 .EVAL  # Evaluates the result as code
                      .trans(^10=>$_)   # And translates it back again
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~74~~ ~~66~~ 65 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
┼ö8Q#xóπcM~oÖ÷╦├mî☼yº─▐4ç≥e╘o▄ê‼ø_k╜ø8%N╫ ╗e<.╗P[─╛èA±!xêj«w╠°{B♪
```
[Run and debug it](https://staxlang.xyz/#p=c59438512378a2e3634d7e6f99f6cbc36d8c0f79a7c4de3487f265d46fdc8813005f6bbd0038254ed720bb653c2ebb505bc4be8a41f12178886aae77ccf87b420d&i=abcdefghij%0Abcd+%2B+efg+%2B+hij%0A%0Aqwertyuiop%0Aqwerty+%2F+uiop%0A%0A%25y83l%3B[%3D9%7C%0A%2883l+*+9%29+%2B+8%25&a=1&m=1)
Stax does not do well here, lacking a true "eval" instruction. It has one that's called "eval" in the docs, but it only works on literal values, not full expressions.
[Answer]
# Bash, 97 bytes
```
IFS=''
read S
read O
A=`echo "$O"|tr "$S" 0-9`
printf %0.f `bc<<<"(${A[@]##0})+0.5"`|tr 0-9 "$S"
```
Could be less if we could truncate, rather than round. Also tricky to handle leading zeroes (as in test case #2) since Bash interprets numbers starting with 0 as octal.
[Answer]
# [Bean](https://github.com/patrickroberts/bean), ~~94~~ 90 bytes
### Hexdump
```
00000000: 53d0 80d6 d800 d3d0 80a0 1f20 8047 53a0  SÐ.ÖØ.ÓÐ. . .GS 
00000010: 1753 d080 d3d0 80a0 5e20 800a a181 8100  .SÐ.ÓÐ. ^ ..¡...
00000020: 40a0 5f52 cac3 4da0 6580 53d0 80a0 5d20  @ _RÊÃM e.SÐ. ] 
00000030: 8089 205f a065 205f 2080 0aa1 8181 0123  .. _ e _ ..¡...#
00000040: 0058 0020 800a a181 8102 40a0 6550 84a0  .X. ..¡...@ eP. 
00000050: 5d20 652e dce2 b02b dc64                 ] e.Üâ°+Üd
```
### JavaScript
```
`${Math.round(
  eval(
    b.replace(
      /./g,
      c => ~(i = a.indexOf(c)) ? i : c
    ).replace(
      /\b0+/g,
      ''
    )
  )
)}`.replace(
  /\d/g,
  i => a[i]
)
```
## Explanation
This program implicitly assigns the first and second lines of input as strings to the variables `a` and `b` respectively.
Each character `c` on line `b` is replaced with the respective index `i` of the character found on line `a`, or itself if it is not found.
Then it removes each sequence of one or more `0`s preceded by a boundary from the resulting string. This is to prevent `eval()` from evaluating any sequence of digits starting with `0` as an octal literal.
After `eval()` and `Math.round()`, the result is coerced back into a string and each digit character `i` is replaced by the corresponding character from line `a` at index `i`.
## Test Cases
[Demo](https://patrickroberts.github.io/bean/#h=U9CA1tgA09CAoB8ggEdToBdT0IDT0ICgXiCACqGBgQBAoF9SysNNoGWAU9CAoF0ggIkgX6BlIF8ggAqhgYEBIwBYACCACqGBgQJAoGVQhKBdIGUu3OKwK9xk&i=YWJjZGVmZ2hpagphYmNkICsgZWZnICsgaGlq)
```
abcdefghij
abcd + efg + hij
bdgi
```
[Demo](https://patrickroberts.github.io/bean#h=U9CA1tgA09CAoB8ggEdToBdT0IDT0ICgXiCACqGBgQBAoF9SysNNoGWAU9CAoF0ggIkgX6BlIF8ggAqhgYEBIwBYACCACqGBgQJAoGVQhKBdIGUu3OKwK9xk&i=YWJjZGVmZ2hpagphYmMgKyBkZWYgLSBnaGlq)
```
abcdefghij
abc + def - ghij
-gedc
```
[Demo](https://patrickroberts.github.io/bean#h=U9CA1tgA09CAoB8ggEdToBdT0IDT0ICgXiCACqGBgQBAoF9SysNNoGWAU9CAoF0ggIkgX6BlIF8ggAqhgYEBIwBYACCACqGBgQJAoGVQhKBdIGUu3OKwK9xk&i=cXdlcnR5dWlvcApxd2VydHkgLyB1aW9w)
```
qwertyuiop
qwerty / uiop
e
```
[Demo](https://patrickroberts.github.io/bean#h=U9CA1tgA09CAoB8ggEdToBdT0IDT0ICgXiCACqGBgQBAoF9SysNNoGWAU9CAoF0ggIkgX6BlIF8ggAqhgYEBIwBYACCACqGBgQJAoGVQhKBdIGUu3OKwK9xk&i=JXk4M2w7Wz05fAooODNsICogOSkgKyA4JQ)
```
%y83l;[=9|
(83l * 9) + 8%
y9|8
```
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 63 bytes
```
$p=<>;eval"y/$p/0-9/";s/\b0+\B//g;$_=int.5+eval;eval"y/0-9/$p/"
```
[Try it online!](https://tio.run/##K0gtyjH9/1@lwNbGzjq1LDFHqVJfpUDfQNdSX8m6WD8myUA7xklfP91aJd42M69Ez1QbpAimEqQMqFrp///C8tSikkoFfYXSzPwCLggPzNSwMM5R0FKw1FTQVrBQ5VKtBPKto20ta/7lF5Rk5ucV/9ctyAEA "Perl 5 – Try It Online")
Takes the expression on the first line of input and the translation list on the second.
[Answer]
# [Perl 5](https://www.perl.org/), 130 bytes
```
sub f{eval sprintf"'%.0f'=~y/%s/%s/r",eval(eval(sprintf"\$_[1]=~y/%s/%s/r",@r=map"\Q$_",$_[0],'0123456789')=~s,\b0,,gr),reverse@r}
```
[Try it online!](https://tio.run/##VYxNb4JAEIbv@ysmFAJb14q1tiDFaNJrD028qSEgA24Dut1FDfHjr9MF00Mnk8kzeT8EymLcNOqQQHbGY1yAEpLvqsywrSc3s8NbPbBUu9Jgre5058@0MqPlcP3PNJNhGQtj9WVGBtOyu2a2O3wevYxf3zzfpuFNsVXiMpZLyiQeUSqcyWtzUAgLVNVk8rmXCJVGFU5HATlteYHO@8d8MZ/SMwE9Ze2YKTMFM2MaKlHwKoCHlOe8UiDkPimwhHinTig7O1cOZPcEZWDGQANyJVHUVkYRiZNNilm@5d@gsae53z39HNMN@dEtVX3gewF3HHSMxKq9UREsQ/8CjqZHn/Y8C2r/4jW/ "Perl 5 – Try It Online")
Maybe that double eval somehow can be turned into `s/.../.../geer`.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 14 bytes
```
⍘ＵＶ⭆η⎇№θι⌕θιιθ
```
[Try it online!](https://tio.run/##NYtBCsIwEEX3nmKWM5iewF1Fd0JBLzCmsRkJiY1poaefDoibz3sPvo9cfeGkOlTJDXv@hnsznHDYWiz5snJauAX81Rt/MDp4hJq5bngui51mB0IOrpLHPwuR7Ux0UuWnH8NrivI@GMERTKADc@3WtAM "Charcoal – Try It Online") Link is to verbose version of code. Note: Expression is evaluated according to Python 3 semantics, so for instance leading zeros on non-zero numbers are illegal. Explanation:
```
   ⭆η           Map over expression's characters and join
        ι       Current character
      №θ        Count matches in first input
     ⎇          If non-zero
         ⌕θι    Replace with position in first input
            ι   Otherwise keep character unchanged
 ＵＶ             Evaluate as Python 3
⍘            θ  Convert to base using first input as digits
```
[Answer]
# [Python 3](https://docs.python.org/3/), 137 bytes
A non-regex approach using `str.translate` and `str.maketrans` to replace the characters. I lost a lot of characters on trimming the leading zeros...
```
lambda s,t,d='0123456789',e=str.translate,m=str.maketrans:e(str(round(eval(' '.join(c.lstrip('0')for c in e(t,m(s,d)).split())))),m(d,s))
```
[Try it online!](https://tio.run/##RY3dTsMwDEbv9xSWqikOZGVQflpQnwRussbdMtKkJBmo0t69eJ0E35XP52N5nPIh@Gru24/Z6WFnNCSVlWnF9v6henx6fqkboahNOZY5ap@czqSGhQf9SUv3SsiMMZy8QfrWDgWI8hisx650vLIjiq2QfYjQgfVAmNWASRkpyzQ6m1Fewp1RScp5jNZn7FHoXWeo3x/sUagLwC0wwwaWSkooYLMn063@Lr5@KObpZMPIF1eAO1iYdU4B9G@vp7pyb@9tc2YbeYYbaCR/qddXvYCpOdfz6hc "Python 3 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 167 bytes
```
import re
a=[*enumerate(input())]
e=input()
for i,c in a:e=re.sub(c,str(i),e)
e=str(round(eval(re.sub(r'\b0+(?!\b)','',e))))
for i,c in a:e=re.sub(str(i),c,e)
print(e)
```
[Try it online!](https://tio.run/##dYxBDsIgEEX3nGJcMVg0Ju5MGg9iXQCdWowCmYKJp0eadOus3vy8vPTNcwznWv07Rc7AJEx/21Mob2KTCX1IJaNSd0H9xmKKDF478AHMhXqm41IsOr1kRq80qeauzLGEEeljXrg5LAd76vC6G6ySWsrmtvsT3HJuDSb2ISOpWo11I02P2T9FQ@igfXCAdfgB "Python 3 – Try It Online")
Room for improvement...
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 121 bytes
I define a pure function with two arguments. Since some functions are repeated I save them in a variable to save a few characters. This code simply does some string replacements and then uses `ToExpression` to evaluate the expression with the Wolfram kernel.
```
(r=Thread[StringPartition[#,1]->(t=ToString)/@Range[0,9]];u[(u=StringReplace)[#2,r]//ToExpression//Round//t,Reverse/@r])&
```
[Try it online!](https://tio.run/##VY3LbsIwEEX3fIUFokqK0fSxIUJGbMoapdlZXrjJNDGCOJ1M2iL1312HSJW6vOeeO3Ox3ODFsittOKiQkCoaQlvpVybX1kdL7Nj5Vi/ko1nvElaFn6oU9rlta9QPMjNmO@hkUFOTY3e2JaZ68STJABT@5bsj7Pt4ByD3Q1sBsMzxE6lH2JNJ78IxLlkf9Ny@lRW@1407zaUYk1iJCMRa3Fh8NftzP76Q@Do4343ulASIG/gnLq@b5/NWq@xnFJMY7rN0tVmOVpiFXw "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Lua](https://www.lua.org), ~~162~~ ~~151~~ 150 bytes
* -11 bytes thanks to my idea of using `load` instead of `function(...) end`
* -1 byte by omitting newline
```
l,p=...print(((math.ceil(load('return '..p:gsub('.',load'n=l:find(...,1,1)return n and n-1'))()-0.5)..''):gsub('%d',load'c=...+1 return l:sub(c,c)')))
```
[Try it online!](https://tio.run/##LY1BbsMgEEX3OcVsrGEaoLWqSokrn6MLKwuCcUJFgWKsKlLv7oLr5f//vRm3qFUI@EgqRpNAzTAtXmcbPOQA2cz54IJWDqbeBTUOw@p47KWUMVmfGWNfKt@lNtaxujNMJi/JAxaiu83LlaFEXif0vesm60dWbN7ylnbUg/IjeNEiESPxIt9ISkTa9WbcfV3fHlvYNdfVWXNNxaP1cjlMDNVVj2a63e0ncqgJjlAKELB1VJnvH5PyY7EhVuY/wTNsxQY0j9Orex/6828FWAnwBGcqp04N0voH "Lua – Try It Online")
Not shortest thing in the world (Lua forces you to be fancy quite hard, especially by huge keywords), but was pretty fun to create. Full program taking input as arguments and printing result.
## Explanation
### Introduction
```
l,p=...
```
Assign values from arguments to variables. Our dictionary is `l` and expression is `p`.
Following expression is quite hard to understand because it have a weird order of execution, so I'll explain it step-by-step:
### Converting to normal numbers
```
p:gsub('.',
load'n=l:find(...,1,1)return n and n-1')
```
Perform replacement on expression string: take each symbol and pass it to function (`load` proved itself to be shorted than normal declaration here).
Function finds position of occurrence in dict string for passed symbol using `find`. `...` is first (and only) argument here as we're in vaarg function (any `load`ed one is) that is our current symbol. Following arguments are required to make `find` ignore special symbols (`1` is just short value which evaluates as `true` when converted to boolean): starting position (one is default here) and `plain`, which actually disables pattern handling. Without those program fails on third test case due to `%` being special.
If match is found, subtract one as Lua strings (and arrays btw) are 1-based. If no match is found, it will return nothing, resulting in no replacement being done.
### Solving
```
math.ceil(load('return '..ABOVE)()-0.5)
```
Prepend `return` to our expression to let it return result, calculate it by compiling as Lua function and calling it, perform rounding ([this](https://stackoverflow.com/a/18313481/5697743) turned other way around to make it shorter).
It the end we get a numerical solution to our problem, only converting it back remains.
### Making it crazy again
```
(ABOVE..'')
:gsub('%d',load'c=...+1 return l:sub(c,c)')
```
First line is a short way to convert number to string, so now we can call string methods in a short way. Let's do so!
Now `gsub` is called again to replace everything back to insanity. This time `%d` is used instead of `.` as replacement pattern as our function may and must process only numbers (`.` would result to error on negative numbers). This time function (`load`ed again to save bytes) first adds `1` to its first (and only) vaargument, converting it to position in dict string, then returns character from it at that position.
Hooray, almost there!
### Dramatic finale, or Why Brackets Matter
```
print((ABOVE))
```
Well… why two pairs of brackets anyways? It's time to talk about parall… eh, multiple return in Lua. Thing is that one function may return few values from one call (look at [this meta question](https://codegolf.meta.stackexchange.com/q/17950/59169) for more examples).
Here, last `gsub` returned two values: answer string we need and amount of replacements done (count of digits actually, but who cares). If it wasn't for internal pair, both string and number would be printed, screwing us up. So here we sacrifice two bytes to omit second result and finally print product of this insanity factory.
---
Well, I've enjoyed explaining almost as much as golfing in first place, hope you got what's going on here.
]