• cerement@slrpnk.net
    link
    fedilink
    arrow-up
    42
    ·
    2 years ago
    • 16 is the right answer if you use PEMDAS only: (8 ÷ 2) × (2 + 2)
    • 1 is the right answer if you use implicit/explicit with PEMDAS: 8 ÷ (2 × (2 + 2))
    • both are correct answers (as in if you don’t put in extra parentheses to reduce ambiguity, you should expect expect either answer)
    • this is also one of the reasons why postfix and prefix notations have an advantage over infix notation
      • postfix (HP, RPN, Forth): 2 2 + 8 2 ÷ × .
      • prefix (Lisp): (× (÷ 8 2) (+ 2 2))
    • brian@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      prefix notation doesn’t need parentheses either though, at least in this case. lisp uses them for readability and to get multiple arity operators. infix doesn’t have any ambiguity either if you parenthesize all operations like that.

    • fruitSnackSupreme@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      How is PEMDAS 16? Multiply is before divide, so it’s 1. I was taught BEDMAS, divide before multiply, which makes it 16. I don’t know what is correct, just asking.

      • synae[he/him]@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        2 years ago

        PEMDAS is actually (PE)(MD)(AS). Those that are grouped together have equal precedence and are evaluated left to right.

        8 / 2 * (2+2)

        8 / 2 * 4

        4 * 4

        16

        Edit to fix formatting, maybe?