Which one has two zero and two four?

I came across a post on Facebook, in which you’re challenged to provide the “correct” answer. Normally, I would bypass these as I don’t have much time in the day-to-day work to engage but I had a build that was particularly slow so I “play”

“Which one has two zero and two four?”

  • A) 0024
  • B) 2024
  • C) 0044

I’ve recently started taking formal Spanish lessons again to improve my public speaking and I looked at the question a bit differently. As I started thinking about the solution, I was taken back to my sophomore year of college at the North Avenue Trade school, when I changed my major from Computer Engineering to Computer Science. That summer, I stayed in Atlanta and took a pivotal class, CS1411. It was there that I met 3 of my best friends. It was in this class that I started learning about parsers by way of building an operating system over the course of the class.

Let’s break the sentence down or in compiler-speak apply a lexical analyzer, parsing the components (tokens) in order to make sense of it

“Which one has” – this is equivalent to a query/filter command, returning a single result similar to:

•  “SELECT TOP 1” in SQL

“.first(where: )” in Swift

Is there a “correct” answer?

The correct answer is “It depends”. Let’s look at the ways in which we can interpret the remaining components

The most common interpretation (based on responses) may say that the words TWO, ZERO, TWO & FOUR each represent a LITERAL value. We will also state that AND is a concatenation operator, meaning we simply combine it with the preceding value(s)

With this interpretation, we get “2024” and B is correct

What if the rules were slightly different?

Let’s now say the first number represents a COUNT operator and the following number represents a LITERAL value. We will maintain the rule that AND is a concatenation operator, as above.

 “Two Zero” would be interpreted as COUNT (“TWO”) followed by a LITERAL number (“ZERO”) meaning “2 of the literal value (0)”, which results in “00”. Similarly, “Two Four” would be interpreted as “44”

With this interpretation, we get “0044” and C is correct

What if AND behaved differently?

Imagine that our AND did more than just concatenate, which makes sense as it feels unnecessary in the prior examples. The values can simply be returned, negating the need for the AND (Think  “me llamo Alondo” instead of “me llamo es Alondo”)

Instead, consider AND behaving as switch operator, moving between modes of the LITERAL and COUNT/LITERAL interpretations.

• COUNT/LITERAL “2 of the literal value (0)”  

• AND (switch modes from COUNT/LITERAL to LITERAL

• LITERAL(“24”)

With this interpretation, we get “0024” and A is correct

Summary

For me, this was a simple reminder that there are often more than “2” sides to something and that the “correct” answer is usually context dependent. It’s important to pay attention to the factors that impact interpretation and therefore resulting outcomes.