Skip to content

Instantly share code, notes, and snippets.

@shenfeng
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save shenfeng/bd83f16e60ca16a8cbc3 to your computer and use it in GitHub Desktop.

Select an option

Save shenfeng/bd83f16e60ca16a8cbc3 to your computer and use it in GitHub Desktop.

Revisions

  1. shenfeng revised this gist Apr 30, 2014. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions tw.py
    Original 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]]

    r = ''.join(mapping[i] for i in specials if n % i == 0)
    if r:
    return r # rule 3, 4

    return str(n)
    return ''.join(mapping[i] for i in specials if n % i == 0) or str(n)


    def test():
  2. shenfeng created this gist Apr 30, 2014.
    65 changes: 65 additions & 0 deletions tw.py
    Original 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()