# A more interesting pictorial numerical puzzle

**Online College Math Teacher**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The solution generally requires that you remember the PEMDAS (in the US, or BODMAS elsewhere) rules for order of operations especially that multiplication takes precedence over addition, and also that you carefully count the number of eggs and number of bananas. I get 36.

OK, let me try to create a more interesting pictorial puzzle.

Mathematicians agree on the PEMDAS rules, although there are many situations that PEMDAS doesn’t handle.
Perhaps the most common is the unary minus operator as in -3^{2}. It is unary because unlike subtraction
that has two operands, the unary operator only has one. I think mathematicians would like to see the
unary operator as changing the sign of the argument, so that -3^{2} equals -9, although some software,
most notably Excel, merrily calculate this as +9.

I don’t believe there is a single authority for all the order of operations cases. For example, Excel, Google Search, and Wolfram Alpha do not always agree. I bet there are some pretty smart people in those companies.

Nowadays I am doing my fun calculations in the R computer language, so for the remainder of this post I will require R as the authority.

So here is my attempt at a more interesting problem, but remember, you have to use the order of operation precedence rules of R: (Let me add the link to the first item: https://www.facebook.com/watch/?v=10158293605695705 )

Do you want to try it before I reveal the R code?

The R code is:

apple <- 1

banana <- 2

kiwi <- 3

lemon <- 4

peach <- banana + lemon

pear <- banana^banana^kiwi   # 2^(2^3) = 256

pineapple <- (pear - banana) %% kiwi^2 * lemon   # (254 %% 9) * 4 = 2 * 4 = 8

strawberry <- pineapple / peach * peach   # 8; no obelus in R

kiwi <- c(lemon, pineapple, strawberry)

watermelon <- kiwi[kiwi == lemon | kiwi == pineapple & kiwi == strawberry]

# watermelon <- (lemon V pineapple ∧ strawberry)   # 4 V (8 & 8) = 4, 8

The ordering rules of R include:

- Modular arithmetic is at the same level as multiplication:   a mod b * c is   (a mod b) *c
- The obelus does not appear in R but is just a division symbol:   a ÷ b * c = (a / b) * c
- Repeated exponentiation goes right to left: a ^ b ^ c = a^(b^c); lots of disagreement outside R on this one
- Logical AND preceds logical OR

**leave a comment**for the author, please follow the link and comment on their blog:

**Online College Math Teacher**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.