RPCFN: Economics 101 - 13
31/Aug 2010
Ruby Programming Challenge For Newbies
RPCFN: Economics 101 (#13)
– By Dr. Bruce Scharlau
About Dr. Bruce Scharlau
In Dr. Bruce’s own words: “I’ve been using and teaching Ruby since trying out the cookbook example in the summer of 2006. As soon as I saw how much easier it all was with Ruby and Rails, I was hooked. I now try to do as much with Ruby as I can with my teaching and own work. It’s a joy to code with Ruby compared to using other languages, which don’t seem as intuitive by comparison. When I’m not busy working, then I try to spend time with the family, or get out sailing.”
Dr. Bruce has this to say about the challenge:
The challenge is useful for newbies as a way to extend their skills in a useful manner. They will learn how they solved the problem, and also gain from seeing how others solved the problem too. We all start from different places when we solve problems, so the ‘obvious’ solution to you, might not occur to someone else who has a different experience of Ruby. This is why it’s good to share examples and code together when possible too.
Prizes
- The participant 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.
- From the remaining working Ruby solutions, three participants would be selected randomly and each one would be awarded any one of Pragmatic’s The Ruby Object Model and Metaprogramming screencasts.
The four persons who win, can’t win again in the next immediate challenge but can still participate.
The Ruby Challenge
The Challenge
As a developer it helps to be able to understand a client’s perspective and to build suitable applications to help them in their field. This means knowing a bit about the world. We’ll help this background knowledge by doing looking at some economic data, and also testing our XML parsing skills.
The file cia-1996.xml is the data from the CIA World Factbook of 1996 in XML format. It has details about 260 countries across five continents. Your challenge, should you choose to accept it, is to uncover the following details buried within this file:
- What is the population of the country with the most people? Yes, we know it’s China, but just how many people lived there in 1996?
- What are the five countries with the highest inflation rates, and what were those rates in 1996?
- What are the six continents in the file and which countries belong to which continent? Can you also produce them in alphabetical order?
Once you’ve worked out how to do part (2), then you can do anything with this file; all you need is a bit of time. Knowing how to do (2) you could then do (3) without too much effort.
You can use any XML library. I used REXML as it’s already there if you have Ruby installed; so don’t need to worry about any gem installs. You may also want to look at how REXML uses XPath.
Submit your solution of your code, which includes a test file that answers the three questions.
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:
- 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:
- Email address (will not be published):
- Brief description of what you do (will not be published):
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 27th Sept. 2010 (Indian Standard Time). No new solutions will be accepted from 28th Sept. onwards.
- On 28th Sept. 2010 all the solutions will be thrown open for everyone to see and comment upon.
- The winning entries will be announced on this blog before 30th Sept.
- 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?
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:
- Dr. Bruce Scharlau.
- GitHub, for giving us access to a private repository on GitHub to store all the submitted solutions.
- The RubyLearning team.
Questions?
Contact Satish Talim at satish [dot] talim [at] 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
- Dmytrii Nagirniak, Australia
- Kirill Shchepelin, Russia
- Lukasz Hanuszczak, Poland
- Rick DeNatale, USA
- David Lake, England
- Julio C. Villasante, Cuba
- Dan Wanek, USA
- Matthew Dahl, USA
- Mark Tabler, USA
- Kalle Lindström, Sweden
- Chris Jones, USA
- Tamas Szabo, Australia
- Adrian Castillo, Mexico
- Norman E. White, USA
- Himansu Desai, USA
- Samnang Chhun, Cambodia
- Predrag Bradaric, Serbia
- Jonathan, Mexico
- Christopher Fortenberry, USA
- Brad O’Connor, Australia
Just for Fun
- Casimir Saternos, USA
- Paul McKibbin, U.K.
The Winners
Congratulations to the winners of this Ruby Challenge. They are:
- Dmytrii Nagirniak from Australia (his Ruby Challenge solution) – the person with the best and most creative Ruby solution. He wins any one of PeepCode’s Ruby on Rails screencasts.
- Adrian Castillo from Mexico, Dan Wanek from USA and Kalle Lindström from Sweden win any one of Pragmatic’s The Ruby Object Model and Metaprogramming screencasts.
Previous Challenge
RPCFN: Cycle Tracks (#12) by David Griffiths.
Note: All the previous challenges, sponsors and winners can be seen on the Ruby Programming Challenge for Newbies page.
- This challenge is now closed.
- The (#14) challenge by Joseph Wilk, U.K. is scheduled for Oct. 2010.