{"id":302,"date":"2014-10-02T20:52:47","date_gmt":"2014-10-02T20:52:47","guid":{"rendered":"https:\/\/www.lianeallen.com\/home\/?p=302"},"modified":"2014-10-02T20:52:47","modified_gmt":"2014-10-02T20:52:47","slug":"fun-with-fizzbuzz","status":"publish","type":"post","link":"https:\/\/www.lianeallen.com\/home\/2014\/10\/fun-with-fizzbuzz\/","title":{"rendered":"Fun with FizzBuzz"},"content":{"rendered":"<p>I decided to make FizzBuzz into something that reads (nominally) like English &#8230; because I&#8217;m easily amused. <\/p>\n<blockquote><p>\n<code>fizz_or_buzz = (1..100)<\/p>\n<p>fizzbuzz = fizz_or_buzz.map do |i|<br \/>\n&nbsp;&nbsp;not_fizzy = (i % 3 != 0)<br \/>\n&nbsp;&nbsp;not_buzzy = (i % 5 != 0)<br \/>\n&nbsp;&nbsp;no_fizz_no_buzz = i.to_s<br \/>\n&nbsp;&nbsp;when_fizzy = (i % 3)<br \/>\n&nbsp;&nbsp;when_buzzy = (i % 5)<\/p>\n<p>&nbsp;&nbsp;if not_fizzy && not_buzzy<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;fizziness = [no_fizz_no_buzz]<br \/>\n&nbsp;&nbsp;else<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;fizziness = [ [\"Fizz\"][when_fizzy], [\"Buzz\"][when_buzzy] ]<br \/>\n&nbsp;&nbsp;end<\/p>\n<p>&nbsp;&nbsp;fizziness.compact.join<br \/>\nend<\/p>\n<p>puts fizzbuzz<\/code>\n<\/p><\/blockquote>\n<p>There&#8217;s a fun little trick in the else clause, taking advantage of ruby&#8217;s handling of nil elements in a 2 element array. It&#8217;s a *really bad* coding practice, but fun to play with. You can see <a href=\"http:\/\/commandercoriander.net\/blog\/2013\/02\/03\/fizzbuzz-in-one-line\/\">an explanation of the nil handling here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided to make FizzBuzz into something that reads (nominally) like English &#8230; because I&#8217;m easily amused. fizz_or_buzz = (1..100) fizzbuzz = fizz_or_buzz.map do |i| &nbsp;&nbsp;not_fizzy = (i % 3 != 0) &nbsp;&nbsp;not_buzzy = (i % 5 != 0) &nbsp;&nbsp;no_fizz_no_buzz = i.to_s &nbsp;&nbsp;when_fizzy = (i % 3) &nbsp;&nbsp;when_buzzy = (i % 5) &nbsp;&nbsp;if not_fizzy &#038;&#038; &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.lianeallen.com\/home\/2014\/10\/fun-with-fizzbuzz\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fun with FizzBuzz&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":3,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"predecessor-version":[{"id":305,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/posts\/302\/revisions\/305"}],"wp:attachment":[{"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lianeallen.com\/home\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}