Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Philip Fitzsimons

Philip Fitzsimons Figment​Engine Figment​Engine

Niner since 2008

  • Countdown to PDC2008: Secrets Revealed

    "when ordering samples from out entire collection, be sure to start with the correct seed"

    hmm, interesting

    "sample" and wave files... and "order" with "entire collection"
    implies data might be held at perfect number offsets in the data chunk?
  • Gary Daniels and Evan Goldring - Mock whiteboard problem

    Very, very late ;-) this handles whitespace and number etc (closer to a real palindrome rather than byte symmetry)


    static bool IsPalindrome(string subject)
    {
    const int STEP_FORWARD = 1;
    const int STEP_BACKWARD = -STEP_FORWARD;
    const int BEFORE_START = -1;
    const int CHAR_AT_A_TIME = 1;
    const int COMPARE_EQUALS = 0;




    // assume its not a palindrome
    bool result = false;


    // how to compare
    CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
    CompareOptions co =
    CompareOptions.IgnoreCase |
    CompareOptions.IgnoreKanaType |
    CompareOptions.IgnoreNonSpace |
    CompareOptions.IgnoreSymbols |
    CompareOptions.IgnoreWidth;


    // null strings are not palindromes
    if (subject != null)
    {
    int AFTER_END = subject.Length;

    // single letter words are palindromes
    result = (AFTER_END == 1 && IsPalindromeChar(subject[0]));

    // start the comparison points at valid characters
    int startOffset = GetNextValidCharacter(subject, BEFORE_START, STEP_FORWARD, AFTER_END);
    int endOffset = GetNextValidCharacter(subject, AFTER_END, STEP_BACKWARD, BEFORE_START);

    while (startOffset < endOffset)
    {
    result = ci.Compare(subject, startOffset, CHAR_AT_A_TIME, subject, endOffset, CHAR_AT_A_TIME, co) == COMPARE_EQUALS;

    if (!result)
    break;


    // move the comparison points towards each other
    startOffset = GetNextValidCharacter(subject, startOffset, STEP_FORWARD, endOffset);
    endOffset = GetNextValidCharacter(subject, endOffset, STEP_BACKWARD, startOffset);
    }
    }

    return result;
    }


    static int GetNextValidCharacter(string subject, int offset, int step, int bound)
    {
    if (offset != bound)
    offset += step;

    while (offset != bound && !IsPalindromeChar(subject[offset]))
    offset += step;

    return offset;
    }

    static bool IsPalindromeChar(char c)
    {
    return char.IsLetter(c) || char.IsDigit(c);
    }

    more on palindromes on my blog