PeterF

Back to Profile: PeterF

Comments

  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Maurits wrote:
    Sathyaish Chakravarthy wrote:
    Maurits wrote:


    The more I think about it, the more I think that zero-length strings ARE palindromes.  This is especially important in recursive algorithms applied to even-length strings.


    Could you please elaborate?


    OK.  One algorithm I've seen is:
    Is_Palindrome:
      If the string length is 0, return TRUE *
      If the string length is 1, return TRUE
      If the first character is different than the last character, return FALSE
      Otherwise, recursively check the string minus the first and last character

    The *'d line is what I'm referring to.  If the TRUE is changed to a FALSE, then every even-length palindrome will incorrectly return FALSE.



    See my solution, just treat 2-length strings differently, so that it only checks if both characters are the same, and then return true or false in stead of invoking itself with string length zero.
  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Sorry, somehow felt compelling to be original Wink

    Well, reversing the string is off course a very simple and wise choice not to over-complicate the code and move on to the next task. If speed would be a goal (when using it very often), it would depend on the type of input data. If you would check the English dictionary for Palindromes, the reversing strings step could in the end be a more time consuming task than moving pointers, compare and return false after the first few iterations in most cases...
  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    What happened to good old recursiveness? Wink

    This version should work for sentences as well (with punctuations etc).

    public bool IsPalindrome(string inputString)
    {
     StringBuilder inputStringBuilder = new StringBuilder(inputString);
     for (int i = inputString.Length-1; i > -1; i--)
      {
       if (!Char.IsLetterOrDigit(inputString.Substring(i, 1),0))
       {
        inputStringBuilder.Remove(i, 1);
       }
      }
     return IsPalindromeNormalized( inputStringBuilder.ToString().ToLower());
    }

    private bool IsPalindromeNormalized(string inputString)
    {
     switch (inputString.Length)
     {
      case 0:
       return false;
       break;
      case 1:
       return true;
       break;
      case 2:
       return inputString.Substring(0, 1) == inputString.Substring(1, 1);
       break;
      default:
       if (inputString.Substring(0, 1) == inputString.Substring(inputString.Length - 1, 1))
       {
        return IsPalindromeNormalized(inputString.Substring(1, inputString.Length - 2));
       }
       else
       {
        return false;
       }
       break;
     }
    }

  • Andrew Clinick - Demo of Visual Studio Tools for Office 2005

    The Channel 9 Team wrote:
    Developing apps for Microsoft Word and Excel hasn't been as easy as it could be. That's about to change with the new Visual Studio Tools for Office. Andrew Clinick gives us a "first look" demo.


    Very well done!

    But one little thing, I hope the winform controls are also rendered on paper?


    Peter
  • Rajesh George - Three new features in SQL Server Express

    So, where is the Express Manager tool when it's downloadable?

    Thanks,
    Peter