Ruby has a very neat syntax, making it easy and enjoyable to write. Code redability is vital, and since DWITE is a team competition, it is important for team-mates to read each other’s code with ease.
Ruby is also a very powerful Object Oriented language. It is excellent for data analyzing, processing and manipulations, with many methods build in and readily available, making it an excellent choice for a number of common DWITE problems. Mr. S. has asked for some sample solutions to test out the judge system, so here’s a very typical DWITE entry problem to consider:
Write a program that will calculate the square of a number rounded to two decimal places.
The input file, DATA11.txt, will contain 5 numbers, on separate lines, each between -32768 and 32767.
And a solution:
outFile = File.new(”OUT11.txt”,”w”)
outFile < < sprintf("%0.2f", num.to_f*num.to_f) << "\n"
Input/Output File handling is phenominal. In the previous contest a team has wrote a working solution to one of the problems in C, but due to a messup with inclusion of header files and file access flags, the solution was not accepted. But with Ruby, there is no need to consern with flags, counting for loops, pesky EOF conditions, or other details.
All of the file handling has been reduced to a clean, readable, single line of code. How is this not amazing?
The next DWITE contest is on Tuesday, November 28, 2006 3:00 pm – 6:00 pm – Eastern Time and the registrations are open. You’ve got nearly a month, so if you haven’t already – download Ruby, check out tutorials, ask lots of questions, and enjoy the contest. The next round should be very interesting.