Worded Calculator

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite
1












A simplistic version of English numeral calculator



Task



Write a program that takes a string as input and outputs the result of the expression.



Rules



The input string will be worded and not numeral.



There will be no parentheses.



Order of calculation will be divide,multiply,subtract then add.



For same operations, the calculations must be done from left to right.



All input numbers will be integers from -999 to 999 (both inclusive)



Output will be an integer of any range.



Division will always be perfectly divisible and zero will never be a denominator.



Restriction of case for input is optional.



Number Format



0 to 20 -> zero,one,two...nineteen,twenty
21 to 99 -> twenty one,twenty two.....ninety eight,ninety nine
100 to 999 -> one hundred, one hundred one, one hundred two...one hundred ten....two hundred fifty....nine hundred ninety eight,nine hundred ninety nine


For negative numbers: Add minus to its positive equivalent



Operation Format



Addition: one plus two
Subtraction: one minus two
Multiplication: one time two #Note that for one on the left of multiplication, it is one time and not times
two times one hundred
Division: forty divided by two


Examples:



o/p <- input

20 four times five
35 twenty plus fifteen
70 fifty plus five times four
-90 minus one time ninety
25 twenty one minus minus four
45 ninety divided by two
700 one time seven hundred
555 one hundred eleven times two plus three hundred thirty three
99 one hundred plus minus one
45 forty five plus two hundred times zero
4 four
-3 three minus three minus three


This is code-golf so shortest code wins










share|improve this question























  • Ignore my now deleted comment.. The expression is the input, and the number is the output.. I had it the other way around because usually left is input and right is output.
    – Kevin Cruijssen
    1 hour ago






  • 1




    Duplicate? - I think that's close enough to be considered as such.
    – Kirill L.
    1 hour ago







  • 1




    It's very close indeed. But I think this one is better specified and has more reasonable limitations.
    – Arnauld
    1 hour ago










  • @Arnauld I will keep this open then but if others think differently, just mark it as duplicate.
    – Vedant Kandoi
    59 mins ago






  • 1




    I say one times two. Is using time normal?
    – Jo King
    9 mins ago















up vote
1
down vote

favorite
1












A simplistic version of English numeral calculator



Task



Write a program that takes a string as input and outputs the result of the expression.



Rules



The input string will be worded and not numeral.



There will be no parentheses.



Order of calculation will be divide,multiply,subtract then add.



For same operations, the calculations must be done from left to right.



All input numbers will be integers from -999 to 999 (both inclusive)



Output will be an integer of any range.



Division will always be perfectly divisible and zero will never be a denominator.



Restriction of case for input is optional.



Number Format



0 to 20 -> zero,one,two...nineteen,twenty
21 to 99 -> twenty one,twenty two.....ninety eight,ninety nine
100 to 999 -> one hundred, one hundred one, one hundred two...one hundred ten....two hundred fifty....nine hundred ninety eight,nine hundred ninety nine


For negative numbers: Add minus to its positive equivalent



Operation Format



Addition: one plus two
Subtraction: one minus two
Multiplication: one time two #Note that for one on the left of multiplication, it is one time and not times
two times one hundred
Division: forty divided by two


Examples:



o/p <- input

20 four times five
35 twenty plus fifteen
70 fifty plus five times four
-90 minus one time ninety
25 twenty one minus minus four
45 ninety divided by two
700 one time seven hundred
555 one hundred eleven times two plus three hundred thirty three
99 one hundred plus minus one
45 forty five plus two hundred times zero
4 four
-3 three minus three minus three


This is code-golf so shortest code wins










share|improve this question























  • Ignore my now deleted comment.. The expression is the input, and the number is the output.. I had it the other way around because usually left is input and right is output.
    – Kevin Cruijssen
    1 hour ago






  • 1




    Duplicate? - I think that's close enough to be considered as such.
    – Kirill L.
    1 hour ago







  • 1




    It's very close indeed. But I think this one is better specified and has more reasonable limitations.
    – Arnauld
    1 hour ago










  • @Arnauld I will keep this open then but if others think differently, just mark it as duplicate.
    – Vedant Kandoi
    59 mins ago






  • 1




    I say one times two. Is using time normal?
    – Jo King
    9 mins ago













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





A simplistic version of English numeral calculator



Task



Write a program that takes a string as input and outputs the result of the expression.



Rules



The input string will be worded and not numeral.



There will be no parentheses.



Order of calculation will be divide,multiply,subtract then add.



For same operations, the calculations must be done from left to right.



All input numbers will be integers from -999 to 999 (both inclusive)



Output will be an integer of any range.



Division will always be perfectly divisible and zero will never be a denominator.



Restriction of case for input is optional.



Number Format



0 to 20 -> zero,one,two...nineteen,twenty
21 to 99 -> twenty one,twenty two.....ninety eight,ninety nine
100 to 999 -> one hundred, one hundred one, one hundred two...one hundred ten....two hundred fifty....nine hundred ninety eight,nine hundred ninety nine


For negative numbers: Add minus to its positive equivalent



Operation Format



Addition: one plus two
Subtraction: one minus two
Multiplication: one time two #Note that for one on the left of multiplication, it is one time and not times
two times one hundred
Division: forty divided by two


Examples:



o/p <- input

20 four times five
35 twenty plus fifteen
70 fifty plus five times four
-90 minus one time ninety
25 twenty one minus minus four
45 ninety divided by two
700 one time seven hundred
555 one hundred eleven times two plus three hundred thirty three
99 one hundred plus minus one
45 forty five plus two hundred times zero
4 four
-3 three minus three minus three


This is code-golf so shortest code wins










share|improve this question















A simplistic version of English numeral calculator



Task



Write a program that takes a string as input and outputs the result of the expression.



Rules



The input string will be worded and not numeral.



There will be no parentheses.



Order of calculation will be divide,multiply,subtract then add.



For same operations, the calculations must be done from left to right.



All input numbers will be integers from -999 to 999 (both inclusive)



Output will be an integer of any range.



Division will always be perfectly divisible and zero will never be a denominator.



Restriction of case for input is optional.



Number Format



0 to 20 -> zero,one,two...nineteen,twenty
21 to 99 -> twenty one,twenty two.....ninety eight,ninety nine
100 to 999 -> one hundred, one hundred one, one hundred two...one hundred ten....two hundred fifty....nine hundred ninety eight,nine hundred ninety nine


For negative numbers: Add minus to its positive equivalent



Operation Format



Addition: one plus two
Subtraction: one minus two
Multiplication: one time two #Note that for one on the left of multiplication, it is one time and not times
two times one hundred
Division: forty divided by two


Examples:



o/p <- input

20 four times five
35 twenty plus fifteen
70 fifty plus five times four
-90 minus one time ninety
25 twenty one minus minus four
45 ninety divided by two
700 one time seven hundred
555 one hundred eleven times two plus three hundred thirty three
99 one hundred plus minus one
45 forty five plus two hundred times zero
4 four
-3 three minus three minus three


This is code-golf so shortest code wins







code-golf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 42 mins ago

























asked 1 hour ago









Vedant Kandoi

1216




1216











  • Ignore my now deleted comment.. The expression is the input, and the number is the output.. I had it the other way around because usually left is input and right is output.
    – Kevin Cruijssen
    1 hour ago






  • 1




    Duplicate? - I think that's close enough to be considered as such.
    – Kirill L.
    1 hour ago







  • 1




    It's very close indeed. But I think this one is better specified and has more reasonable limitations.
    – Arnauld
    1 hour ago










  • @Arnauld I will keep this open then but if others think differently, just mark it as duplicate.
    – Vedant Kandoi
    59 mins ago






  • 1




    I say one times two. Is using time normal?
    – Jo King
    9 mins ago

















  • Ignore my now deleted comment.. The expression is the input, and the number is the output.. I had it the other way around because usually left is input and right is output.
    – Kevin Cruijssen
    1 hour ago






  • 1




    Duplicate? - I think that's close enough to be considered as such.
    – Kirill L.
    1 hour ago







  • 1




    It's very close indeed. But I think this one is better specified and has more reasonable limitations.
    – Arnauld
    1 hour ago










  • @Arnauld I will keep this open then but if others think differently, just mark it as duplicate.
    – Vedant Kandoi
    59 mins ago






  • 1




    I say one times two. Is using time normal?
    – Jo King
    9 mins ago
















Ignore my now deleted comment.. The expression is the input, and the number is the output.. I had it the other way around because usually left is input and right is output.
– Kevin Cruijssen
1 hour ago




Ignore my now deleted comment.. The expression is the input, and the number is the output.. I had it the other way around because usually left is input and right is output.
– Kevin Cruijssen
1 hour ago




1




1




Duplicate? - I think that's close enough to be considered as such.
– Kirill L.
1 hour ago





Duplicate? - I think that's close enough to be considered as such.
– Kirill L.
1 hour ago





1




1




It's very close indeed. But I think this one is better specified and has more reasonable limitations.
– Arnauld
1 hour ago




It's very close indeed. But I think this one is better specified and has more reasonable limitations.
– Arnauld
1 hour ago












@Arnauld I will keep this open then but if others think differently, just mark it as duplicate.
– Vedant Kandoi
59 mins ago




@Arnauld I will keep this open then but if others think differently, just mark it as duplicate.
– Vedant Kandoi
59 mins ago




1




1




I say one times two. Is using time normal?
– Jo King
9 mins ago





I say one times two. Is using time normal?
– Jo King
9 mins ago











1 Answer
1






active

oldest

votes

















up vote
4
down vote














Python 2, 333 331 330 309 307 bytes





lambda s:eval(''.join([[w and`N(w,0)*100+N(w,2)`,'+-*/'['pmtd'.find(w[:1])]][i%2]for i,w in enumerate(re.split(' *(plus|minus|times?|divided by) ',s))]))
N=lambda x,y:sum(('zeontwthfofisiseeiniteel'.find(w[:2])/2+10*(w[-3:]in'lveen'))*10**('ty'==w[-2:])for w in x.rpartition('hundred')[y].split())
import re


Try it online!






share|improve this answer






















    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "200"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175369%2fworded-calculator%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote














    Python 2, 333 331 330 309 307 bytes





    lambda s:eval(''.join([[w and`N(w,0)*100+N(w,2)`,'+-*/'['pmtd'.find(w[:1])]][i%2]for i,w in enumerate(re.split(' *(plus|minus|times?|divided by) ',s))]))
    N=lambda x,y:sum(('zeontwthfofisiseeiniteel'.find(w[:2])/2+10*(w[-3:]in'lveen'))*10**('ty'==w[-2:])for w in x.rpartition('hundred')[y].split())
    import re


    Try it online!






    share|improve this answer


























      up vote
      4
      down vote














      Python 2, 333 331 330 309 307 bytes





      lambda s:eval(''.join([[w and`N(w,0)*100+N(w,2)`,'+-*/'['pmtd'.find(w[:1])]][i%2]for i,w in enumerate(re.split(' *(plus|minus|times?|divided by) ',s))]))
      N=lambda x,y:sum(('zeontwthfofisiseeiniteel'.find(w[:2])/2+10*(w[-3:]in'lveen'))*10**('ty'==w[-2:])for w in x.rpartition('hundred')[y].split())
      import re


      Try it online!






      share|improve this answer
























        up vote
        4
        down vote










        up vote
        4
        down vote










        Python 2, 333 331 330 309 307 bytes





        lambda s:eval(''.join([[w and`N(w,0)*100+N(w,2)`,'+-*/'['pmtd'.find(w[:1])]][i%2]for i,w in enumerate(re.split(' *(plus|minus|times?|divided by) ',s))]))
        N=lambda x,y:sum(('zeontwthfofisiseeiniteel'.find(w[:2])/2+10*(w[-3:]in'lveen'))*10**('ty'==w[-2:])for w in x.rpartition('hundred')[y].split())
        import re


        Try it online!






        share|improve this answer















        Python 2, 333 331 330 309 307 bytes





        lambda s:eval(''.join([[w and`N(w,0)*100+N(w,2)`,'+-*/'['pmtd'.find(w[:1])]][i%2]for i,w in enumerate(re.split(' *(plus|minus|times?|divided by) ',s))]))
        N=lambda x,y:sum(('zeontwthfofisiseeiniteel'.find(w[:2])/2+10*(w[-3:]in'lveen'))*10**('ty'==w[-2:])for w in x.rpartition('hundred')[y].split())
        import re


        Try it online!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 5 mins ago

























        answered 45 mins ago









        TFeld

        12.9k2836




        12.9k2836



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175369%2fworded-calculator%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery