20
4
Recently I've been writing a new language, to avoid needing to handle order of operations, I simply parenthesize each expression properly to avoid this entirely.
Because parenthesis are at char-codes 40-41, your code will need to be as short as possible.
Examples
1+2*3
(1+(2*3))
2*(3+4)
(2*(3+4))
2*3/4+3
(((2*3)/4)+3)
342*32/8
((342*32)/8)
Rules
The only operations you'll need to handle are: *
(multiplication), /
(division), +
(addition), and -
(subtraction).
- The order of operations is:
- Parenthesis
- Multiplication, Division
- Adition, Subtraction
- You should prefer to go left-right
- The input numbers will always be positive integers (see bonuses)
Bonuses
-20% if you handle negation:
3+-5
(3+(-5))
-5% if you allow spaces to be placed inside the input:
3 + 4
(3+4)
-10% if you can handle decimals in the input:
1+.12
(1+.12)
1+0.21/3
(1+(0.21/3))
500 bounty: if you manage to write an answer in Unnamed/Blocks
And you want us to write the parser for you? :3 – Conor O'Brien – 2015-12-24T21:04:08.940
25"Because parenthesis are at char codes 40-41, your code will need to be as short as possible." OK, now you're just being plain ridiculous. ;P – ETHproductions – 2015-12-24T21:06:10.683
@ETHproductions I'll award a bounty (500?) if anyone manages to do that but I doubt it's possible because currently it can barely add numbers :/ – Downgoat – 2015-12-24T21:07:57.830
Whoops, accidentally deleted my comment. Here it is for reference: "Do we get a bonus for answering in your new language?" – ETHproductions – 2015-12-24T21:09:33.140
3And this is easier than prefix (Polish) notation because? – wizzwizz4 – 2015-12-24T21:12:36.817
3
Possible duplicate.
– flawr – 2015-12-24T22:02:59.4978@flawr I saw that but it's very different in the fact that that question has you output all ways parenthesizing an expression. Here you have to take into account order of operations which I think is a significant difference as code can't be trivially modified for this challenge – Downgoat – 2015-12-24T22:20:02.143
3Important test case:
1+2+3+4
(which certain solutions might parenthesise as((1+2)+(3+4))
) – Martin Ender – 2015-12-24T23:25:12.3631About handling negation:
3 - - - - 6
=>(3+6)
or(3-(-(-(-6))))
? – edc65 – 2015-12-28T15:28:20.123Is it ok to put parenthesis around each number? For example:
((3)+(4))
for3+4
and((1)+((2)*(3)))
for1+2*3
? – agtoever – 2015-12-29T14:01:10.063The first paragraph gives some context, but you seem to have forgotten to give the specification. You've told us what you do: what do you want us to do? What input do we take? What processing do we perform on it? – Peter Taylor – 2015-12-30T09:57:02.483
Where can I find specification for Unnamed? – Akangka – 2016-01-02T05:28:37.463
@ChristianIrwan there's not much documentation but there's an esolangs article here and you can look at the source code of the page and look for the <script> tag for source code. I also have an answer on the site here. One tip is that ` is the input and anything in {} in evaluated as JavaScript that's about all I remember
– Downgoat – 2016-01-02T05:34:28.893@Doᴡɴɢᴏᴀᴛ The esolang article doesn't have specification of command. – Akangka – 2016-01-02T05:42:03.780
I don't read in Javascript. – Akangka – 2016-01-02T05:59:38.250
@ChristianIrwan hmm, sorry about the lack of documentation, I don't even know how the language works anymore but basically
is replaced with the input. This means your code is essentially
1,1::0,0={JS_CODE}|;
0,0essentially sets the first output (Unnamed has 2D output).
1,1sets an output to a 1*1 matrix. the
|` is the Set command. I'll try to write up some more docs tonight, – Downgoat – 2016-01-02T06:02:44.3271The "Unnamed" link does not work. – Erik the Outgolfer – 2016-10-06T08:23:22.750