The Artima Developer Community
Sponsored Link

Agile Buzz Forum
FizzBuzz Station

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Oliver Steele

Posts: 112
Nickname: ows
Registered: Aug, 2003

Oliver Steele is Chief Software Architect at Laszlo Systems, Inc.
FizzBuzz Station Posted: Feb 28, 2008 8:02 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Oliver Steele.
Original Post: FizzBuzz Station
Feed Title: Oliver Steele on Software
Feed URL: http://feeds.feedburner.com/osteele
Feed Description: Languages of the real and artificial.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Oliver Steele
Latest Posts From Oliver Steele on Software

Advertisement

Uh oh! I overthought fizzbuzz.


The following Ruby snippets aren’t quite the same as the automaton above (this Haskell version is actually closest to that), but here’s a couple of Regexp solutions in a style that I haven’t seen before. They have a kind of Turing-tape flavor to them. I’m not much of a golfer, so please let me know in the comments if you tighten them up any.


puts (1..100).map { |n| '1'*n+":#{n}\n" }.join.
  gsub(/^(1{5})*:/,'\0Buzz').gsub(/^(1{3})*:/,'Fizz').gsub(/.*:|(z)\d+/,'\1')

puts (1..100).map { |n| 'x'*n+"#{n}\n" }.join.
  gsub(/^(xxx)*\d/,'Fizz').gsub(/[05]$/,'Buzz').gsub(/^x*|\d*(.+?)\d*/,'\1')

Read: FizzBuzz Station

Topic: Sydney Smalltalk users group Previous Topic   Next Topic Topic: Cue the Angry Hordes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use