Ruby Programming Challenge For Newbies
RPCFN: Average Arrival Time For A Flight (#2)
– By Chris Strom
Thank you for the very encouraging response to the first-ever “Ruby Programming Challenge For Newbies (RPCFN)“. The second Ruby challenge is from Chris Strom.
About Chris Strom
Chris Strom (twitter / blog) in his day job, is the Director of Software Engineering for mdlogix, a small company in Baltimore, Maryland. They develop software that manages clinical research trials and associated data. They primarily code with Ruby on Rails. His background is in web development, mostly in Perl until ~2005 when he made the switch to Ruby.
Chris has this to say about the challenge:
RPCFN is a good idea as reading books and documentation can only take you so far when learning a new language. To really learn, you need to use the language. RPCFN provides a fabulous forum for using Ruby in the form of regular, engaging (but not arcanely difficult) challenges. Better yet, it provides feedback on how to use Ruby well, as each fortnight the best solution to a challenge is chosen. RPCFN is a wonderful introduction to the Ruby language and to the Ruby community. Welcome newbies!
This fortnights programming challenge is sponsored by Railsware. Railsware is glad to support the Ruby Programming Challenge and help the Ruby community grow and get stronger.
Railsware is a product development company specializing in Ruby on Rails and UI design creating premium-quality web applications. The company works with startups and established businesses looking to build ecommerce, social networking, specialized business applications and many other products.
- The person with the best Ruby solution (if there is a tie between answers, then the one who posted first will be the winner) will be awarded any one of PeepCode’s Ruby on Rails screencasts.
- The other prize, selected randomly amongst the remaining working Ruby solutions, will be awarded any one of BDDCasts’ screencasts.
The two persons who win, can’t win again in the next immediate challenge but can still participate.
The Ruby Challenge
You owe a big favor and have agreed to pick up a friend at the airport every Friday night. The airline on which your friend flies is cheap, but terrible with reporting delays and departure/arrival times. You soon realize that the 10pm flight is never on time and is usually late by more than an hour. If the plane has arrived at 11:15pm, 12:03am, 11:30pm, 11:23pm and 11:48pm, what is the average arrival time?
Does the solution still work if your friend changes to a flight arriving 6 hours later? What about 12 hours later?
The output should look something like this when run from the console:
>> average_time_of_day(["11:51pm", "11:56pm", "12:01am", "12:06am", "12:11am"]) => "12:01am" >> average_time_of_day(["6:41am", "6:51am", "7:01am"]) => "6:51am"
- Your digital ways will not help you, time of day is cyclical.
- You may need to use the Math and Time classes.
Requirements: This has to be a pure Ruby script, using only the Ruby Standard Libraries (meaning, no external Gems). You do not need to build a gem for this. Pure Ruby code is all that is needed.
How to Enter the Challenge
Read the Challenge Rules. By participating in this challenge, you agree to be bound by these Challenge Rules. It’s free and registration is optional. You can enter the challenge just by posting the following as a comment to this blog post:
- Your name:
- Email address (will not be published):
- Brief description of what you do (will not be published):
- Country of Residence:
- GIST URL of your Solution (i.e. Ruby code) with explanation and / or test cases:
- Code works with Ruby 1.8 / 1.9 / Both:
- As soon as we receive your GIST URL, we will fork your submission. This means that your solution is frozen and accepted. Please be sure that is the solution you want, as it is now recorded in time and is the version that will be evaluated.
- All solutions posted would be hidden to allow participants to come up with their own solutions.
- You should post your entries before midnight of 18th Oct. 2009 (Indian Standard Time). No new solutions will be accepted from 19th to 22nd Oct. 2009.
- On Monday, 19th Oct. 2009 all the solutions will be thrown open for everyone to see and comment upon.
- The winning entries will be announced on this blog on 22nd Oct. The winners will be sent their prizes by email.
More details on the RPCFN?
Please refer to the RPCFN FAQ for answers to the following questions:
- What Is The Ruby Programming Challenge For Newbies (RPCFN)?
- How does RPCFN benefit you?
- Challenge Rules
- Best Solution
- Can I Submit A Ruby Programming Challenge Topic?
RPCFN is entirely financed by RubyLearning and sometimes sponsors, so if you enjoy solving Ruby problems and would like to give something back by helping with the running costs then any donations are gratefully received.
Special thanks to:
- Chris Strom.
- Sponsor Railsware.
- Jeff Schoolcraft of BDDCasts.
- The RubyLearning team, namely Dave Lilley (New Zealand), Jeff Savin (Canada), Michael Kohl (Austria), Peter Crawford (Italy), Satoshi Asakawa (Japan) and Victor Goff (USA).
- Giordano Scalzo
- Jonathan Julian
- Loïc Paillotin
Contact Satish Talim at firstname.lastname@example.org OR if you have any doubts / questions about the challenge (the current problem statement), please post them as comments to this post and the author will reply asap.
There are two categories of participants. Some are vying for the prizes and some are participating for the fun of it.
In the competition
- Othmane Benkirane, Morocco – declared winner
- Tisho Georgiev, Bulgaria
- Pete Campbell, USA
- Jonathan Julian, USA
- Antonio, Canada
- Robison WR Santos, Brazil
- Ricardo Duarte, Brazil
- Paul Barry, USA
- Haris Amin, USA
- Charles Feduke, USA – declared winner
- Oliver, UK
- Bryan Liles, USA
- Gunther Diemant, Germany
- Valério Farias, Brazil
- Vikas Maskeri, India
- Jiren Patel, India
- Stefan, Germany
- Ahmed Al Hafoudh, Slovakia
- Tom Voltz, USA
- David Jenkins, USA
- Michael Lang, USA
- Thiago Fernandes Massa, Brazil
- Tim Rand, USA
- Milan Dobrota, Serbia
- Mike Hodgson, Canada
- Brad O’Connor, Australia
- Giordano Scalzo, Italy
- Rainer Thiel, New Zealand
- Todd Huss, USA
- Pankaj Sisodiya, India
- Loïc Paillotin, USA
- Chuck Ha, USA
- Josh Baxley, USA
- Javier Blanco Gutiérrez, Spain
- Sogo Ohta, Japan
- Daniel Wanek, USA
- Himansu Desai, USA
- John McDonald, USA
- Ben Miller, UK
- Sriram Varahan, India
- Conner Peirce, USA
- Ben Marini, USA
Just for Fun
- Michael Kohl, Austria
- Peter Cooper, UK
Congratulations to the winners of this Ruby Challenge. They are:
- Charles Feduke from USA (his Ruby Challenge solution) – the person with the best Ruby solution. He wins any one of PeepCode’s Ruby on Rails screencasts.
- Othmane Benkirane from Morocco (his Ruby Challenge solution) – selected randomly amongst the remaining working Ruby solutions. He wins any one of BDDCasts’ screencasts.
RPCFN: Shift Subtitle (#1) by Fabio Akita.
RPCFN: Short Circuit (#3) by Gautam Rege.
- This Challenge is now closed. Chris Strom has a working solution to this problem. This is not a “perfect” or the sole “correct” solution, but just one way of doing it.
- Chris Strom has written a blog post that talks about the most common “issues” faced by Ruby beginners.
- The (#3) challenge by Gautam Rege, India is scheduled for 1st Nov. 2009.
- The (#4) challenge by Michael Kohl, Austria is scheduled for 1st Dec. 2009.
- The (#5) challenge by Peter Cooper, UK is scheduled for 1st Jan. 2010.