Note: This article first appeared on 8th Oct. 2009 but the original is not accessible; hence the reprint.

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-everRuby Programming Challenge For Newbies (RPCFN)“. The second Ruby challenge is from Chris Strom.

About Chris Strom

Chris StromChris 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!

Sponsor

Railsware for premium-quality web applications

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.

Prizes

  • 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

RPCFN

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?

Program Output

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"

Hint

  • 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:

  1. Your name:
  2. Email address (will not be published):
  3. Brief description of what you do (will not be published):
  4. Country of Residence:
  5. GIST URL of your Solution (i.e. Ruby code) with explanation and / or test cases:
  6. Code works with Ruby 1.8 / 1.9 / Both:

Note:

  • 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:

Donations

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.

Acknowledgements

Special thanks to:

Questions?

Contact Satish Talim at satish.talim@gmail.com 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.

The Participants

There are two categories of participants. Some are vying for the prizes and some are participating for the fun of it.

In the competition

  1. Othmane Benkirane, Morocco – declared winner
  2. Tisho Georgiev, Bulgaria
  3. Pete Campbell, USA
  4. Jonathan Julian, USA
  5. Antonio, Canada
  6. Robison WR Santos, Brazil
  7. Ricardo Duarte, Brazil
  8. Paul Barry, USA
  9. Haris Amin, USA
  10. Charles Feduke, USA – declared winner
  11. Oliver, UK
  12. Bryan Liles, USA
  13. Gunther Diemant, Germany
  14. Valério Farias, Brazil
  15. Vikas Maskeri, India
  16. Jiren Patel, India
  17. Stefan, Germany
  18. Ahmed Al Hafoudh, Slovakia
  19. Tom Voltz, USA
  20. David Jenkins, USA
  21. Michael Lang, USA
  22. Thiago Fernandes Massa, Brazil
  23. Tim Rand, USA
  24. Milan Dobrota, Serbia
  25. Mike Hodgson, Canada
  26. Brad O’Connor, Australia
  27. Giordano Scalzo, Italy
  28. Rainer Thiel, New Zealand
  29. Todd Huss, USA
  30. Pankaj Sisodiya, India
  31. Loïc Paillotin, USA
  32. Chuck Ha, USA
  33. Josh Baxley, USA
  34. Javier Blanco Gutiérrez, Spain
  35. Sogo Ohta, Japan
  36. Daniel Wanek, USA
  37. Himansu Desai, USA
  38. John McDonald, USA
  39. Ben Miller, UK
  40. Sriram Varahan, India
  41. Conner Peirce, USA
  42. Ben Marini, USA

Just for Fun

  1. Michael Kohl, Austria
  2. Peter Cooper, UK

The Winners

Winners

Congratulations to the winners of this Ruby Challenge. They are:

Previous Challenge

RPCFN: Shift Subtitle (#1) by Fabio Akita.

Next Challenge

RPCFN: Short Circuit (#3) by Gautam Rege.

Update

  • 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.

Technorati Tags: , , , , ,

Posted by Satish Talim

{ 0 comments }

Note: This article first appeared on 8th Oct. 2009 but the original is not accessible; hence the reprint.

In this brief interview, Satish Talim of RubyLearning talks to Felipe Elias Philipp of Brazil, winner of the first-ever Ruby Programming Challenge For Newbies.

Felipe Elias Philipp

Satish>> Welcome Felipe and thanks for taking out time to share your thoughts. For the benefit of the readers, could you tell us something about your self?

Felipe>> Thanks Satish for the opportunity. Well, about me… I’m a Brazilian guy, a web developer and a Mac user. I’m 22 years old and I started to program at school, since I was 16. Since then, programming has become my life and I can’t imagine myself doing any other thing.

Satish>> How did you get involved with Ruby programming?

Felipe>> I discovered Ruby through Rails on a well-known website by Brazilians: iMasters. I was just amazed as it was so easy to understand the Ruby code and I could solve the problems in a very simple way. This got me very motivated and I became more interested in the subject. At that time, I was working with ASP and I was deciding whether to learn Java or .NET. By then, I had realized that Ruby was simpler and I decided to learn it.

Satish>> Could you name three features of Ruby that you like the most, as compared to other languages? Why?

Felipe>> One of the things that caught my attention was the fact that Ruby is an extremely dynamic language. The way I can open classes and add my own methods is one of the features I like most. Creating DSLs was something I had never seen before and which I found very interesting. These are some of the features I remember at the moment, although I like almost everything in the language.

Satish>> How was experience of taking part in the Ruby Programming Challenge For Newbies (RPCFN)?

Felipe>> Despite knowing Ruby for almost two years, I had never written more than 50 lines of code. I had not found a project that motivated me to practice. However the RPCFN aroused me! Also, I enjoyed the challenge very much. I recommend everybody to take part in the RPCFN. Even if you know the language, there is always something new to learn. I intend to participate in all the forthcoming challenges.

Satish>> What are your future plans?

Felipe>> I want to study Ruby and Rails deeper, and also learn other languages (Python and Erlang are already on my list). In the short ter, I intend to share whatever I learn about Ruby and about programming in general; perhaps starting my own blog or something else.

Thank you Felipe. In case you have any queries and/or questions, kindly post your questions here (as comments to this blog post) and Felipe would be glad to answer.

Technorati Tags: , , , ,

Posted by Satish Talim

{ 0 comments }

RPCFN: Shift Subtitle (#1) – Reprint

January 25, 2015

Ruby Programming Challenge For Newbies RPCFN: Shift Subtitle (#1) By Fabio Akita Note: This article first appeared on 24th Sept. 2009 but the original is not accessible; hence the reprint. After a very encouraging response to our poll from YOU, the readers of the RL blog, RL is happy to announce the first-ever fortnightly ( […]

Read the full article →

RPCFN: Ruby Programming Challenge For Newbies (Reprint)

January 25, 2015

RPCFN: Ruby Programming Challenge For Newbies Note: This article first appeared on 20th Sept. 2009 but the original is not accessible; hence the reprint. After a very encouraging response to our poll from YOU, the readers of the RL blog, RL is happy to announce the first-ever fortnightly (every 14 days) “Ruby Programming Challenge For […]

Read the full article →

What are the Twelve Rules of Sinatra? (Reprint)

January 24, 2015

Note: This article first appeared on 19th July. 2009 but the original is not accessible; hence the reprint. The Twelve Rules of Sinatra The Twelve Rules of Sinatra: Download this as a Free Report. Recently, I was reading Scott Adams’ (of Dilbert fame) blog post “Rule of Twelve” where he stated: The Rule of Twelve […]

Read the full article →