Advertisement
Guest User

FizzBuzzWithoutNumbers

a guest
Nov 19th, 2015
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. ZERO = None
  2.  
  3. def succ(prior):
  4.   return [prior]
  5.  
  6. def pred(x):
  7.   for val in x:
  8.     return val
  9.   raise Exception("Nope")
  10.  
  11. ONE = succ(ZERO)
  12. TWO = succ(ONE)
  13. THREE = succ(TWO)
  14. FOUR = succ(THREE)
  15. FIVE = succ(FOUR)
  16. SIX = succ(FIVE)
  17. SEVEN = succ(SIX)
  18. EIGHT = succ(SEVEN)
  19. NINE = succ(EIGHT)
  20. TEN = succ(NINE)
  21.  
  22. def add(a, b):
  23.     x = a
  24.     y = b
  25.     while x is not None:
  26.         x = pred(x)
  27.         y = [y]
  28.     return y
  29.  
  30. def multiply(a,b):
  31.     x = a
  32.     y = None
  33.     while x is not None:
  34.       x = pred(x)
  35.       y = add(y, b)
  36.     return y
  37.  
  38. def roman_digits_pattern(lo, hi, hihi):
  39.     return [
  40.         '',
  41.         lo,
  42.         "".join([lo, lo]),
  43.         "".join([lo, lo, lo]),
  44.         "".join([lo, hi]),
  45.         hi,
  46.         "".join([hi, lo]),
  47.         "".join([hi, lo, lo]),
  48.         "".join([hi, lo, lo, lo]),
  49.         "".join([lo, hihi])
  50.     ]
  51.  
  52. def build_roman_table():
  53.     tens = roman_digits_pattern('I', 'V', 'X')
  54.     hundreds = roman_digits_pattern('X', 'L', 'C')
  55.     thousands = roman_digits_pattern('C', 'D', 'M')
  56.     table = []
  57.     for a in thousands:
  58.         for b in hundreds:
  59.             for c in tens:
  60.                 table.append("".join([a,b,c]))
  61.     return table
  62.  
  63. ROMAN_DIGITS = build_roman_table()
  64.  
  65. def print_number(x):
  66.     z = x
  67.     for digit in ROMAN_DIGITS:
  68.         if z is None:
  69.             print(digit)
  70.             return
  71.         z = pred(z)
  72.  
  73. def fizz_buzz(limit):
  74.     div_by_five = FOUR
  75.     div_by_three = TWO
  76.     at = ONE
  77.     x = limit
  78.     while x is not None:
  79.         x = pred(x)
  80.         result = []
  81.         show_number = True
  82.         if div_by_three is None:
  83.             show_number = False
  84.             div_by_three = THREE
  85.             result.append("Fizz")
  86.         if div_by_five is None:
  87.             show_number = False
  88.             div_by_five = FIVE
  89.             result.append("Buzz")
  90.         if show_number:
  91.             print_number(at)
  92.         else:
  93.             print("".join(result))
  94.         div_by_three = pred(div_by_three)
  95.         div_by_five = pred(div_by_five)
  96.         at = succ(at)      
  97.  
  98. ONE_HUNDRED = multiply(TEN, TEN)
  99. fizz_buzz(ONE_HUNDRED)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement