while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}
The code is designed to calculate the current year from the total number days since 1980 to the present, but its a tarp!
A bag of Jelly Babies for the person who figures out whats wrong with the fragment of code above. It's world famous now, but no cheating please! I saw the problem without cheating and so should you!
[via]
As far as I can tell - without cheating - it will go into an endless loop when called with the date January 1st on a year after a leap year, ie January 1st 1981. This is so because days will pass the condition days > 365, but not days > 366, meaning days will not be decremented. Adding an else statement for the inner if would help. :)
ReplyDeleteSpeaking of bugs, Blogger's new comment box fails if you're trying to add a comment with Opera if you have a Google account. It almost fails with FF too, but I managed tog et around it by pressing preview. Gee!
As we discussed earlier, right except for the date the infinite loop would begin. It was yesterday (31st December on 2008, a leap year) that everyones Zune mp3 player refused to start because of the loop at start up. Adding an else to that inner if with a break is the solution I thought of too. I used a simple "break;" to end the loop. Some people came up with very fancy while loop conditions to solve the problem :)
ReplyDeleteNot sure whats up with the comment form, it works fine in Chrome but not in FF for me either. Strangely, it works fine in Flock, a Mozilla derivative. The incompatibilities between Google and Opera is the reason I stopped using it as a browser, a pity really.
Acording to engadget and the like, the problem is to do with the Freescale power management chip rather than Microsoft coding (a number of Toshiba models were also affected).
ReplyDeleteOh Des... Don't you dare interrupt our M$ bashing. ;)
ReplyDeleteSorry for d'interruption..carry on !
ReplyDeleteYes its a fair point, Des. When writing up this post I was aware that it was a Freescale problem, they hold the patent on the source code, but its appearance on the Zune its covered by Microsoft's EULA, so therefore they're the ones who I put in the post title. It's like if you buy a new car, and the timing belt melts off the sprockets. You don't tell your friends, "man, the timing belt made by Nashikonica Inc. snapped and ruined my new car's engine" you say, "Mother fucking VW shit... things like this never happened when Hitler was making them". The buck stops with M$, otherwise we could continue to iterate through blame until we were nailing a Freescale code monkey to a tree by the balls.
ReplyDeleteI'm most annoyed with Microsoft simply because the MacTards are having a field-day with this.
This comment has been removed by the author.
ReplyDeleteah feck...
ReplyDelete"I manage an MS-based organisation"
Apple could cause Armageddon and people would still be making excuses for them. They can do no wrong.
ReplyDelete"I manage an MS-based organisation"
An or A... it doesn't matter because in 2009, as long as you dont have to write "I managed an MS-based organisation" you'll be doing fine :)
after all there's no "return" in it :D
ReplyDeletereturn toSender;
ReplyDelete