<story><title>Fizzbuzz, Interviews, And Overthinking</title><url>http://dave.fayr.am/posts/2012-10-4-finding-fizzbuzz.html</url></story><parent_chain><item><author>aristus</author><text>&lt;p&gt;&lt;pre&gt;&lt;code&gt;  cases = (
    (3, &apos;Fizz&apos;),
    (5, &apos;Buzz&apos;),
    (7, &apos;Bazz&apos;),
    (11, &apos;Boo&apos;),
    (13, &apos;Blip&apos;),
  )

  for i in range(1, 101):
      out = []
      for c in cases:
          if i % c[0] == 0:
              out.append(c[1])
      if out:
          print &apos;&apos;.join(out)
      else:
          print i

&lt;/code&gt;&lt;/pre&gt;
Edit: not to detract from the post&apos;s point, I think it&apos;s valid. Monoids are cool and all but simple counting arguments can take you a long, long, long, way when case analysis fails you.</text></item></parent_chain><comment><author>sowhatquestion</author><text>This can be edited down to six lines with a simple trick: a Python string multiplied by True will return itself, and multiplied by False will return the empty string.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  for i in range(110):
      pr = &quot;&quot;
      pr += &quot;Fizz&quot; * (i%3 == 0)
      pr += &quot;Buzz&quot; * (i%5 == 0)
      pr += &quot;Bazz&quot; * (i%7 == 0)
      print (pr if pr else i)
&lt;/code&gt;&lt;/pre&gt;
I iterated over range(110) to show that it handles the &quot;FizzBuzzBazz&quot; case correctly.&lt;p&gt;EDIT: Or we could use lambdas as OP&apos;s Ruby code did; this might be more maintainable...&lt;p&gt;&lt;pre&gt;&lt;code&gt;  cases = [
      lambda n: &quot;Fizz&quot; * (n%3 == 0),
      lambda n: &quot;Buzz&quot; * (n%5 == 0),
      lambda n: &quot;Bazz&quot; * (n%7 == 0) ]

  for i in range(110):
      pr = &quot;&quot;
      for case in cases:
          pr += case(i)
      print (pr if pr else i)
&lt;/code&gt;&lt;/pre&gt;
That&apos;s nine nonblank lines.</text></comment>
<story><title>Fizzbuzz, Interviews, And Overthinking</title><url>http://dave.fayr.am/posts/2012-10-4-finding-fizzbuzz.html</url></story><parent_chain><item><author>aristus</author><text>&lt;p&gt;&lt;pre&gt;&lt;code&gt;  cases = (
    (3, &apos;Fizz&apos;),
    (5, &apos;Buzz&apos;),
    (7, &apos;Bazz&apos;),
    (11, &apos;Boo&apos;),
    (13, &apos;Blip&apos;),
  )

  for i in range(1, 101):
      out = []
      for c in cases:
          if i % c[0] == 0:
              out.append(c[1])
      if out:
          print &apos;&apos;.join(out)
      else:
          print i

&lt;/code&gt;&lt;/pre&gt;
Edit: not to detract from the post&apos;s point, I think it&apos;s valid. Monoids are cool and all but simple counting arguments can take you a long, long, long, way when case analysis fails you.</text></item></parent_chain><comment><author>Xion</author><text>Precisely.&lt;p&gt;The Ruby solution author quotes as ideal and impressive seems way overblown to me. And I don&apos;t buy that ,,it would probably be dismissed as “overly complex” by younger programmers&apos;&apos; because it is exactly what I would consider perfect approach... few years ago. Since then I learned the value of simplicity, and abstractions with adequate flexibility.&lt;p&gt;That Ruby code exhibits neither.</text></comment>