News for hackers. Stuff that matters.

lostnbored

Re:FizzBuzz Enterprise Edition on Sunday December 21, 2014 @11:58PM (#8782061)
Here is an implementation in Python with only one operator

  # Inputs
  >>> i = range(1, 100)
  >>> d = [(15, 'FizzBuzz'), (5, 'Buzz'), (3, 'Fizz')]

  # Let's define some lambdas - calculation, test, reduction
  >>> c = lambda x, y: y[1] if (x % y[0] == 0) else x
  >>> t = lambda a, b:  a if type(a) is str else b
  >>> r = lambda e: reduce(t, e)

  # Now process
  >>> map(r, map(lambda x: map(lambda f: c(x, f), d), i))