@@ -0,0 +1,1799 @@
+%22%22%22%0AI18N is an abbreviation for 'internationalization', which begins with 'i', ends%0Awith 'n', and has 18 other letters in between.  Find all ways to condense any number%0Anon-contiguous substrings in 'internationalization' or any other string.  E.g., for%0A'internationalization', return:%0A%0Ai18n%0Ain17n%0A...%0Ainter3ion2iza3n%0A...%0A%0A%0ALoop invariant: at any level in _condense, a prefix has been formed by previous calls.%0AThis prefix is a partial result, and it always ends in a letter and is composed of%0Aintegers and letters with no two integers being neighbors.%0A%0ATherefore, returning a suffix that starts with an integer or letter and has no neighboring%0Aintegers will ensure an overall result that has no neighboring integers.%0A%22%22%22%0A%0A%0Adef condense(word):%0A    if len(word) %3C= 3:%0A        return %5Bword%5D%0A%0A    first, last, rest = word%5B0%5D, word%5B-1%5D, word%5B1:-1%5D%0A    return %5Bfirst + mid + last for mid in _condense(rest)%5D%0A%0A%0Adef _condense(word):%0A    if not word:%0A        return %5B''%5D%0A%0A    condense_whole_word = %5Bstr(len(word))%5D%0A    keep_first_char = %5B'%7B%7D%7B%7D'.format(word%5B0%5D, rest) for rest in _condense(word%5B1:%5D)%5D%0A    condense_all_prefixes = %5B'%7B%7D%7B%7D%7B%7D'.format(str(i), word%5Bi%5D, rest)%0A                             for i in xrange(1, len(word))%0A                             for rest in _condense(word%5Bi+1:%5D)%5D%0A    # more accurately: condense all proper prefixes (a prefix that's not the whole word)%0A    return condense_whole_word + keep_first_char + condense_all_prefixes%0A%0A%0Adef tests():%0A    assert condense('zzz') == %5B'zzz'%5D%0A    assert sorted(condense('zaaaz')) == sorted(%5B'z3z', 'za2z', 'z1a1z', 'z2az', 'zaa1z', 'za1az', 'z1aaz', 'zaaaz'%5D)%0A    # assert 'inter3ion2iza3n' in condense('internationalization')%0A    # commented out test passes but is long-running%0A%0A    print 'tests pass!'%0A%0A%0Aif __name__ == '__main__':%0A    tests()%0A

add i18n.py