Tuesday, February 5, 2008

Ambiguity in Specifications

On the T on the way to work this morning there was an ad recruiting for ITA Software. The ad ran something like this (I'm paraphrasing):

================
Problem:
If you take all the numbers from 1 to 999,999 and write them out as words, then concatenate them, what is the 51 millionth letter?

If you can solve this, come work for us!
===============

Coding for this problem is not difficult. However, I could come up with several different answers. I assert that the question is ambiguous.

Ambiguity 1: "from X to Y"
  • Is this inclusive? That is, do I include the numbers 1 and 999,999 or not? 
  • I assume this is whole numbers (integers) only; the problem isn't really solvable unless some interval is defined.
Ambiguity 2: "concatenate"
  • In most languages, this means that you simply write out the numbers one after the other with no delimiter (no space, no line ending, etc). Confirm this assumption.
  • In a few languages, calling concatenate results in removing all white space. Confirm that this is not the underlying assumption.
Ambiguity 3: "write out the number"
  • 1171
  • one-thousand, one hundred, seventy-one
  • one thousand one hundred seventy one
  • one thousand one hundred and seventy one (I believe this one actually expresses 1100.71)
  • one one seven one
None of these ambiguities is a difficult thing to determine, but they will change your answer. The moral of the story is to really read your specification, eliminate ambiguities, and then start coding.

Somehow, I think this is more interesting as a test question than as a coding question!

No comments:

Post a Comment