GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/backtrack/generate_abbreviations.py at master · RajaRamu/algorithms Expand file tree/ Copy pathgenerate_abbreviations.pyMore file actions 26 lines (21 loc) · 642 Bytes / Copy pathgenerate_abbreviations.pyFile metadata and controls26 lines (21 loc) · 642 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 """ given input word, return the list of abbreviations. ex) word => [1ord, w1rd, wo1d, w2d, 3d, w3 ... etc] """ def generate_abbreviations(word): result = [] backtrack(result, word, 0, 0, "") return result def backtrack(result, word, pos, count, cur): if pos == len(word): if count > 0: cur += str(count) result.append(cur) return if count > 0: # add the current word backtrack(result, word, pos+1, 0, cur+str(count)+word[pos]) else: backtrack(result, word, pos+1, 0, cur+word[pos]) # skip the current word backtrack(result, word, pos+1, count+1, cur) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |