Time Problems: Tips? Hints? Rants?

Post here if you don't find any other place for your post. But please, stay on-topic: algorithms, programming or something related to this web site and its services.

Moderator: Board moderators

Post Reply
Booley
New poster
Posts: 1
Joined: Mon Feb 11, 2013 12:40 am

Time Problems: Tips? Hints? Rants?

Post by Booley »

Time-themed problems stump me every time! There's always some corner case or some bug in my code that I can't resolve :x (e.g. time turns past midnight, considering leap years). Do you guys have any tips/strategies for handling time-themed problems? They've been coming up in some recent contests for me, and I don't want them to be my bottleneck.

On a similar note, I've heard about Java's GregorianCalendar, Date, Calendar, and other classes related to handling time, but I don't know how to use them effectively. Does anyone know of a thorough tutorial/guide on handling Java's functions with time?
lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: Time Problems: Tips? Hints? Rants?

Post by lbv »

Booley wrote:Time-themed problems stump me every time! There's always some corner case or some bug in my code that I can't resolve :x (e.g. time turns past midnight, considering leap years). Do you guys have any tips/strategies for handling time-themed problems? They've been coming up in some recent contests for me, and I don't want them to be my bottleneck.
I think I understand where you're coming from. Some time-related problems do require a lot of attention to corner cases and little things that are easy to overlook.

Personally, I don't find them particularly "tricky" compared to any other type of problem, like geometry, D.P., graph problems, etc. I do think, however, that when you get used to the idea that a certain type of problem is "difficult" for you, then you're creating an artificial barrier that makes it that much harder to solve a problem that may be really "easy" if you were not predisposed to have a hard time with it. So my first tip would be, don't think of them (or any other type of problem) as a "bottleneck".

The other tip I could give you is to do something that is what naturally we all do when solving algorithm problems; if you struggle with a concept, make sure to solve it correctly once, and then reuse your solution.

Take, for example, calculations involving leap years. Something that has worked for me in this regard was writing a couple of useful functions that take the burden of leap years off of my mind: one function that receives three integers (day, month, year) and converts them to a single integer (representing that date as a number of days from an arbitrary starting point), and one that does the reverse process --that is, it receives the same kind of arbitrary number, and produces three integers: day, month and year. The hardest to write is the second one, but once you have it, it's a huge help. Try your solution with problems like "Y3K Problem" (893) and "Cancer of Scorpio" (11947), in case you haven't solved them yet, and then you know you have something in your toolset that handles those pesky leap year problems.

Booley wrote: On a similar note, I've heard about Java's GregorianCalendar, Date, Calendar, and other classes related to handling time, but I don't know how to use them effectively. Does anyone know of a thorough tutorial/guide on handling Java's functions with time?
Regarding tutorial/guides, I can't help you with that, but what about if you write one? This is a serious suggestion. A lot of good "tutorials" are written by people who are learning the very concept that is being explained in the tutorial as they go. And when you make the effort to explain something, it does wonders for your thought processes and helps you gain a deeper understanding of the thing you're trying to explain.

Good luck :)
mohsinj690
New poster
Posts: 1
Joined: Mon Oct 13, 2014 1:39 pm

Re: Time Problems: Tips? Hints? Rants?

Post by mohsinj690 »

The other tip I could give you is to do something that is what naturally we all do when solving algorithm problems; if you struggle with a concept, make sure to solve it correctly once, and then reuse your solution.
Post Reply

Return to “Other words”