Last active
August 29, 2015 14:00
-
-
Save shenfeng/bd83f16e60ca16a8cbc3 to your computer and use it in GitHub Desktop.
Revisions
-
shenfeng revised this gist
Apr 30, 2014 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,7 @@ def transform(specials, mapping, n): if str(specials[0]) in str(n): return mapping[specials[0]] return ''.join(mapping[i] for i in specials if n % i == 0) or str(n) def test(): -
shenfeng created this gist
Apr 30, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ def transform(specials, mapping, n): """ https://www.jinshuju.net/f/EGQL3D """ # rule 5 if str(specials[0]) in str(n): return mapping[specials[0]] r = ''.join(mapping[i] for i in specials if n % i == 0) if r: return r # rule 3, 4 return str(n) def test(): right_answers = """ 1 2 Fizz 4 Buzz Fizz Whizz 8 Fizz Buzz 11 Fizz Fizz Whizz FizzBuzz 16 17 Fizz 19 Buzz """ specials = [3, 5, 7] mapping = {3: 'Fizz', 5: 'Buzz', 7: 'Whizz'} right_answers = [line.strip() for line in right_answers.split('\n') if line.strip()] for i in range(1, len(right_answers)): assert transform(specials, mapping, i) == right_answers[i - 1] print 'test pass' def main(): specials = [] while len(specials) != 3: raw = raw_input('input three less than 10 numbers: ') specials = [int(n) for n in raw.split(' ') if n.isdigit() and int(n) < 10] mapping = dict(zip(specials, ['Fizz', 'Buzz', 'Whizz'])) for i in range(1, 100): print transform(specials, mapping, i) if __name__ == "__main__": test() main()