Created
May 22, 2012 21:39
-
-
Save killerswan/2771778 to your computer and use it in GitHub Desktop.
Inverse Fizz Buzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Kevin Cantu | |
| # | |
| # inverse fizz buzz, per David Bell's comment | |
| # http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html | |
| def makeOffsets(num): | |
| off = [3,5,6,9,10,12,15] | |
| acc = [] | |
| for x in range(num/7 + 2): | |
| acc += map((lambda n: n + 15 * x), off) | |
| return acc | |
| def makeRef(num): | |
| ref = 'fbffbfx' | |
| acc = '' | |
| for x in range(num/7 + 2): | |
| acc += ref | |
| return acc | |
| def startIndexRef(seq): | |
| ref = makeRef(len(seq)) | |
| return str.find(ref, seq) | |
| def getRange(seq): | |
| startIndex = startIndexRef(seq) | |
| offsets = makeOffsets(len(seq)) | |
| start = offsets[startIndex] | |
| end = offsets[startIndex + len(seq)] | |
| return range(start, end) | |
| def printRange(seq): | |
| r = getRange(seq) | |
| print seq, ":", r | |
| if __name__ == '__main__': | |
| map(printRange, [ | |
| 'f', | |
| 'b', | |
| 'fb', | |
| 'bf', | |
| 'fbf', | |
| 'ff', | |
| 'ffb', | |
| 'bff', | |
| 'ffbfxfbf', | |
| 'xxf' | |
| ]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment