CatsCradle CatsCradle

Niner since 2004


  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Had to throw my 2 cents in. A lot of you have great ideas about how to reverse and compare a string but I haven't seen anyone really interrogate the problem top down correctly. That goes for the guy in the video who posed it.

    A palindrome is a word, phrase or verse that is READ the same backward as forward. I believe this also implies Means the same. Just the fact that it must be a word, phrase or verse means aBBa is not a Palindrome. (In English anyway)  Neither is 'm'. Neither could a book (ie War and Peace Wink). So the guy in the video was incorrect in answering yes to that question. (Needs to sharpen HIS information gathering skills). Since reading a word, phrase or verse implies it is in a consistent language (Joyce's Ulysses aside) characters inconsistent with that language make testing impossible. An accent grave or aigu used in a standard English sentence would disqualify it and should raise an INVALID_CHARACTER_ERROR.
    Punctuation such as commas, colons, dashes etc.. are in another layer of sentence structure addressing interpretation. They are irrelevant to determining whether a word, phrase or verse is a palindrome.
    So the rules for reversing a string and comparing it are much different from determining if a word, phrase or verse is a palindrome.

    Some of you hinted at this when you suggested puncutation and spaces should be stripped before making the comparison. I suppose to make the function generic one would have to add an additional parameter of dictionary. This would also help take care of Unicode issues.

    If we consider the poser of the original task as playing the role of user I think we can glean something from the excercise other than 100 routines to find out if a string is layed out the same backwards as forwards. It is something that I think we can all relate to in our efforts to define a problem as communicated to us by our users. When he said 'Palindrome' and proceeded to outline the rules, at some point we would think "I get it. He means reverse the string and see if it is the same. He's using Palindrome to let us know that he knows (or thinks he knows) the word and therefore is an intelligent and exciting individual." We would then go write the String_Compare_Reversal method according to his rules and he would be happy.