Click here to Skip to main content
12,951,619 members (56,883 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

8K views
Posted 2 Apr 2011

Solving Facebook Programming Puzzles using Ruby

, 2 Apr 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
I really enjoy solving puzzles. That’s probably what drove me to becoming a software developer. So I was thrilled to learn that Facebook has a series of programming puzzles. Once you solve a puzzle, you email your code to Facebook and they email you back your results.

I really enjoy solving puzzles. That’s probably what drove me to becoming a software developer. So I was thrilled to learn that Facebook has a series of programming puzzles. Once you solve a puzzle, you email your code to Facebook and they email you back your results. What follows are the steps that I took to get my computer setup, solve my first puzzle, and submit it to Facebook for testing. It’s important to note that while I primarily work in the .NET world, the Facebook Puzzle bot doesn’t do .NET. This gave the opportunity choose a new language to learn from their list of supported languages (I chose Ruby).

General information about the Facebook Puzzles are at http://www.facebook.com/careers/puzzles.php

  1. Download Ruby-1.8.6 from http://www.ruby-lang.org/en/downloads/
  2. Next I picked the puzzle I was going to work on. For my first one I picked Hoppity http://www.facebook.com/careers/puzzles.php#!/careers/puzzles.php?puzzle_id=7
  3. My solution looked like this:

    #!/usr/bin/env ruby
    n = File.open(ARGV[0]).gets.to_i
    1.upto(n) do |i|
        if i % 3 == 0 && i % 5 == 0
            print "Hop\n"
        elsif i % 3 == 0
            print "Hoppity\n"
        elsif i % 5 == 0
            print "Hophop\n"
        end
    end
  4. Then I saved the solution to a file named the same as the keyword on the Facebook puzzles page. In this case, hoppity with no file extension. Source files from scripted languages shouldn’t have a file extension when they are submitted.
  5. You can test the solution by creating a sample input file and calling Ruby from the Ruby command line like this:

    David Eisenstat has some more information on his site http://www.davideisenstat.com/fbpfaq/. Including more information on how to submit solutions for compiled languages.

  6. Finally, email the file to {0xFACEB00C>>2 in decimal}@fb.com (or 1051962371@fb.com). Once the puzzle engine processes your submission you’ll receive an email with the results.

I hope that you enjoy solving these puzzles as much as I do. And who knows, maybe you’ll even learn something. ;-)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pete Mourfield
Software Developer (Senior)
United States United States
Software Developer

You may also be interested in...

Pro

Comments and Discussions

 
GeneralInteresting Pin
Tariq Newaz Shahriar28-Nov-13 7:32
memberTariq Newaz Shahriar28-Nov-13 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170525.1 | Last Updated 3 Apr 2011
Article Copyright 2011 by Pete Mourfield
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid