Tuesday, November 3, 2009

ACM ECNA Regional 2009

The final standings are here. As usual the contest report doesn't mention any technical problems. I thought I would mention the ones I heard of here.

When the contest started the McMaster site had not yet handed out problems. So after PC^2 was started it was stopped again, then the contest was started over 8 minutes later. At least at my site we started and were never told to stop, and didn't check PC^2. I believe that the other sites except for McMaster did the same thing. Essentially McMaster was 8 minutes late to a 5:08 long competition. Its not fair, but it shouldn't change the results of the world finals teams.

The time left on PC^2 was wrong for about the last hour of the contest. It showed < 2 minutes left for about the last hour. We were done at that point so we were unaffected. This is a huge problem for teams still working because it makes it much harder to manage time. The other CMU team was printing every few minutes because on the printout was the current time.

The last issue may or may not be an issue. At this point I'm willing to give the benefit of the doubt to the judges. Most of the teams who got B incorrect (Waterloo, CMU Dragons, Purdue) weren't sure why they got it wrong. There are rumblings that the test data was wrong, or that there was floating point error. I haven't throughly checked our 4 wrong answers to that problem, but at this point I believe all 4 of them were incorrect. After the floating point debacle of last year I think the judges probably checked the problem very throughly before finalizing the results.

When the test data is released for B we'll be able to go back and figure out why teams were getting wrong answers. The problem was hard to code, and hard to debug so it is plausible that teams just had subtle bugs in their code.

The final results were CMU Dragons in 4th, Waterloo in 3rd, University of Michigan 2nd, and my team, CMU Tartans in first. My team had plenty of good luck on our side. We weren't affected any of the issues and potentially we got B right despite rounding errors in the test data. Either way we are headed to Harbin China in February.

Tuesday, October 20, 2009

The TopCoder Easy

The easy division one problem on TopCoder is a weird type of problem, that I'm not sure exactly how to tackle. The problem almost always has a very short (~15 lines of code) solution, but normally you need at least one insight to get to that solution. My problem has always been either finding the insight, or being able to prove its correctness.

For the last two SRMs I have solved the easy using a more complicated approach, but one that doesn't require much insight at all. Take OrderedNim(http://www.topcoder.com/stat?c=problem_solution&rm=302474&rd=13904&pm=10190&cr=22657324) for example. The answer is directly related to whether or not the piles have one stone or more than one, but I couldn't think of the exact solution. Instead I just used DP to solve the problem. Sure it took me longer to code, but it avoided a leap of faith in doing so.

I'm still not sure if it is optimal to spend more time looking for the elegant solution, or to just dive into the longer solution. At this point I am confident enough in my coding that I'm not going to lose much time by coding the longer solution. On the other hand I think I am also running away from the elegant code because I don't have the solution. It is hard to force yourself to think of a better way when you have found a method that works.

I am probably doing something wrong because my times for the easy solutions have not been great. ()They haven't been bad, but for the last two SRMs my mediums have carried a majority of the weight. I'm very happy to be able to get fast times and still be very confident that my code is correct. I got the fastest medium overall in SRM 450 and the fastest Java solution in 451 (~10th overall). ()

Saturday, October 17, 2009

The Programming Contest Version of Chicken

In the last few practices we have had a couple of problems that have induced an interesting phenomena. The best example is one problem from world finals last year. It was questionable whether the brute force solution would time out or not. My team decided to wait and just look at the scoreboard in 15 minutes. When we checked the scoreboard a bunch of teams had a wrong answer for the problem and no one had solved it. We had our answer without wasting any of our time solving the problem.

Assuming all parties recognize that the problem may or may not be brute force able it seems optimal to always wait until someone else attempts it. On one side if you are able to brute force it you will have a smaller time penalty, on the other side if it isn't you waste console time. In general I think that console time is more important.

At world finals I think it is much more crucial to not spend times on problems you don't solve then to worry about time penalty. All but a few teams there will solve no more than 6 of the 10 problems. You can waste a ton of time by attempting one of the harder problems and never solving it. This creates an even better argument for not attempting the questionably brute force able problem.

At world finals there will probably always be a couple teams who are too optimistic and try the brute force solution, but at regionals that may not be the case. My region (East Central North America) had only 5-6 top teams last year. In theory this could lead to a phenomenon where a lot of the top teams don't solve a brute force able problem until very late into a contest.

Saturday, May 9, 2009

Learning while Coding

There has been a phenomena that has been bugging me for a while, but I just couldn't put my finger on it. A couple days ago my brother (a non programmer) asked about which programming language to use for a little project of his. I asked what the project was, and didn't get more than some vague statements. He said that he wanted to start coding and figure out how to do it on the way. I have been guilty of this many times (including the AI project I am currently having trouble with). I think it is one of the most inefficient ways of going about programming.

For some reason when you code you aren't able to focus on the big picture of the program. I have a very hard time anticipating problems I am going to have 20 lines in the future until I actually get there. There are plenty of TopCoder problems where half way through I realize that my algorithm doesn't work. I have had the same thing happen at my internship over the summer. In a good case I figure out the problem before I am finished coding, occasionally it takes until I start debugging to figure things out.

I think the problem comes from the fact that it is hard to spend the time and understand your algorithm. It's very easy for me to just dive in and start coding. For some reason I am scarred of going through the work to really figure out exactly how things are going to work. I think that being able to plan things out in detail (to the point where what you code doesn't change much between the first draft and the final version) is a crucial skill for both competative programming and for programming in the real world. 

I think you can really see the difference when it comes to debug time. Look at the last problem we solved at the ACM world finals. Alan and I talked it over thoroughly and we really knew exactly what we wanted to do. The code got written in about 15 minutes and the debug time was just a couple of minutes. Contrast that with my performance on the medium problem in the TopCoder open round 4, I recognized it as DP (without grasping the full complexity of it), jumped in and started coding. After an hour I was still debugging a flawed algorithm.

Another example is coding malloc. My friend just jumped in and started coding it. He was well on his way to finishing the code while I was still figuring out how I wanted to setup my #defines. I debugged it for a couple of hours, it took him days to finally get his code correct. Planning is especially important for things like malloc (basically a ton of bit operations, and problems show up way after they occurred). The more complicated the code, the more you need to plan.

When I started TopCoder I always wanted to be really fast. Speed was a huge focus for me as it is for many other competitors. I think that focusing on speed early on doesn't help the learning process at all. The real focus should be on correctness. Plan things out on paper in detail and get things correct (in practice and in the contest). After doing that for a while it is easy to recognize a problem that you can solve quickly without planning and ones you need to spend a half our coding.

Saturday, April 25, 2009

ACM World Finals

Our plan going into the world finals was to slow down for the first hour so that we would tackle the correct problems in the problem set. We had not done that well at problem selection on the last couple of practices. The goal was to get 5 problems (the best CMU has ever done is 4), but I thought we were capable of 6 on a very good day.

We started out as we always do, Celestine (the fastest coder) reading A-C, I get D and every other after it (D,F,H,J) and Alan gets E and every other. Celestine recognized that A was pretty trivial very early on. He talked it over with me and we came up with the algorithm which he coded and got correct on the first submission. Already we had started out better than at regionals.

From there we didn't have an immediate next problem. I started working on F, and eventually got a rather crude algorithm for it. I talked it over with Celestine and he started to code it. After a few minutes he noticed a cool property that allowed the code to be significantly simpler (basically taking all the computational geometry except convex hull out of the problem). While he coded that up I talked over B with Alan, and started coding it out on paper.

Celestine got F correct, so I hopped on the terminal to type up B. Alan was working on E on paper while Celestine scavenged for another problem. My first two attempts at B were incorrect, but after some help debugging from Celestine we found the bugs (not implementation problems but a small misunderstanding of the problem). We finally got B done and Celestine went to code up I. I talked over E with Alan and we got an algorithm working that we thought was correct.

Celestine turned in I and got it wrong the first time. We found a small typo resubmitted and got it wrong again. We fixed another few bugs over the next hour or so, but we still didn't have it correct. Alan started typing up E while we finished up I. Celestine was still debugging I, when Alan turned it in and got it back wrong. I looked over it with him, and after a few minutes we were both confident in the implementation. It took a few more minutes before I found the counterexample. We quickly found a fix that would still reuse most of the old code. In the meantime I told Celestine to go from int to double math and to do another stupid fix just in the off chance one of those is our bug. We ended up having integer overflow so that fixed I. Alan quickly fixed E and we were finished with 5 before the scoreboard was frozen.

From there we went looking for more problems. Alan recognized that H is basically the 2-sat algorithm. He coded that while I watched, in the meantime Celestine looked at the other problems trying to find the next easiest one. Alan quickly finished H (whenever we pair program the debug time seems to be nearly instant) and got it right. We were a little worried about some parts of the algorithm, but I think that if I had more of a grasp as to why 2-sat works, not just the algorithm it would be easy to show that ours is correct.

At that point we had 6 problems left with about 35 minutes on the clock. We selected D as the next easiest problem, but despite our best attempts we didn't get too far on it. I think at the end we had some good ideas on how to solve it, but we were probably 30 minutes to an hour away from getting it.

With the contest over we milled about waiting for the results. It was really nerve wracking for us, we were in roughly 16th place when the scoreboard froze without a very good time penalty. We knew we had a shot at a medal, but it didn't seem like a good shot at the time. Eventually the scoreboard went final and our tiebreaker was good enough to put us ahead of most of the teams with 6 problems solved and in 12th place for a bronze medal.

Monday, April 20, 2009

ACM World Finals Days 1 and 2


We arrived in Stockholm on Saturday, and went straight to the Grand Hotel where we stayed. Despite the jet lagged we managed to get out and see the Nobel (prize) museum which was very interesting. The day ended uneventfully with registration and some food in the hotel.

Sunday started very early with a trip to Vaxholm's fortress at 7:45am.We arrived to see a castle on an island which looked very interesting. If you did not know, Stockholm is on an archipelago.

I was fully expecting a tour of the castle, but instead we were shuffled into an auditorium. We got to listen to IBM talk to us about how they are making the world smarter and saving the world. I guess if you pay for everything you get to give the group a presentation. The presentation was down right terrible. The lecture was a high level view of a bunch of projects that IBM are involved with that are helping save the world. The audience is a bunch of incredibly smart, and very technical people. Tell us about the interesting technical details. One of our coaches remarked is that a good measure of how smart you are is how fast you fell asleep at the lecture.

From there we were divided into groups to do a scavenger hunt. My first thought were math and logic puzzles. It ended up being a bunch of team building type exercises. Games where you have to work together to do something. For example the game pictured on the right. Everyone holds a rope to help control where the ball goes. You need to drop the ball into the cylinders and based on which lights turn on you determine the order of the cylinders. Then you drop the ball into the cylinders in that order for bonus points.

Celestine's team ended up winning the scavenger hunt and winning some well deserved viking hats. We returned to the hotel for a few hours before taking a short walking tour of Stockholm on the way to city hall for the opening ceremony. The opening ceremony recognized a number of volunteers who make this event happen. It must take an immense amount of time to coordinate an event of this side. Just helping make the problem set for our local contest took quite a bit of my time.

The rescheduled TopCoder SRM was during the opening ceremony so ACRush and all the other great TopCoders here missed it. That probably made it a much easier contest than a normal SRM.

In general the first few days were interesting, but a lot of waiting around. I'm really ready to go and start the contest. I'm doing being nervous, lets just get on with it.

Monday, April 13, 2009

Pretty Bad Practice

Today we had another practice (with Purdue and Duke), we got 3rd getting only one problem. Purdue and Duke both managed to get two. I think we did poorly versus what we could have done on the problem set.

Alan dove into a simulation problem that he probably should have planned on paper more. That basically took his entire five hours. Celestine and I worked together on H and got it. On D I thought I had it but didn't manage to solve it. We didn't put much work into problems we could have gotten, and a lot into problems we didn't have a chance on.

I think that this is a good time to have this learning experience for us. Going into world finals we can't change which problems we will be able to solve and how long it will take us to solve them, but we can change how we play the game. I think that we will go in with a focus on playing the game correctly.

This also really helps because we know what it is like to get our asses kicked by a problem set. We aren't going to just get frustrated by how many other teams are solving.

I am still worried about what sort of mind set I will be in during the actual contest. I think the key is really in the first 30-45 minutes. We need to get started with the correct problems in the correct direction. The first problem we start on needs to be the easy problem, and we need to knock it down. In soccer it is always important for the goal keeper to get a good touch on the ball early in the game, we need the exact same thing.

The one thing we can't really simulate is the intensity at an actual competition. You really want to go full steam ahead, but we need to slow down and get things right. It isn't about saving 5 minutes of console time here and there. Our one and only goal should be to not make the huge mistakes, like miss reading problems, trying a hard problem, or jumping into a simulation too early.

I'm ready to be in Stockholm and not have to worry about any of my homework for a few days. CMU is great, but the workload coupled with lots of 5+ hours practices is really draining.