Fizz, buzz, fizzbuzz

Feb 06 2008

I was hit by a simple question today: write a fizzbuzz in ruby. Pretty fun anyway.

What’s Fizzbuzz?

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

I started from this:

class Fixnum
...
end

I think it was a little overkill and slow the coding speed a lot. Here is the result:

def fizzbuzz
(1..100).each { |item|
puts print_value(item)
}
end

def print_value(item)
print_value = ''
print_value += 'Fizz' if item.div_by_3?
print_value += 'Buzz' if item.div_by_5?
print_value.empty? ? item : print_value
end

class Fixnum
def div_by_3?
self % 3 == 0
end

def div_by_5?
self % 5 == 0
end
end

fizzbuzz

Here are some simple samples from internet:
One liner:

1.upto(100) { |n| puts n % 3 == 0 ? n % 5 == 0 ? "fizzbuzz" : "buzz" : n % 5 == 0 ? "fizz" : n }

Another one liner:

puts (1..100).to_a.collect { |i| i % 15 == 0 ? ‘fizzbuzz’ : (i % 5 == 0 ? ‘fizz’ : (i % 3 == 0 ? ‘buzz’ : i)) }.join(’ ‘)

One more one liner

puts (1..100).map{|i|i%15==0?’FizzBuzz’:i%5==0?’Buzz’:i%3==0?’Fizz’:i}

Regular one, pretty close to mine:

(1..100).each{|i|
x = ''
x += 'Fizz' if i%3==0
x += 'Buzz' if i%5==0
puts(x.empty? ? i : x);
}

Want to know more?

  1. Coding Horror:  Why Can’t Programmers.. Program?
  2. Imran On Tech: Using FizzBuzz to Find Developers who Grok Coding
  3. Wikipedia: Bizz buzz
  4. RubyQuiz: FizzBuzz (#126)

Go back to practice more, and more…

2 responses so far

links for 2008-02-06

Feb 06 2008

No responses yet

恭祝新年快乐!2008万事如意!

Feb 06 2008

过年了!新春快乐!恭喜发财!

No responses yet

DemoCamp Toronto 17 is open to register

Feb 05 2008

DemoCamp Toronto 17 will be hosted in Toronto Board of Trade, 1 First Canadian Place again on Monday, February 25th, 2008.

It is open to register now. Please hurry up to get your ticket from http://democamp.eventbrite.com/

If you can’t make it this time, please come back here later. I will cover this event for sure.

What’s Democamp Toronto?

DemoCamp is a variation of the un-conference style of event, started by the TorCamp group as an excuse to have more regular meetings where community members share what they’ve been working on, demo their products, meet others (and share a drink or 3).

What’s TorCamp?

TorCamp is a remarkable community of people in the Toronto area – a community of designers, developers, marketers, PR people, executives, testers, quality assurance specialists, consultants, recruiters, network administrators, business developers, venture capitalists, angel investors, policy analysts, etc. Since the first TorCamp event in November 2005, TorCampers have congregated at least once and often five or ten times a month in conference centers, cafes and parks to share ideas and look for unexpected aha! connections of people and ideas. And it’s not just about BarCamp events: if you look at the hottest things going on in the Toronto Tech community, you’ll usually find a TorCamper among the instigators.

What’s the rule? We have a rule? Yes.

The rules are pretty simple. Demos are 5 minutes. There is generally no Powerpoint for Demos, if there is to be Powerpoint it must be approved by the stewards. Ignite presentations are 5 minutes. They are 20 slides x 15 seconds/slide and the presenter does not have control over the slide advancement. All Ignite decks must be submitted to the stewards before the event.

Should I attend?

  • If you want to know what are the hottest things happening in Toronto Tech community
  • If you want to show some super cool things you are working on

See you there! :)

No responses yet

links for 2008-02-05

Feb 05 2008

No responses yet

FacebookCamp Toronto 3

Feb 05 2008

Just came back from FacebookCamp Toronto 3. It was absolutely another great event again!

As you can see here, there were more than 400 people from Toronto or around area attended this camp. Actually FacebookCamp Toronto is the biggest Facebook Developer Garage in the whole world so far. Pretty amazing!

I’ve uploaded all the photos I’ve taken onto FacebookCamp Event page, please check out them here: http://www.facebook.com/photo_search.php?oid=9090547740&view=all

Here is the links to the detail pages:

http://www.facebook.com/group.php?gid=2411884086 (Group)

http://www.facebook.com/event.php?eid=9090547740 (Event)

http://barcamp.org/FacebookCampToronto3 (Agenda and detail wiki page)

The actual agenda was pretty much the same as the wiki one, except Dave’s keynote has been moved after “Facebook vs OpenSocial” as he was stuck in the traffic.

  • Intro – update from last FBCT (Roy/Colin/Andrew)

Facebook gets bigger and bigger, Facebook users in Canada get more and more…

  • Facebook Pages Case Study ( Andrew Cherwenka, Trapeze Media )

Even a Facebook Page can make a success marketing story too!

  • Bebo Facebook Application ( Roy Pereira & Colin Smillie, refresh partners )

First website who has licensed Facebook API. Transferring apps from Facebook to Bebo is not that easy now, but it’s getting better.

“Write once, run anywhere” is not exactly true. Damn!

  • ExtremeVP Introduction (Amar Varma)

I am on Facebook and I am using Mac!

“A lot of big things will happen on Facebook Platform, but I don’t tell you now.”

  • Website Marketing in Facebook Case Study ( Tim Shore, BlogTO )

Toronto Faves and Toronto Events, don’t miss them if you are in Toronto too.

Jay Goldman – Author of “Facebook Cookbook”. Check out his blog for more detail information on Facebook Beacons.

Demos: 5 minutes each ( 5 Slots, no more, see you next time)

Their status is COOL.

3D Scene on Facebook.

From Facebook President to ePresident.

I debate this will be big.

Serious business conference call for free.

What a wonderful time! See you next camp. :)

3 responses so far

links for 2008-02-04

Feb 04 2008

One response so far

links for 2008-02-03

Feb 03 2008

One response so far

The best Menu Items for Leopard – My Mac Serial 2

Feb 02 2008

This the second one of My Mac Serial posts. The first one is about Color Pickers.

What’s Menu Items?

WikiPedia: A Menu extra, menu item, menulet, or status item in Mac OS X is a small icon or sometimes a word that appears at the right of the menu bar. They often provide quick ways to use applications (e.g. iChat) or display information (for example the system clock), or control system-level variables (for example the volume control). There are a number of third party menu items available. Menu extras are similar to items in the Microsoft Windows system tray but are less common.

This is the current Menu bar I have. A little too long, yeah, I know. The resolution of my main screen is 1680×1050, so most of the time it is still OK for me to have such a mass Menu bar.

OK. Let’s talk about them. One by one from left to right:

  • Spotlight from Apple.
    Not that much need to be said again. Spotlight had a huge performance improvement in Leopard. The search and index processes are all much faster than it was in Tiger. Two features may be worth a highlight:

    • Spotlight in Leopard can search through your files on your network.
    • Spotlight window is same as Finder window, so you will have coverflow and quicklook too.
  • MenuCalendarClock from objectpark.
    The current version I have is for iCal, they do have another version for Entourage if you care. MenuCalendarClock make my life so much easier on handling my schedule and todos. As you can see in the screenshot, everything on your iCal is just one click away. You can simply find your detail events by click the highlighted date and more:

    • Create, update and complete todos
    • Search! through your schedule and todos
  • Built-in bluetooth menu item from Apple.
    Nothing special. I keep it just because sometime I have to turn bluetooth off and on again to find my MS Presenter mouse 8000.
  • Built-in input source menu item from Apple.
    Nothing special either. I need it so I will know what kind of input method before I am typing.
  • These three are all iStat Menus from iSlayer.com.
    It helps me to monitor my lovely MacBook at all the time, so I could know what’s going on in my system and make sure be cooler. The color? Yes, it is pink. Looks pretty, right? :)
  • WeatherPop from weatherpop.com.
    Simple and straight updates you about the weather of the multiple locations you want to know. If you are in USA, you will have a Radar view too, even better.
  • SwitchResX from (Miss?) Stéphane Madrau.
    It is extremely helpful if you use extra monitors and you change your locations often. It provides a lot short cuts on the menu, so you easily switch your main display, change resolutions, turn on/off Video Mirroring when you do presentation, save icons position of your desktop, detect displays if nothing happen after you plugin extra monitors and even more. Another very neat feature is it is very easy to change the rotation of your monitor. Of cause you need a monitor which supports this. So I can always turn my monitor from horizontal to vertical when I am reading blogs. Now a day blog posts are getting longer and longer. Such as the one you are reading now. :D
  • Built-in AirPort from Apple and WiFind from TastyApps.com.
    AirPort menu has little improvement in Leopard. It becomes much useful after you install WiFind. WiFind can tell you the signal strength of every wifi network you can reach, and are they open or not. WiFind supports Tiger too, and it integrates even better with AirPort Menu. In Tiger, you will only have one networks list instead of one list plus a submenu list too.
  • MUMENU from MacUpdate.com.
    It keeps me always uptodate on my mac applications. It is quite essential for somebody like me as an appaholic. As you can see in the screenshot, it will kindly show the application icons if you already have the application installed.
  • Freeze Frame from Elgebar Studios.
    Freeze Frame allows you to completely freeze an application, making it use absolutely no CPU cycles. I keep my applications always open at all the time. At some point I will have severial web pages open with flash in them, it will become annoying as they take a lot of your cpu time. So I can simply freeze my Firefox or Safari when I am doing other things.
  • Jumpcut is a opensource application. It is hosted at sourceforge right now. Jumpcut was original created by Mr. Steve Cook from snarkout.org. It is very simple but powerful enough. It provides quick, natural, intuitive access to your clipboard’s history. You can paste from your previous copy by just one click.
  • TextExpander from SmileOnMyMac.
    TextExpander saves you countless keystrokes with customized abbreviations for your frequently-used text strings and images. For example, instead of input “February 2, 2008″ you just type “ddate”,TextExpander will automatic change “ddate” to “February 2, 2008″. Yes, it just did it for me again. I really love their tagline for it, “If yor’re not using it, you are wasting time”. And I can tell you, it is true.
  • TrackTime from mamooba.
    I am using it to track how much time I spend on every projects, applications and websites. It has a very beautiful timeline interface. It even has some AppliScript APIs, so you can put it into your workflow then every time you open an application it will switch your tracking project too.
  • Wallpaper Clock from Jacob Bandes-Storch.
    It shows clock as part of your wallpaper in the most artistic way. VladStudio has more than 100 wallpaper clocks which you can choose from. You can even use them on windows too, by using Chameleon Clock from Softshape. Wallpaper Clock handles one of my screen and another screen is handled by the next one.
  • Desktoptopia from desktoptopia.com.
    Desktoptopia is a desktop background manager for the mac that automatically loads and displays designer desktops on your monitor, as often as you wish. desktoptopia.com currenly had more than 200 wallpapers you can use, everyone of them are very high quality and gorgeous. And you can even submit your own.
  • PTHVolume from PTH Consulting.
    We all have built-in sound volume control from Apple. But if you have more than one input devices or output devices, PTHVolume make it so much easier to switch between them.
  • Adium from adiumx.com.
    No need to say anything. Everybody on mac is using it. Adium is a free instant messaging application for Mac OS X that can connect to AIM, MSN, Jabber, Yahoo, and more.
  • Well, finally. Last but absolute not least. Skitch from plasq.
    I took all the snapshots by Skitch except the last one for itself, which it couldn’t do. I couldn’t image how much longer I need to finish this post without Skitch and Skitch.com. Simply grab a comment what I agree with:

I used to think a Mac was not a Mac without QuickSilver. Now it’s not a Mac without QuickSilver AND Skitch. It’s been like growing a thumb for the first time — how on earth did I ever live without Skitch before?! — Chris Messina

That’s it. Wow. Hope you can find something new here. :)

If you want more, here are some other links:

Britta Gustafson manages a extensive of Menu Items list on http://menu.jeweledplatypus.org/ and a faq page on http://menu.jeweledplatypus.org/meta/. The last updated time for that was 6/16/07, so it is out of date but still pretty complete.

4 responses so far

links for 2008-02-02

Feb 02 2008

No responses yet

« Newer - Older »