OJ’s rants What would OJ do?

4Feb/076

Challenge #3 – Day of Birth

I haven't posted a challenge for a while, so I thought I'd get you all thinking again with another basic little program. It's simple, but there are a stack of possible solutions, so I'm expecting a bit of variety. So here we go.

Write a program that asks the user for their date of birth using the date format YYYY-MM-DD (eg. 1978-12-05 in my case). The program should respond by telling the user what day of the week they were born on.

You're allowed to use any language you want, but you're not allowed to use the built-in date object functionality other than to determine the current system date. That is, you can't date difference functions to determine time that's passed. You have to figure that out for yourself.

For those C# coders, don't even think about posting: dateOfBirth.Day :) You're supposed to do the hard bit yourself

Anyway, it's easy peasy :) Don't forget about leap years and stuff! I look forward to seeing your answers. I'll post up a solution in a week or so. Let me know if I haven't been clear.

  • OJ
    Right, no takers? Am I going to have just post my own solution and that's it?!

    How disappointing :)
  • OJ
    No, the calendar was realigned by minutes or seconds, not whole days, so that stuff makes no difference. The C# and PHP functions don't take that into account coz they don't need to.

    Come on, show me some code :)
  • It's actually harder than you think, because at various points in the past the calendar has been realigned or the number of days in a month has changed, etc. It'd take a bit of research to find all these special cases and take them into account - which presumably the C#, PHP, etc library authors (should) have already done.
  • OJ
    What better reason is there than to make me happy? :D
  • Gawd, I hate reimplementing library functionality unless there's a good reason for it...

    Anyway, I'll give it a go if I get a bit of bored time!
  • dan
    I can get the leap year no worries.. haven't thought about the rest (actionscript) :
    Date.prototype.isLeapYear = function ( year ) {
    if (year == null) {
    year = this.getFullYear();
    }
    return (((year % 4 == 0) &&(year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
    }
blog comments powered by Disqus