What is 6÷2×(1+2) =?Convert from Infix Notation to Prefix Notation(Somewhat) Pedantic Birthday...

Why is working on the same position for more than 15 years not a red flag?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

What is 6÷2×(1+2) =?

How to limit sight distance to 1 km

Difference between `vector<int> v;` and `vector<int> v = vector<int>();`

Writing a character who is going through a civilizing process without overdoing it?

Can I string the D&D Starter Set campaign into another module, keeping the same characters?

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Explain the objections to these measures against human trafficking

Roman Numerals equation 1

Word or phrase for showing great skill at something WITHOUT formal training in it

Can a person refuse a presidential pardon?

Advice for a new journal editor

Why would the Pakistan airspace closure cancel flights not headed to Pakistan itself?

Would a National Army of mercenaries be a feasible idea?

Find some digits of factorial 17

Why exactly do action photographers need high fps burst cameras?

What is the lore-based reason that the Spectator has the Create Food and Water trait, instead of simply not requiring food and water?

Eww, those bytes are gross

Can making a creature unable to attack after it has been assigned as an attacker remove it from combat?

Why has the mole been redefined for 2019?

How long is the D&D Starter Set campaign?

Why do no American passenger airlines still operate dedicated cargo flights?

Caruana vs Carlsen game 10 (WCC) why not 18...Nxb6?



What is 6÷2×(1+2) =?


Convert from Infix Notation to Prefix Notation(Somewhat) Pedantic Birthday ParadoxVerify the birth numberWeapons of Math InstructionPlay scrabble with the periodic tableArbitrary PEMDASInteger-Digits of the Arithmetic-TablesCreate an omnifix calculatorGet the century of a yearMissing numbers in arithmetic sum













21












$begingroup$


Feel free to skip this introduction and go to the challenge part, if you don't care about the background and inspiration of this challenge.



Introduction:



Inspired by a discussion that is already going on for many years regarding the expression $6÷2(1+2)$.



Irrelevant part for this challenge, but still interesting to know:




With the expression $6÷2(1+2)$, mathematicians will quickly see that the correct answer is $1$, whereas people with a simple math background from school will quickly see that the correct answer is $9$. So where does this controversy and therefore different answers come from? There are two conflicting rules in how $6÷2(1+2)$ is written. One due to the part 2(, and one due to the division symbol ÷.


Although both mathematicians and 'ordinary people' will use PEMDAS (Parenthesis - Exponents - Division/Multiplication - Addition/Subtraction), for mathematicians the expression is evaluated like this below, because $2(3)$ is just like for example $2x^2$ a monomial a.k.a. "a single term due to implied multiplication by juxtaposition" (and therefore part of the P in PEMDAS), which will be evaluated differently than $2×(3)$ (a binomial a.k.a. two terms):

$$6÷2(1+2) → frac{6}{2(3)} → frac{6}{6} → 1$$


Whereas for 'ordinary people', $2(3)$ and $2×(3)$ will be the same (and therefore part of the MD in PEMDAS), so they'll use this instead:

$$6÷2(1+2) → 6/2×(1+2) → 6/2×3 → 3×3 → 9$$




However, even if we would have written the original expression as $6÷2×(1+2)$, there can still be some controversy due to the use of the division symbol ÷. In modern mathematics, the / and ÷ symbols have the exact same meaning: divide. Some rules pre-1918 regarding the division symbol ÷†† state that it had a different meaning than the division symbol /. This is because ÷ used to mean "divide the number/expression on the left with the number/expression on the right"†††. So $a ÷ b$ then, would be $(a) / (b)$ or $frac{a}{b}$ now. In which case $6÷2×(1+2)$ would be evaluated like this by people pre-1918:



$$6÷2×(1+2) → frac{6}{2×(1+2)} → frac{6}{2×3} → frac{6}{6} → 1$$



†: Although I have found multiple sources explaining how ÷ was used in the past (see ††† below), I haven't been able to find definitive prove this changed somewhere around 1918. But for the sake of this challenge we assume 1918 was the turning point where ÷ and / starting to mean the same thing, where they differed in the past.
††: Other symbols have also been used in the past for division, like : in 1633 (or now still in The Netherlands and other European non-English speaking countries, since this is what I've personally learned in primary school xD) or ) in the 1540s. But for this challenge we only focus on the pre-1918 meaning of the obelus symbol ÷.
†††: Sources: this article in general. And the pre-1918 rules regarding ÷ are mentioned in: this The American Mathematical Monthly article from February 1917; this German Teutsche Algebra book from 1659 page 9 and page 76; this A First Book in Algebra from 1895 page 46 [48/189].



Slightly off-topic: regarding the actual discussion about this expression: It should never be written like this in the first place! The correct answer is irrelevant, if the question is unclear. *Clicks the "close because it's unclear what you're asking" button*.

And for the record, even different versions of Casio calculators don't know how to properly deal with this expression:
enter image description here



Challenge:



You are given two inputs:




  • A (valid) mathematical expression consisting only of the symbols 0123456789+-×/÷()

  • A year


And you output the result of the mathematical expression, based on the year (where ÷ is used differently when $year<1918$, but is used exactly the same as / when $yearge1918$).



Challenge rules:




  • You can assume the mathematical expression is valid and only uses the symbols 0123456789+-×/÷(). This also means you won't have to deal with exponentiation. (You are also allowed to use a different symbols for × or ÷ (i.e. * or %), if it helps the golfing or if your language only supports ASCII.)

  • You are allowed to add space-delimiters to the input-expression if this helps the (perhaps manual) evaluation of the expression.

  • I/O is flexible. Input can be as a string, character-array, etc. Year can be as an integer, date-object, string, etc. Output will be a decimal number.

  • You can assume there won't be any division by 0 test cases.

  • You can assume the numbers in the input-expression will be non-negative (so you won't have to deal with differentiating the - as negative symbol vs - as subtraction symbol). The output can however still be negative!

  • You can assume N( will always be written as N×( instead. We'll only focus on the second controversy of the division symbols / vs ÷ in this challenge.

  • Decimal output-values should have a precision of at least three decimal digits.

  • If the input-expression contains multiple ÷ (i.e. $4÷2÷2$) with $year<1918$, they are evaluated like this: $4÷2÷2 → frac{4}{frac{2}{2}} → frac{4}{1} → 4$. (Or in words: number $4$ is divided by expression $2 ÷2$, where expression $2 ÷2$ in turn means number $2$ is divided by number $2$.)

  • Note that the way ÷ works implicitly means it has operator precedence over × and / (see test case $4÷2×2÷3$).

  • You can assume the input-year is within the range $[0000, 9999]$.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input-expression:   Input-year:   Output:      Expression interpretation with parenthesis:

6÷2×(1+2) 2018 9 (6/2)×(1+2)
6÷2×(1+2) 1917 1 6/(2×(1+2))
9+6÷3-3+15/3 2000 13 ((9+(6/3))-3)+(15/3)
9+6÷3-3+15/3 1800 3 (9+6)/((3-3)+(15/3))
4÷2÷2 1918 1 (4/2)/2
4÷2÷2 1900 4 4/(2/2)
(1÷6-3)×5÷2/2 2400 -3.541... ((((1/6)-3)×5)/2)/2
(1÷6-3)×5÷2/2 1400 1.666... ((1/(6-3))×5)/(2/2)
1×2÷5×5-15 2015 -13 (((1×2)/5)×5)-15
1×2÷5×5-15 1719 0.2 (1×2)/((5×5)-15)
10/2+3×7 1991 26 (10/2)+(3×7)
10/2+3×7 1911 26 (10/2)+(3×7)
10÷2+3×7 1991 26 (10/2)+(3×7)
10÷2+3×7 1911 0.434... 10/(2+(3×7))
4÷2+2÷2 2000 3 (4/2)+(2/2)
4÷2+2÷2 1900 2 4/((2+2)/2)
4÷2×2÷3 9999 1.333... ((4/2)×2)/3
4÷2×2÷3 0000 3 4/((2×2)/3)
((10÷2)÷2)+3÷7 2000 2.928... ((10/2)/2)+(3/7)
((10÷2)÷2)+3÷7 1900 0.785... (((10/2)/2)+3)/7
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1920 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1750 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
10÷2/2+4 2000 6.5 ((10/2)/2)+4
10÷2/2+4 0100 2 10/((2/2)+4)









share|improve this question











$endgroup$








  • 10




    $begingroup$
    You know, I really don't like the PEMDAS acronym, because at first glance, it appears to imply that Multiplication comes before Division and Addition comes before Subtraction...
    $endgroup$
    – Jo King
    22 hours ago








  • 1




    $begingroup$
    Since the issue of N( is irrelevant for this challenge, it just confuses matters. Even your title is misleading. Remove all mention of that!
    $endgroup$
    – Adám
    22 hours ago








  • 3




    $begingroup$
    -1, no freehand circles :((
    $endgroup$
    – Don't be a x-triple dot
    22 hours ago








  • 10




    $begingroup$
    So, first you divide people into "real mathematicians", who know the "real" meaning of ÷, and "ordinary people", then you mention that this "real" meaning is actually archaic, and not used since 1918. As a person with a mathematical background, born slightly after 1918 I think the only purpose of the part under spoiler is to try to feel superior to others with no real reason to. A nice Code Golf question though.
    $endgroup$
    – FreeNickname
    20 hours ago






  • 5




    $begingroup$
    I'm not sure if any "mathematician uses PEMDAS". I mean, it's really just an acronym to learn the order, which most people outgrow at some point. I'm not a mathematician myself, but it took me considerable effort to recall the mnemonic in my native language, while I have absolutely no problems applying operations in the correct order...
    $endgroup$
    – Jasper
    14 hours ago
















21












$begingroup$


Feel free to skip this introduction and go to the challenge part, if you don't care about the background and inspiration of this challenge.



Introduction:



Inspired by a discussion that is already going on for many years regarding the expression $6÷2(1+2)$.



Irrelevant part for this challenge, but still interesting to know:




With the expression $6÷2(1+2)$, mathematicians will quickly see that the correct answer is $1$, whereas people with a simple math background from school will quickly see that the correct answer is $9$. So where does this controversy and therefore different answers come from? There are two conflicting rules in how $6÷2(1+2)$ is written. One due to the part 2(, and one due to the division symbol ÷.


Although both mathematicians and 'ordinary people' will use PEMDAS (Parenthesis - Exponents - Division/Multiplication - Addition/Subtraction), for mathematicians the expression is evaluated like this below, because $2(3)$ is just like for example $2x^2$ a monomial a.k.a. "a single term due to implied multiplication by juxtaposition" (and therefore part of the P in PEMDAS), which will be evaluated differently than $2×(3)$ (a binomial a.k.a. two terms):

$$6÷2(1+2) → frac{6}{2(3)} → frac{6}{6} → 1$$


Whereas for 'ordinary people', $2(3)$ and $2×(3)$ will be the same (and therefore part of the MD in PEMDAS), so they'll use this instead:

$$6÷2(1+2) → 6/2×(1+2) → 6/2×3 → 3×3 → 9$$




However, even if we would have written the original expression as $6÷2×(1+2)$, there can still be some controversy due to the use of the division symbol ÷. In modern mathematics, the / and ÷ symbols have the exact same meaning: divide. Some rules pre-1918 regarding the division symbol ÷†† state that it had a different meaning than the division symbol /. This is because ÷ used to mean "divide the number/expression on the left with the number/expression on the right"†††. So $a ÷ b$ then, would be $(a) / (b)$ or $frac{a}{b}$ now. In which case $6÷2×(1+2)$ would be evaluated like this by people pre-1918:



$$6÷2×(1+2) → frac{6}{2×(1+2)} → frac{6}{2×3} → frac{6}{6} → 1$$



†: Although I have found multiple sources explaining how ÷ was used in the past (see ††† below), I haven't been able to find definitive prove this changed somewhere around 1918. But for the sake of this challenge we assume 1918 was the turning point where ÷ and / starting to mean the same thing, where they differed in the past.
††: Other symbols have also been used in the past for division, like : in 1633 (or now still in The Netherlands and other European non-English speaking countries, since this is what I've personally learned in primary school xD) or ) in the 1540s. But for this challenge we only focus on the pre-1918 meaning of the obelus symbol ÷.
†††: Sources: this article in general. And the pre-1918 rules regarding ÷ are mentioned in: this The American Mathematical Monthly article from February 1917; this German Teutsche Algebra book from 1659 page 9 and page 76; this A First Book in Algebra from 1895 page 46 [48/189].



Slightly off-topic: regarding the actual discussion about this expression: It should never be written like this in the first place! The correct answer is irrelevant, if the question is unclear. *Clicks the "close because it's unclear what you're asking" button*.

And for the record, even different versions of Casio calculators don't know how to properly deal with this expression:
enter image description here



Challenge:



You are given two inputs:




  • A (valid) mathematical expression consisting only of the symbols 0123456789+-×/÷()

  • A year


And you output the result of the mathematical expression, based on the year (where ÷ is used differently when $year<1918$, but is used exactly the same as / when $yearge1918$).



Challenge rules:




  • You can assume the mathematical expression is valid and only uses the symbols 0123456789+-×/÷(). This also means you won't have to deal with exponentiation. (You are also allowed to use a different symbols for × or ÷ (i.e. * or %), if it helps the golfing or if your language only supports ASCII.)

  • You are allowed to add space-delimiters to the input-expression if this helps the (perhaps manual) evaluation of the expression.

  • I/O is flexible. Input can be as a string, character-array, etc. Year can be as an integer, date-object, string, etc. Output will be a decimal number.

  • You can assume there won't be any division by 0 test cases.

  • You can assume the numbers in the input-expression will be non-negative (so you won't have to deal with differentiating the - as negative symbol vs - as subtraction symbol). The output can however still be negative!

  • You can assume N( will always be written as N×( instead. We'll only focus on the second controversy of the division symbols / vs ÷ in this challenge.

  • Decimal output-values should have a precision of at least three decimal digits.

  • If the input-expression contains multiple ÷ (i.e. $4÷2÷2$) with $year<1918$, they are evaluated like this: $4÷2÷2 → frac{4}{frac{2}{2}} → frac{4}{1} → 4$. (Or in words: number $4$ is divided by expression $2 ÷2$, where expression $2 ÷2$ in turn means number $2$ is divided by number $2$.)

  • Note that the way ÷ works implicitly means it has operator precedence over × and / (see test case $4÷2×2÷3$).

  • You can assume the input-year is within the range $[0000, 9999]$.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input-expression:   Input-year:   Output:      Expression interpretation with parenthesis:

6÷2×(1+2) 2018 9 (6/2)×(1+2)
6÷2×(1+2) 1917 1 6/(2×(1+2))
9+6÷3-3+15/3 2000 13 ((9+(6/3))-3)+(15/3)
9+6÷3-3+15/3 1800 3 (9+6)/((3-3)+(15/3))
4÷2÷2 1918 1 (4/2)/2
4÷2÷2 1900 4 4/(2/2)
(1÷6-3)×5÷2/2 2400 -3.541... ((((1/6)-3)×5)/2)/2
(1÷6-3)×5÷2/2 1400 1.666... ((1/(6-3))×5)/(2/2)
1×2÷5×5-15 2015 -13 (((1×2)/5)×5)-15
1×2÷5×5-15 1719 0.2 (1×2)/((5×5)-15)
10/2+3×7 1991 26 (10/2)+(3×7)
10/2+3×7 1911 26 (10/2)+(3×7)
10÷2+3×7 1991 26 (10/2)+(3×7)
10÷2+3×7 1911 0.434... 10/(2+(3×7))
4÷2+2÷2 2000 3 (4/2)+(2/2)
4÷2+2÷2 1900 2 4/((2+2)/2)
4÷2×2÷3 9999 1.333... ((4/2)×2)/3
4÷2×2÷3 0000 3 4/((2×2)/3)
((10÷2)÷2)+3÷7 2000 2.928... ((10/2)/2)+(3/7)
((10÷2)÷2)+3÷7 1900 0.785... (((10/2)/2)+3)/7
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1920 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1750 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
10÷2/2+4 2000 6.5 ((10/2)/2)+4
10÷2/2+4 0100 2 10/((2/2)+4)









share|improve this question











$endgroup$








  • 10




    $begingroup$
    You know, I really don't like the PEMDAS acronym, because at first glance, it appears to imply that Multiplication comes before Division and Addition comes before Subtraction...
    $endgroup$
    – Jo King
    22 hours ago








  • 1




    $begingroup$
    Since the issue of N( is irrelevant for this challenge, it just confuses matters. Even your title is misleading. Remove all mention of that!
    $endgroup$
    – Adám
    22 hours ago








  • 3




    $begingroup$
    -1, no freehand circles :((
    $endgroup$
    – Don't be a x-triple dot
    22 hours ago








  • 10




    $begingroup$
    So, first you divide people into "real mathematicians", who know the "real" meaning of ÷, and "ordinary people", then you mention that this "real" meaning is actually archaic, and not used since 1918. As a person with a mathematical background, born slightly after 1918 I think the only purpose of the part under spoiler is to try to feel superior to others with no real reason to. A nice Code Golf question though.
    $endgroup$
    – FreeNickname
    20 hours ago






  • 5




    $begingroup$
    I'm not sure if any "mathematician uses PEMDAS". I mean, it's really just an acronym to learn the order, which most people outgrow at some point. I'm not a mathematician myself, but it took me considerable effort to recall the mnemonic in my native language, while I have absolutely no problems applying operations in the correct order...
    $endgroup$
    – Jasper
    14 hours ago














21












21








21


6



$begingroup$


Feel free to skip this introduction and go to the challenge part, if you don't care about the background and inspiration of this challenge.



Introduction:



Inspired by a discussion that is already going on for many years regarding the expression $6÷2(1+2)$.



Irrelevant part for this challenge, but still interesting to know:




With the expression $6÷2(1+2)$, mathematicians will quickly see that the correct answer is $1$, whereas people with a simple math background from school will quickly see that the correct answer is $9$. So where does this controversy and therefore different answers come from? There are two conflicting rules in how $6÷2(1+2)$ is written. One due to the part 2(, and one due to the division symbol ÷.


Although both mathematicians and 'ordinary people' will use PEMDAS (Parenthesis - Exponents - Division/Multiplication - Addition/Subtraction), for mathematicians the expression is evaluated like this below, because $2(3)$ is just like for example $2x^2$ a monomial a.k.a. "a single term due to implied multiplication by juxtaposition" (and therefore part of the P in PEMDAS), which will be evaluated differently than $2×(3)$ (a binomial a.k.a. two terms):

$$6÷2(1+2) → frac{6}{2(3)} → frac{6}{6} → 1$$


Whereas for 'ordinary people', $2(3)$ and $2×(3)$ will be the same (and therefore part of the MD in PEMDAS), so they'll use this instead:

$$6÷2(1+2) → 6/2×(1+2) → 6/2×3 → 3×3 → 9$$




However, even if we would have written the original expression as $6÷2×(1+2)$, there can still be some controversy due to the use of the division symbol ÷. In modern mathematics, the / and ÷ symbols have the exact same meaning: divide. Some rules pre-1918 regarding the division symbol ÷†† state that it had a different meaning than the division symbol /. This is because ÷ used to mean "divide the number/expression on the left with the number/expression on the right"†††. So $a ÷ b$ then, would be $(a) / (b)$ or $frac{a}{b}$ now. In which case $6÷2×(1+2)$ would be evaluated like this by people pre-1918:



$$6÷2×(1+2) → frac{6}{2×(1+2)} → frac{6}{2×3} → frac{6}{6} → 1$$



†: Although I have found multiple sources explaining how ÷ was used in the past (see ††† below), I haven't been able to find definitive prove this changed somewhere around 1918. But for the sake of this challenge we assume 1918 was the turning point where ÷ and / starting to mean the same thing, where they differed in the past.
††: Other symbols have also been used in the past for division, like : in 1633 (or now still in The Netherlands and other European non-English speaking countries, since this is what I've personally learned in primary school xD) or ) in the 1540s. But for this challenge we only focus on the pre-1918 meaning of the obelus symbol ÷.
†††: Sources: this article in general. And the pre-1918 rules regarding ÷ are mentioned in: this The American Mathematical Monthly article from February 1917; this German Teutsche Algebra book from 1659 page 9 and page 76; this A First Book in Algebra from 1895 page 46 [48/189].



Slightly off-topic: regarding the actual discussion about this expression: It should never be written like this in the first place! The correct answer is irrelevant, if the question is unclear. *Clicks the "close because it's unclear what you're asking" button*.

And for the record, even different versions of Casio calculators don't know how to properly deal with this expression:
enter image description here



Challenge:



You are given two inputs:




  • A (valid) mathematical expression consisting only of the symbols 0123456789+-×/÷()

  • A year


And you output the result of the mathematical expression, based on the year (where ÷ is used differently when $year<1918$, but is used exactly the same as / when $yearge1918$).



Challenge rules:




  • You can assume the mathematical expression is valid and only uses the symbols 0123456789+-×/÷(). This also means you won't have to deal with exponentiation. (You are also allowed to use a different symbols for × or ÷ (i.e. * or %), if it helps the golfing or if your language only supports ASCII.)

  • You are allowed to add space-delimiters to the input-expression if this helps the (perhaps manual) evaluation of the expression.

  • I/O is flexible. Input can be as a string, character-array, etc. Year can be as an integer, date-object, string, etc. Output will be a decimal number.

  • You can assume there won't be any division by 0 test cases.

  • You can assume the numbers in the input-expression will be non-negative (so you won't have to deal with differentiating the - as negative symbol vs - as subtraction symbol). The output can however still be negative!

  • You can assume N( will always be written as N×( instead. We'll only focus on the second controversy of the division symbols / vs ÷ in this challenge.

  • Decimal output-values should have a precision of at least three decimal digits.

  • If the input-expression contains multiple ÷ (i.e. $4÷2÷2$) with $year<1918$, they are evaluated like this: $4÷2÷2 → frac{4}{frac{2}{2}} → frac{4}{1} → 4$. (Or in words: number $4$ is divided by expression $2 ÷2$, where expression $2 ÷2$ in turn means number $2$ is divided by number $2$.)

  • Note that the way ÷ works implicitly means it has operator precedence over × and / (see test case $4÷2×2÷3$).

  • You can assume the input-year is within the range $[0000, 9999]$.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input-expression:   Input-year:   Output:      Expression interpretation with parenthesis:

6÷2×(1+2) 2018 9 (6/2)×(1+2)
6÷2×(1+2) 1917 1 6/(2×(1+2))
9+6÷3-3+15/3 2000 13 ((9+(6/3))-3)+(15/3)
9+6÷3-3+15/3 1800 3 (9+6)/((3-3)+(15/3))
4÷2÷2 1918 1 (4/2)/2
4÷2÷2 1900 4 4/(2/2)
(1÷6-3)×5÷2/2 2400 -3.541... ((((1/6)-3)×5)/2)/2
(1÷6-3)×5÷2/2 1400 1.666... ((1/(6-3))×5)/(2/2)
1×2÷5×5-15 2015 -13 (((1×2)/5)×5)-15
1×2÷5×5-15 1719 0.2 (1×2)/((5×5)-15)
10/2+3×7 1991 26 (10/2)+(3×7)
10/2+3×7 1911 26 (10/2)+(3×7)
10÷2+3×7 1991 26 (10/2)+(3×7)
10÷2+3×7 1911 0.434... 10/(2+(3×7))
4÷2+2÷2 2000 3 (4/2)+(2/2)
4÷2+2÷2 1900 2 4/((2+2)/2)
4÷2×2÷3 9999 1.333... ((4/2)×2)/3
4÷2×2÷3 0000 3 4/((2×2)/3)
((10÷2)÷2)+3÷7 2000 2.928... ((10/2)/2)+(3/7)
((10÷2)÷2)+3÷7 1900 0.785... (((10/2)/2)+3)/7
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1920 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1750 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
10÷2/2+4 2000 6.5 ((10/2)/2)+4
10÷2/2+4 0100 2 10/((2/2)+4)









share|improve this question











$endgroup$




Feel free to skip this introduction and go to the challenge part, if you don't care about the background and inspiration of this challenge.



Introduction:



Inspired by a discussion that is already going on for many years regarding the expression $6÷2(1+2)$.



Irrelevant part for this challenge, but still interesting to know:




With the expression $6÷2(1+2)$, mathematicians will quickly see that the correct answer is $1$, whereas people with a simple math background from school will quickly see that the correct answer is $9$. So where does this controversy and therefore different answers come from? There are two conflicting rules in how $6÷2(1+2)$ is written. One due to the part 2(, and one due to the division symbol ÷.


Although both mathematicians and 'ordinary people' will use PEMDAS (Parenthesis - Exponents - Division/Multiplication - Addition/Subtraction), for mathematicians the expression is evaluated like this below, because $2(3)$ is just like for example $2x^2$ a monomial a.k.a. "a single term due to implied multiplication by juxtaposition" (and therefore part of the P in PEMDAS), which will be evaluated differently than $2×(3)$ (a binomial a.k.a. two terms):

$$6÷2(1+2) → frac{6}{2(3)} → frac{6}{6} → 1$$


Whereas for 'ordinary people', $2(3)$ and $2×(3)$ will be the same (and therefore part of the MD in PEMDAS), so they'll use this instead:

$$6÷2(1+2) → 6/2×(1+2) → 6/2×3 → 3×3 → 9$$




However, even if we would have written the original expression as $6÷2×(1+2)$, there can still be some controversy due to the use of the division symbol ÷. In modern mathematics, the / and ÷ symbols have the exact same meaning: divide. Some rules pre-1918 regarding the division symbol ÷†† state that it had a different meaning than the division symbol /. This is because ÷ used to mean "divide the number/expression on the left with the number/expression on the right"†††. So $a ÷ b$ then, would be $(a) / (b)$ or $frac{a}{b}$ now. In which case $6÷2×(1+2)$ would be evaluated like this by people pre-1918:



$$6÷2×(1+2) → frac{6}{2×(1+2)} → frac{6}{2×3} → frac{6}{6} → 1$$



†: Although I have found multiple sources explaining how ÷ was used in the past (see ††† below), I haven't been able to find definitive prove this changed somewhere around 1918. But for the sake of this challenge we assume 1918 was the turning point where ÷ and / starting to mean the same thing, where they differed in the past.
††: Other symbols have also been used in the past for division, like : in 1633 (or now still in The Netherlands and other European non-English speaking countries, since this is what I've personally learned in primary school xD) or ) in the 1540s. But for this challenge we only focus on the pre-1918 meaning of the obelus symbol ÷.
†††: Sources: this article in general. And the pre-1918 rules regarding ÷ are mentioned in: this The American Mathematical Monthly article from February 1917; this German Teutsche Algebra book from 1659 page 9 and page 76; this A First Book in Algebra from 1895 page 46 [48/189].



Slightly off-topic: regarding the actual discussion about this expression: It should never be written like this in the first place! The correct answer is irrelevant, if the question is unclear. *Clicks the "close because it's unclear what you're asking" button*.

And for the record, even different versions of Casio calculators don't know how to properly deal with this expression:
enter image description here



Challenge:



You are given two inputs:




  • A (valid) mathematical expression consisting only of the symbols 0123456789+-×/÷()

  • A year


And you output the result of the mathematical expression, based on the year (where ÷ is used differently when $year<1918$, but is used exactly the same as / when $yearge1918$).



Challenge rules:




  • You can assume the mathematical expression is valid and only uses the symbols 0123456789+-×/÷(). This also means you won't have to deal with exponentiation. (You are also allowed to use a different symbols for × or ÷ (i.e. * or %), if it helps the golfing or if your language only supports ASCII.)

  • You are allowed to add space-delimiters to the input-expression if this helps the (perhaps manual) evaluation of the expression.

  • I/O is flexible. Input can be as a string, character-array, etc. Year can be as an integer, date-object, string, etc. Output will be a decimal number.

  • You can assume there won't be any division by 0 test cases.

  • You can assume the numbers in the input-expression will be non-negative (so you won't have to deal with differentiating the - as negative symbol vs - as subtraction symbol). The output can however still be negative!

  • You can assume N( will always be written as N×( instead. We'll only focus on the second controversy of the division symbols / vs ÷ in this challenge.

  • Decimal output-values should have a precision of at least three decimal digits.

  • If the input-expression contains multiple ÷ (i.e. $4÷2÷2$) with $year<1918$, they are evaluated like this: $4÷2÷2 → frac{4}{frac{2}{2}} → frac{4}{1} → 4$. (Or in words: number $4$ is divided by expression $2 ÷2$, where expression $2 ÷2$ in turn means number $2$ is divided by number $2$.)

  • Note that the way ÷ works implicitly means it has operator precedence over × and / (see test case $4÷2×2÷3$).

  • You can assume the input-year is within the range $[0000, 9999]$.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input-expression:   Input-year:   Output:      Expression interpretation with parenthesis:

6÷2×(1+2) 2018 9 (6/2)×(1+2)
6÷2×(1+2) 1917 1 6/(2×(1+2))
9+6÷3-3+15/3 2000 13 ((9+(6/3))-3)+(15/3)
9+6÷3-3+15/3 1800 3 (9+6)/((3-3)+(15/3))
4÷2÷2 1918 1 (4/2)/2
4÷2÷2 1900 4 4/(2/2)
(1÷6-3)×5÷2/2 2400 -3.541... ((((1/6)-3)×5)/2)/2
(1÷6-3)×5÷2/2 1400 1.666... ((1/(6-3))×5)/(2/2)
1×2÷5×5-15 2015 -13 (((1×2)/5)×5)-15
1×2÷5×5-15 1719 0.2 (1×2)/((5×5)-15)
10/2+3×7 1991 26 (10/2)+(3×7)
10/2+3×7 1911 26 (10/2)+(3×7)
10÷2+3×7 1991 26 (10/2)+(3×7)
10÷2+3×7 1911 0.434... 10/(2+(3×7))
4÷2+2÷2 2000 3 (4/2)+(2/2)
4÷2+2÷2 1900 2 4/((2+2)/2)
4÷2×2÷3 9999 1.333... ((4/2)×2)/3
4÷2×2÷3 0000 3 4/((2×2)/3)
((10÷2)÷2)+3÷7 2000 2.928... ((10/2)/2)+(3/7)
((10÷2)÷2)+3÷7 1900 0.785... (((10/2)/2)+3)/7
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1920 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
(10÷(2÷2))+3×7+(10÷(2÷2))+3×7
1750 62 (10/(2/2))+(3×7)+(10/(2/2))+(3×7)
10÷2/2+4 2000 6.5 ((10/2)/2)+4
10÷2/2+4 0100 2 10/((2/2)+4)






code-golf math number arithmetic integer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 hours ago







Kevin Cruijssen

















asked 23 hours ago









Kevin CruijssenKevin Cruijssen

39.2k558203




39.2k558203








  • 10




    $begingroup$
    You know, I really don't like the PEMDAS acronym, because at first glance, it appears to imply that Multiplication comes before Division and Addition comes before Subtraction...
    $endgroup$
    – Jo King
    22 hours ago








  • 1




    $begingroup$
    Since the issue of N( is irrelevant for this challenge, it just confuses matters. Even your title is misleading. Remove all mention of that!
    $endgroup$
    – Adám
    22 hours ago








  • 3




    $begingroup$
    -1, no freehand circles :((
    $endgroup$
    – Don't be a x-triple dot
    22 hours ago








  • 10




    $begingroup$
    So, first you divide people into "real mathematicians", who know the "real" meaning of ÷, and "ordinary people", then you mention that this "real" meaning is actually archaic, and not used since 1918. As a person with a mathematical background, born slightly after 1918 I think the only purpose of the part under spoiler is to try to feel superior to others with no real reason to. A nice Code Golf question though.
    $endgroup$
    – FreeNickname
    20 hours ago






  • 5




    $begingroup$
    I'm not sure if any "mathematician uses PEMDAS". I mean, it's really just an acronym to learn the order, which most people outgrow at some point. I'm not a mathematician myself, but it took me considerable effort to recall the mnemonic in my native language, while I have absolutely no problems applying operations in the correct order...
    $endgroup$
    – Jasper
    14 hours ago














  • 10




    $begingroup$
    You know, I really don't like the PEMDAS acronym, because at first glance, it appears to imply that Multiplication comes before Division and Addition comes before Subtraction...
    $endgroup$
    – Jo King
    22 hours ago








  • 1




    $begingroup$
    Since the issue of N( is irrelevant for this challenge, it just confuses matters. Even your title is misleading. Remove all mention of that!
    $endgroup$
    – Adám
    22 hours ago








  • 3




    $begingroup$
    -1, no freehand circles :((
    $endgroup$
    – Don't be a x-triple dot
    22 hours ago








  • 10




    $begingroup$
    So, first you divide people into "real mathematicians", who know the "real" meaning of ÷, and "ordinary people", then you mention that this "real" meaning is actually archaic, and not used since 1918. As a person with a mathematical background, born slightly after 1918 I think the only purpose of the part under spoiler is to try to feel superior to others with no real reason to. A nice Code Golf question though.
    $endgroup$
    – FreeNickname
    20 hours ago






  • 5




    $begingroup$
    I'm not sure if any "mathematician uses PEMDAS". I mean, it's really just an acronym to learn the order, which most people outgrow at some point. I'm not a mathematician myself, but it took me considerable effort to recall the mnemonic in my native language, while I have absolutely no problems applying operations in the correct order...
    $endgroup$
    – Jasper
    14 hours ago








10




10




$begingroup$
You know, I really don't like the PEMDAS acronym, because at first glance, it appears to imply that Multiplication comes before Division and Addition comes before Subtraction...
$endgroup$
– Jo King
22 hours ago






$begingroup$
You know, I really don't like the PEMDAS acronym, because at first glance, it appears to imply that Multiplication comes before Division and Addition comes before Subtraction...
$endgroup$
– Jo King
22 hours ago






1




1




$begingroup$
Since the issue of N( is irrelevant for this challenge, it just confuses matters. Even your title is misleading. Remove all mention of that!
$endgroup$
– Adám
22 hours ago






$begingroup$
Since the issue of N( is irrelevant for this challenge, it just confuses matters. Even your title is misleading. Remove all mention of that!
$endgroup$
– Adám
22 hours ago






3




3




$begingroup$
-1, no freehand circles :((
$endgroup$
– Don't be a x-triple dot
22 hours ago






$begingroup$
-1, no freehand circles :((
$endgroup$
– Don't be a x-triple dot
22 hours ago






10




10




$begingroup$
So, first you divide people into "real mathematicians", who know the "real" meaning of ÷, and "ordinary people", then you mention that this "real" meaning is actually archaic, and not used since 1918. As a person with a mathematical background, born slightly after 1918 I think the only purpose of the part under spoiler is to try to feel superior to others with no real reason to. A nice Code Golf question though.
$endgroup$
– FreeNickname
20 hours ago




$begingroup$
So, first you divide people into "real mathematicians", who know the "real" meaning of ÷, and "ordinary people", then you mention that this "real" meaning is actually archaic, and not used since 1918. As a person with a mathematical background, born slightly after 1918 I think the only purpose of the part under spoiler is to try to feel superior to others with no real reason to. A nice Code Golf question though.
$endgroup$
– FreeNickname
20 hours ago




5




5




$begingroup$
I'm not sure if any "mathematician uses PEMDAS". I mean, it's really just an acronym to learn the order, which most people outgrow at some point. I'm not a mathematician myself, but it took me considerable effort to recall the mnemonic in my native language, while I have absolutely no problems applying operations in the correct order...
$endgroup$
– Jasper
14 hours ago




$begingroup$
I'm not sure if any "mathematician uses PEMDAS". I mean, it's really just an acronym to learn the order, which most people outgrow at some point. I'm not a mathematician myself, but it took me considerable effort to recall the mnemonic in my native language, while I have absolutely no problems applying operations in the correct order...
$endgroup$
– Jasper
14 hours ago










5 Answers
5






active

oldest

votes


















16












$begingroup$


R, 68 66 bytes





function(x,y,`=`=`/`)eval(parse(t=`if`(y<1918,x,gsub('=','/',x))))


Try it online!



Expects equality sign = instead of ÷ and * instead of ×.



The code makes use of some nasty operator overloading, making advantage of the fact that = is a right-to-left operator with very low precedence (the exact behavior that we want from pre-1918 ÷), and R retains its original precedence when it is overloaded. The rest is automatically done for us by eval.



As a bonus, here is the same exact approach implemented in terser syntax. This time our special division operator is tilde (~):




Julia 0.7, 51 bytes





~=/;f(x,y)=eval(parse(y<1918?x:replace(x,'~','/')))


Try it online!






share|improve this answer











$endgroup$













  • $begingroup$
    `=`=`/` is diabolical! Great solution!
    $endgroup$
    – Gregor
    16 hours ago



















4












$begingroup$


Python 3.8 (pre-release), 324 310 306 bytes





lambda s,y:eval((g(s*(y<1918))or s).replace('%','/'))
def g(s):
if'%'not in s:return s
l=r=j=J=i=s.find('%');x=y=0
while j>-1and(x:=x+~-')('.find(s[j])%3-1)>-1:l=[l,j][x<1];j-=1
while s[J:]and(y:=y+~-'()'.find(s[J])%3-1)>-1:r=[r,J+1][y<1];J+=1
return g(s[:l]+'('+g(s[l:i])+')/('+g(s[i+1:r])+')'+s[r:])


Try it online!



Takes % instead of ÷ and * instead of ×






share|improve this answer











$endgroup$





















    4












    $begingroup$

    JavaScript (ES6),  130  129 bytes



    Takes input as (year)(expr). Expects % and * instead of ÷ and ×.





    y=>g=e=>(e!=(e=e.replace(/([^()]*)/,h=e=>(p=s='',x=e.replace(/%/g,_=>y<1918?(p+='(',s+='))',')/(('):'/'),eval(p+x+s))))?g:h)(e)


    Try it online!



    How?



    Processing leaf expressions



    The helper function $h$ expects a leaf expression $e$ as input, processes all % symbols according to the rules of the year $y$ (defined in the parent scope) and evaluates the resulting string.



    If $y<1918$, we transform A%B into (A)/((B)) to enforce low precedence and right-to-left associativity.



    Examples:





    • 8%2 becomes (8)/((2)), whose simplified form is 8/2


    • 2+3%3+2 becomes (2+3)/((3+2)), whose simplified form is (2+3)/(3+2)


    • 8%2%2 becomes ((8)/((2)/((2)))), whose simplified form is 8/(2/2)


    If $yge 1918$, each % is simply turned into a /.



    h = e => (            // e = input string
    p = s = '', // p = prefix, s = suffix
    x = e.replace( // x = updated body
    ∕%∕g, // for each character '%' in e:
    _ => //
    y < 1918 ? ( // if y is less than 1918:
    p += '(', // append an opening parenthesis to the prefix
    s += '))', // append two closing parentheses to the suffix
    ')/((' // replace '%' with ')/(('
    ) : // else:
    '/' // replace '%' with '/'
    ), // end of replace()
    eval(p + x + s) // evaluate (prefix + body + suffix) as JS code
    ) //


    Dealing with nested expressions



    As mentioned above, the function $h$ is designed to operate properly on a leaf expression, i.e. an expression without any other sub-expression enclosed in parentheses.



    That's why we use the helper function $g$ to recursively identify and process leaf expressions.



    g = e => (            // e = input
    e != // compare the current expression with
    ( e = e.replace( // the updated expression where:
    /([^()]*)/, // each leaf expression '(A)'
    h // is processed with h
    ) // end of replace()
    ) ? // if the new expression is different from the original one:
    g // do a recursive call to g
    : // else:
    h // invoke h on the final string
    )(e) // invoke either g(e) or h(e)





    share|improve this answer











    $endgroup$













    • $begingroup$
      Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
      $endgroup$
      – Scott Hamper
      2 hours ago



















    2












    $begingroup$


    Japt, 28 26 17 bytes



    -2 bytes thanks to Shaggy



    OvUddV>#¿7?'/:"/(


    Try it online!



    The header replaces × with * and ÷ with d



    Explanation:



    OvUddV>#¿7?'/:"/(
    Implicit U = expression
    V = year
    Ov Japt eval:
    Ud Replace from U:
    d "d" with:
    V>#¿7? If V > 1917:
    '/ "/"
    : Else:
    "/( "/("


    This is a perfect challenge for Japt since Japt auto-inserts missing parenthesis.






    share|improve this answer











    $endgroup$













    • $begingroup$
      17 bytes?
      $endgroup$
      – Shaggy
      11 hours ago










    • $begingroup$
      Hmm ... would slicing work out shorter than the ternary?
      $endgroup$
      – Shaggy
      9 hours ago










    • $begingroup$
      @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
      $endgroup$
      – Oliver
      9 hours ago



















    0












    $begingroup$

    Perl 5, 47 97 bytes




    / /;$="($`)";$'<1918?s;%;)/(;g:s;%;/;g;$=eval



    fixing with 97 bytes couldn't find shorter right now



    / /;$_="($`)";$'<1918?do{1while s-([^()]+)-local$_=$&;s,%,)/((,rg.")"x y,%,,-ee}:y-%-/-;$_=eval


    TIO






    share|improve this answer











    $endgroup$









    • 3




      $begingroup$
      Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
      $endgroup$
      – Dada
      19 hours ago












    • $begingroup$
      it's true, i can't look anymore for the moment
      $endgroup$
      – Nahuel Fouilleul
      19 hours ago










    • $begingroup$
      @Dada, fixed (+50bytes)
      $endgroup$
      – Nahuel Fouilleul
      10 hours ago











    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',
    autoActivateHeartbeat: false,
    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%2f180608%2fwhat-is-6%25c3%25b72%25c3%259712%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    16












    $begingroup$


    R, 68 66 bytes





    function(x,y,`=`=`/`)eval(parse(t=`if`(y<1918,x,gsub('=','/',x))))


    Try it online!



    Expects equality sign = instead of ÷ and * instead of ×.



    The code makes use of some nasty operator overloading, making advantage of the fact that = is a right-to-left operator with very low precedence (the exact behavior that we want from pre-1918 ÷), and R retains its original precedence when it is overloaded. The rest is automatically done for us by eval.



    As a bonus, here is the same exact approach implemented in terser syntax. This time our special division operator is tilde (~):




    Julia 0.7, 51 bytes





    ~=/;f(x,y)=eval(parse(y<1918?x:replace(x,'~','/')))


    Try it online!






    share|improve this answer











    $endgroup$













    • $begingroup$
      `=`=`/` is diabolical! Great solution!
      $endgroup$
      – Gregor
      16 hours ago
















    16












    $begingroup$


    R, 68 66 bytes





    function(x,y,`=`=`/`)eval(parse(t=`if`(y<1918,x,gsub('=','/',x))))


    Try it online!



    Expects equality sign = instead of ÷ and * instead of ×.



    The code makes use of some nasty operator overloading, making advantage of the fact that = is a right-to-left operator with very low precedence (the exact behavior that we want from pre-1918 ÷), and R retains its original precedence when it is overloaded. The rest is automatically done for us by eval.



    As a bonus, here is the same exact approach implemented in terser syntax. This time our special division operator is tilde (~):




    Julia 0.7, 51 bytes





    ~=/;f(x,y)=eval(parse(y<1918?x:replace(x,'~','/')))


    Try it online!






    share|improve this answer











    $endgroup$













    • $begingroup$
      `=`=`/` is diabolical! Great solution!
      $endgroup$
      – Gregor
      16 hours ago














    16












    16








    16





    $begingroup$


    R, 68 66 bytes





    function(x,y,`=`=`/`)eval(parse(t=`if`(y<1918,x,gsub('=','/',x))))


    Try it online!



    Expects equality sign = instead of ÷ and * instead of ×.



    The code makes use of some nasty operator overloading, making advantage of the fact that = is a right-to-left operator with very low precedence (the exact behavior that we want from pre-1918 ÷), and R retains its original precedence when it is overloaded. The rest is automatically done for us by eval.



    As a bonus, here is the same exact approach implemented in terser syntax. This time our special division operator is tilde (~):




    Julia 0.7, 51 bytes





    ~=/;f(x,y)=eval(parse(y<1918?x:replace(x,'~','/')))


    Try it online!






    share|improve this answer











    $endgroup$




    R, 68 66 bytes





    function(x,y,`=`=`/`)eval(parse(t=`if`(y<1918,x,gsub('=','/',x))))


    Try it online!



    Expects equality sign = instead of ÷ and * instead of ×.



    The code makes use of some nasty operator overloading, making advantage of the fact that = is a right-to-left operator with very low precedence (the exact behavior that we want from pre-1918 ÷), and R retains its original precedence when it is overloaded. The rest is automatically done for us by eval.



    As a bonus, here is the same exact approach implemented in terser syntax. This time our special division operator is tilde (~):




    Julia 0.7, 51 bytes





    ~=/;f(x,y)=eval(parse(y<1918?x:replace(x,'~','/')))


    Try it online!







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 17 hours ago

























    answered 21 hours ago









    Kirill L.Kirill L.

    4,8651525




    4,8651525












    • $begingroup$
      `=`=`/` is diabolical! Great solution!
      $endgroup$
      – Gregor
      16 hours ago


















    • $begingroup$
      `=`=`/` is diabolical! Great solution!
      $endgroup$
      – Gregor
      16 hours ago
















    $begingroup$
    `=`=`/` is diabolical! Great solution!
    $endgroup$
    – Gregor
    16 hours ago




    $begingroup$
    `=`=`/` is diabolical! Great solution!
    $endgroup$
    – Gregor
    16 hours ago











    4












    $begingroup$


    Python 3.8 (pre-release), 324 310 306 bytes





    lambda s,y:eval((g(s*(y<1918))or s).replace('%','/'))
    def g(s):
    if'%'not in s:return s
    l=r=j=J=i=s.find('%');x=y=0
    while j>-1and(x:=x+~-')('.find(s[j])%3-1)>-1:l=[l,j][x<1];j-=1
    while s[J:]and(y:=y+~-'()'.find(s[J])%3-1)>-1:r=[r,J+1][y<1];J+=1
    return g(s[:l]+'('+g(s[l:i])+')/('+g(s[i+1:r])+')'+s[r:])


    Try it online!



    Takes % instead of ÷ and * instead of ×






    share|improve this answer











    $endgroup$


















      4












      $begingroup$


      Python 3.8 (pre-release), 324 310 306 bytes





      lambda s,y:eval((g(s*(y<1918))or s).replace('%','/'))
      def g(s):
      if'%'not in s:return s
      l=r=j=J=i=s.find('%');x=y=0
      while j>-1and(x:=x+~-')('.find(s[j])%3-1)>-1:l=[l,j][x<1];j-=1
      while s[J:]and(y:=y+~-'()'.find(s[J])%3-1)>-1:r=[r,J+1][y<1];J+=1
      return g(s[:l]+'('+g(s[l:i])+')/('+g(s[i+1:r])+')'+s[r:])


      Try it online!



      Takes % instead of ÷ and * instead of ×






      share|improve this answer











      $endgroup$
















        4












        4








        4





        $begingroup$


        Python 3.8 (pre-release), 324 310 306 bytes





        lambda s,y:eval((g(s*(y<1918))or s).replace('%','/'))
        def g(s):
        if'%'not in s:return s
        l=r=j=J=i=s.find('%');x=y=0
        while j>-1and(x:=x+~-')('.find(s[j])%3-1)>-1:l=[l,j][x<1];j-=1
        while s[J:]and(y:=y+~-'()'.find(s[J])%3-1)>-1:r=[r,J+1][y<1];J+=1
        return g(s[:l]+'('+g(s[l:i])+')/('+g(s[i+1:r])+')'+s[r:])


        Try it online!



        Takes % instead of ÷ and * instead of ×






        share|improve this answer











        $endgroup$




        Python 3.8 (pre-release), 324 310 306 bytes





        lambda s,y:eval((g(s*(y<1918))or s).replace('%','/'))
        def g(s):
        if'%'not in s:return s
        l=r=j=J=i=s.find('%');x=y=0
        while j>-1and(x:=x+~-')('.find(s[j])%3-1)>-1:l=[l,j][x<1];j-=1
        while s[J:]and(y:=y+~-'()'.find(s[J])%3-1)>-1:r=[r,J+1][y<1];J+=1
        return g(s[:l]+'('+g(s[l:i])+')/('+g(s[i+1:r])+')'+s[r:])


        Try it online!



        Takes % instead of ÷ and * instead of ×







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 18 hours ago

























        answered 22 hours ago









        TFeldTFeld

        15.4k21247




        15.4k21247























            4












            $begingroup$

            JavaScript (ES6),  130  129 bytes



            Takes input as (year)(expr). Expects % and * instead of ÷ and ×.





            y=>g=e=>(e!=(e=e.replace(/([^()]*)/,h=e=>(p=s='',x=e.replace(/%/g,_=>y<1918?(p+='(',s+='))',')/(('):'/'),eval(p+x+s))))?g:h)(e)


            Try it online!



            How?



            Processing leaf expressions



            The helper function $h$ expects a leaf expression $e$ as input, processes all % symbols according to the rules of the year $y$ (defined in the parent scope) and evaluates the resulting string.



            If $y<1918$, we transform A%B into (A)/((B)) to enforce low precedence and right-to-left associativity.



            Examples:





            • 8%2 becomes (8)/((2)), whose simplified form is 8/2


            • 2+3%3+2 becomes (2+3)/((3+2)), whose simplified form is (2+3)/(3+2)


            • 8%2%2 becomes ((8)/((2)/((2)))), whose simplified form is 8/(2/2)


            If $yge 1918$, each % is simply turned into a /.



            h = e => (            // e = input string
            p = s = '', // p = prefix, s = suffix
            x = e.replace( // x = updated body
            ∕%∕g, // for each character '%' in e:
            _ => //
            y < 1918 ? ( // if y is less than 1918:
            p += '(', // append an opening parenthesis to the prefix
            s += '))', // append two closing parentheses to the suffix
            ')/((' // replace '%' with ')/(('
            ) : // else:
            '/' // replace '%' with '/'
            ), // end of replace()
            eval(p + x + s) // evaluate (prefix + body + suffix) as JS code
            ) //


            Dealing with nested expressions



            As mentioned above, the function $h$ is designed to operate properly on a leaf expression, i.e. an expression without any other sub-expression enclosed in parentheses.



            That's why we use the helper function $g$ to recursively identify and process leaf expressions.



            g = e => (            // e = input
            e != // compare the current expression with
            ( e = e.replace( // the updated expression where:
            /([^()]*)/, // each leaf expression '(A)'
            h // is processed with h
            ) // end of replace()
            ) ? // if the new expression is different from the original one:
            g // do a recursive call to g
            : // else:
            h // invoke h on the final string
            )(e) // invoke either g(e) or h(e)





            share|improve this answer











            $endgroup$













            • $begingroup$
              Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
              $endgroup$
              – Scott Hamper
              2 hours ago
















            4












            $begingroup$

            JavaScript (ES6),  130  129 bytes



            Takes input as (year)(expr). Expects % and * instead of ÷ and ×.





            y=>g=e=>(e!=(e=e.replace(/([^()]*)/,h=e=>(p=s='',x=e.replace(/%/g,_=>y<1918?(p+='(',s+='))',')/(('):'/'),eval(p+x+s))))?g:h)(e)


            Try it online!



            How?



            Processing leaf expressions



            The helper function $h$ expects a leaf expression $e$ as input, processes all % symbols according to the rules of the year $y$ (defined in the parent scope) and evaluates the resulting string.



            If $y<1918$, we transform A%B into (A)/((B)) to enforce low precedence and right-to-left associativity.



            Examples:





            • 8%2 becomes (8)/((2)), whose simplified form is 8/2


            • 2+3%3+2 becomes (2+3)/((3+2)), whose simplified form is (2+3)/(3+2)


            • 8%2%2 becomes ((8)/((2)/((2)))), whose simplified form is 8/(2/2)


            If $yge 1918$, each % is simply turned into a /.



            h = e => (            // e = input string
            p = s = '', // p = prefix, s = suffix
            x = e.replace( // x = updated body
            ∕%∕g, // for each character '%' in e:
            _ => //
            y < 1918 ? ( // if y is less than 1918:
            p += '(', // append an opening parenthesis to the prefix
            s += '))', // append two closing parentheses to the suffix
            ')/((' // replace '%' with ')/(('
            ) : // else:
            '/' // replace '%' with '/'
            ), // end of replace()
            eval(p + x + s) // evaluate (prefix + body + suffix) as JS code
            ) //


            Dealing with nested expressions



            As mentioned above, the function $h$ is designed to operate properly on a leaf expression, i.e. an expression without any other sub-expression enclosed in parentheses.



            That's why we use the helper function $g$ to recursively identify and process leaf expressions.



            g = e => (            // e = input
            e != // compare the current expression with
            ( e = e.replace( // the updated expression where:
            /([^()]*)/, // each leaf expression '(A)'
            h // is processed with h
            ) // end of replace()
            ) ? // if the new expression is different from the original one:
            g // do a recursive call to g
            : // else:
            h // invoke h on the final string
            )(e) // invoke either g(e) or h(e)





            share|improve this answer











            $endgroup$













            • $begingroup$
              Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
              $endgroup$
              – Scott Hamper
              2 hours ago














            4












            4








            4





            $begingroup$

            JavaScript (ES6),  130  129 bytes



            Takes input as (year)(expr). Expects % and * instead of ÷ and ×.





            y=>g=e=>(e!=(e=e.replace(/([^()]*)/,h=e=>(p=s='',x=e.replace(/%/g,_=>y<1918?(p+='(',s+='))',')/(('):'/'),eval(p+x+s))))?g:h)(e)


            Try it online!



            How?



            Processing leaf expressions



            The helper function $h$ expects a leaf expression $e$ as input, processes all % symbols according to the rules of the year $y$ (defined in the parent scope) and evaluates the resulting string.



            If $y<1918$, we transform A%B into (A)/((B)) to enforce low precedence and right-to-left associativity.



            Examples:





            • 8%2 becomes (8)/((2)), whose simplified form is 8/2


            • 2+3%3+2 becomes (2+3)/((3+2)), whose simplified form is (2+3)/(3+2)


            • 8%2%2 becomes ((8)/((2)/((2)))), whose simplified form is 8/(2/2)


            If $yge 1918$, each % is simply turned into a /.



            h = e => (            // e = input string
            p = s = '', // p = prefix, s = suffix
            x = e.replace( // x = updated body
            ∕%∕g, // for each character '%' in e:
            _ => //
            y < 1918 ? ( // if y is less than 1918:
            p += '(', // append an opening parenthesis to the prefix
            s += '))', // append two closing parentheses to the suffix
            ')/((' // replace '%' with ')/(('
            ) : // else:
            '/' // replace '%' with '/'
            ), // end of replace()
            eval(p + x + s) // evaluate (prefix + body + suffix) as JS code
            ) //


            Dealing with nested expressions



            As mentioned above, the function $h$ is designed to operate properly on a leaf expression, i.e. an expression without any other sub-expression enclosed in parentheses.



            That's why we use the helper function $g$ to recursively identify and process leaf expressions.



            g = e => (            // e = input
            e != // compare the current expression with
            ( e = e.replace( // the updated expression where:
            /([^()]*)/, // each leaf expression '(A)'
            h // is processed with h
            ) // end of replace()
            ) ? // if the new expression is different from the original one:
            g // do a recursive call to g
            : // else:
            h // invoke h on the final string
            )(e) // invoke either g(e) or h(e)





            share|improve this answer











            $endgroup$



            JavaScript (ES6),  130  129 bytes



            Takes input as (year)(expr). Expects % and * instead of ÷ and ×.





            y=>g=e=>(e!=(e=e.replace(/([^()]*)/,h=e=>(p=s='',x=e.replace(/%/g,_=>y<1918?(p+='(',s+='))',')/(('):'/'),eval(p+x+s))))?g:h)(e)


            Try it online!



            How?



            Processing leaf expressions



            The helper function $h$ expects a leaf expression $e$ as input, processes all % symbols according to the rules of the year $y$ (defined in the parent scope) and evaluates the resulting string.



            If $y<1918$, we transform A%B into (A)/((B)) to enforce low precedence and right-to-left associativity.



            Examples:





            • 8%2 becomes (8)/((2)), whose simplified form is 8/2


            • 2+3%3+2 becomes (2+3)/((3+2)), whose simplified form is (2+3)/(3+2)


            • 8%2%2 becomes ((8)/((2)/((2)))), whose simplified form is 8/(2/2)


            If $yge 1918$, each % is simply turned into a /.



            h = e => (            // e = input string
            p = s = '', // p = prefix, s = suffix
            x = e.replace( // x = updated body
            ∕%∕g, // for each character '%' in e:
            _ => //
            y < 1918 ? ( // if y is less than 1918:
            p += '(', // append an opening parenthesis to the prefix
            s += '))', // append two closing parentheses to the suffix
            ')/((' // replace '%' with ')/(('
            ) : // else:
            '/' // replace '%' with '/'
            ), // end of replace()
            eval(p + x + s) // evaluate (prefix + body + suffix) as JS code
            ) //


            Dealing with nested expressions



            As mentioned above, the function $h$ is designed to operate properly on a leaf expression, i.e. an expression without any other sub-expression enclosed in parentheses.



            That's why we use the helper function $g$ to recursively identify and process leaf expressions.



            g = e => (            // e = input
            e != // compare the current expression with
            ( e = e.replace( // the updated expression where:
            /([^()]*)/, // each leaf expression '(A)'
            h // is processed with h
            ) // end of replace()
            ) ? // if the new expression is different from the original one:
            g // do a recursive call to g
            : // else:
            h // invoke h on the final string
            )(e) // invoke either g(e) or h(e)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 17 hours ago

























            answered 21 hours ago









            ArnauldArnauld

            77.3k693324




            77.3k693324












            • $begingroup$
              Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
              $endgroup$
              – Scott Hamper
              2 hours ago


















            • $begingroup$
              Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
              $endgroup$
              – Scott Hamper
              2 hours ago
















            $begingroup$
            Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
            $endgroup$
            – Scott Hamper
            2 hours ago




            $begingroup$
            Here's a version of h that's 9 bytes shorter: h=e=>eval(e.split`%`.reduceRight((a,c)=>y<1918?`(${c})/(${a})`:c+'/'+a))
            $endgroup$
            – Scott Hamper
            2 hours ago











            2












            $begingroup$


            Japt, 28 26 17 bytes



            -2 bytes thanks to Shaggy



            OvUddV>#¿7?'/:"/(


            Try it online!



            The header replaces × with * and ÷ with d



            Explanation:



            OvUddV>#¿7?'/:"/(
            Implicit U = expression
            V = year
            Ov Japt eval:
            Ud Replace from U:
            d "d" with:
            V>#¿7? If V > 1917:
            '/ "/"
            : Else:
            "/( "/("


            This is a perfect challenge for Japt since Japt auto-inserts missing parenthesis.






            share|improve this answer











            $endgroup$













            • $begingroup$
              17 bytes?
              $endgroup$
              – Shaggy
              11 hours ago










            • $begingroup$
              Hmm ... would slicing work out shorter than the ternary?
              $endgroup$
              – Shaggy
              9 hours ago










            • $begingroup$
              @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
              $endgroup$
              – Oliver
              9 hours ago
















            2












            $begingroup$


            Japt, 28 26 17 bytes



            -2 bytes thanks to Shaggy



            OvUddV>#¿7?'/:"/(


            Try it online!



            The header replaces × with * and ÷ with d



            Explanation:



            OvUddV>#¿7?'/:"/(
            Implicit U = expression
            V = year
            Ov Japt eval:
            Ud Replace from U:
            d "d" with:
            V>#¿7? If V > 1917:
            '/ "/"
            : Else:
            "/( "/("


            This is a perfect challenge for Japt since Japt auto-inserts missing parenthesis.






            share|improve this answer











            $endgroup$













            • $begingroup$
              17 bytes?
              $endgroup$
              – Shaggy
              11 hours ago










            • $begingroup$
              Hmm ... would slicing work out shorter than the ternary?
              $endgroup$
              – Shaggy
              9 hours ago










            • $begingroup$
              @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
              $endgroup$
              – Oliver
              9 hours ago














            2












            2








            2





            $begingroup$


            Japt, 28 26 17 bytes



            -2 bytes thanks to Shaggy



            OvUddV>#¿7?'/:"/(


            Try it online!



            The header replaces × with * and ÷ with d



            Explanation:



            OvUddV>#¿7?'/:"/(
            Implicit U = expression
            V = year
            Ov Japt eval:
            Ud Replace from U:
            d "d" with:
            V>#¿7? If V > 1917:
            '/ "/"
            : Else:
            "/( "/("


            This is a perfect challenge for Japt since Japt auto-inserts missing parenthesis.






            share|improve this answer











            $endgroup$




            Japt, 28 26 17 bytes



            -2 bytes thanks to Shaggy



            OvUddV>#¿7?'/:"/(


            Try it online!



            The header replaces × with * and ÷ with d



            Explanation:



            OvUddV>#¿7?'/:"/(
            Implicit U = expression
            V = year
            Ov Japt eval:
            Ud Replace from U:
            d "d" with:
            V>#¿7? If V > 1917:
            '/ "/"
            : Else:
            "/( "/("


            This is a perfect challenge for Japt since Japt auto-inserts missing parenthesis.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 10 hours ago

























            answered 13 hours ago









            OliverOliver

            5,1301832




            5,1301832












            • $begingroup$
              17 bytes?
              $endgroup$
              – Shaggy
              11 hours ago










            • $begingroup$
              Hmm ... would slicing work out shorter than the ternary?
              $endgroup$
              – Shaggy
              9 hours ago










            • $begingroup$
              @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
              $endgroup$
              – Oliver
              9 hours ago


















            • $begingroup$
              17 bytes?
              $endgroup$
              – Shaggy
              11 hours ago










            • $begingroup$
              Hmm ... would slicing work out shorter than the ternary?
              $endgroup$
              – Shaggy
              9 hours ago










            • $begingroup$
              @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
              $endgroup$
              – Oliver
              9 hours ago
















            $begingroup$
            17 bytes?
            $endgroup$
            – Shaggy
            11 hours ago




            $begingroup$
            17 bytes?
            $endgroup$
            – Shaggy
            11 hours ago












            $begingroup$
            Hmm ... would slicing work out shorter than the ternary?
            $endgroup$
            – Shaggy
            9 hours ago




            $begingroup$
            Hmm ... would slicing work out shorter than the ternary?
            $endgroup$
            – Shaggy
            9 hours ago












            $begingroup$
            @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
            $endgroup$
            – Oliver
            9 hours ago




            $begingroup$
            @Shaggy That's exactly what I've been trying to work out. No luck getting it shorter though
            $endgroup$
            – Oliver
            9 hours ago











            0












            $begingroup$

            Perl 5, 47 97 bytes




            / /;$="($`)";$'<1918?s;%;)/(;g:s;%;/;g;$=eval



            fixing with 97 bytes couldn't find shorter right now



            / /;$_="($`)";$'<1918?do{1while s-([^()]+)-local$_=$&;s,%,)/((,rg.")"x y,%,,-ee}:y-%-/-;$_=eval


            TIO






            share|improve this answer











            $endgroup$









            • 3




              $begingroup$
              Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
              $endgroup$
              – Dada
              19 hours ago












            • $begingroup$
              it's true, i can't look anymore for the moment
              $endgroup$
              – Nahuel Fouilleul
              19 hours ago










            • $begingroup$
              @Dada, fixed (+50bytes)
              $endgroup$
              – Nahuel Fouilleul
              10 hours ago
















            0












            $begingroup$

            Perl 5, 47 97 bytes




            / /;$="($`)";$'<1918?s;%;)/(;g:s;%;/;g;$=eval



            fixing with 97 bytes couldn't find shorter right now



            / /;$_="($`)";$'<1918?do{1while s-([^()]+)-local$_=$&;s,%,)/((,rg.")"x y,%,,-ee}:y-%-/-;$_=eval


            TIO






            share|improve this answer











            $endgroup$









            • 3




              $begingroup$
              Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
              $endgroup$
              – Dada
              19 hours ago












            • $begingroup$
              it's true, i can't look anymore for the moment
              $endgroup$
              – Nahuel Fouilleul
              19 hours ago










            • $begingroup$
              @Dada, fixed (+50bytes)
              $endgroup$
              – Nahuel Fouilleul
              10 hours ago














            0












            0








            0





            $begingroup$

            Perl 5, 47 97 bytes




            / /;$="($`)";$'<1918?s;%;)/(;g:s;%;/;g;$=eval



            fixing with 97 bytes couldn't find shorter right now



            / /;$_="($`)";$'<1918?do{1while s-([^()]+)-local$_=$&;s,%,)/((,rg.")"x y,%,,-ee}:y-%-/-;$_=eval


            TIO






            share|improve this answer











            $endgroup$



            Perl 5, 47 97 bytes




            / /;$="($`)";$'<1918?s;%;)/(;g:s;%;/;g;$=eval



            fixing with 97 bytes couldn't find shorter right now



            / /;$_="($`)";$'<1918?do{1while s-([^()]+)-local$_=$&;s,%,)/((,rg.")"x y,%,,-ee}:y-%-/-;$_=eval


            TIO







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 10 hours ago

























            answered 19 hours ago









            Nahuel FouilleulNahuel Fouilleul

            2,60529




            2,60529








            • 3




              $begingroup$
              Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
              $endgroup$
              – Dada
              19 hours ago












            • $begingroup$
              it's true, i can't look anymore for the moment
              $endgroup$
              – Nahuel Fouilleul
              19 hours ago










            • $begingroup$
              @Dada, fixed (+50bytes)
              $endgroup$
              – Nahuel Fouilleul
              10 hours ago














            • 3




              $begingroup$
              Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
              $endgroup$
              – Dada
              19 hours ago












            • $begingroup$
              it's true, i can't look anymore for the moment
              $endgroup$
              – Nahuel Fouilleul
              19 hours ago










            • $begingroup$
              @Dada, fixed (+50bytes)
              $endgroup$
              – Nahuel Fouilleul
              10 hours ago








            3




            3




            $begingroup$
            Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
            $endgroup$
            – Dada
            19 hours ago






            $begingroup$
            Very nice idea. However, you have an issue with 4%2%2 which returns 1 in both cases. (whereas it should return 4 pre-1918)
            $endgroup$
            – Dada
            19 hours ago














            $begingroup$
            it's true, i can't look anymore for the moment
            $endgroup$
            – Nahuel Fouilleul
            19 hours ago




            $begingroup$
            it's true, i can't look anymore for the moment
            $endgroup$
            – Nahuel Fouilleul
            19 hours ago












            $begingroup$
            @Dada, fixed (+50bytes)
            $endgroup$
            – Nahuel Fouilleul
            10 hours ago




            $begingroup$
            @Dada, fixed (+50bytes)
            $endgroup$
            – Nahuel Fouilleul
            10 hours ago


















            draft saved

            draft discarded




















































            If this is an answer to a challenge…




            • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


            • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
              Explanations of your answer make it more interesting to read and are very much encouraged.


            • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



            More generally…




            • …Please make sure to answer the question and provide sufficient detail.


            • …Avoid asking for help, clarification or responding to other answers (use comments instead).





            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180608%2fwhat-is-6%25c3%25b72%25c3%259712%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

            How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

            Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...