Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:53:47+00:00 2026-06-13T21:53:47+00:00

Problem 19: You are given the following information, but you may prefer to do

  • 0

Problem 19:

You are given the following information, but you may prefer to do some
research for yourself.

1 Jan 1900 was a Monday.

Thirty days has September, April, June and
November.

All the rest have thirty-one, Saving February alone, Which
has twenty-eight, rain or shine. And on leap years, twenty-nine.

A leap year occurs on any year evenly divisible by 4, but not on a
century unless it is divisible by 400.

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

I thought that using PHP for this would be a breeze since it has so many built-in time and date functions. My code is really quite simple, so I’m having a hard time seeing what I’m doing that’s wrong.

My code:

<?php
    echo "<pre>";
    $sunday_count = 0;
    for( $year = 1901; $year <= 2000; $year++ ) {
        for( $month = 1; $month <= 12; $month++ ) {
            // Produces a date in format: 1/1/2000
            $date = $month . "/1/" . $year;
            $time = strtotime( $date );
            $is_sunday = ( date( 'l', $time ) == "Sunday" );
            echo "$date "
               . ( $is_sunday ? 'was a Sunday. ' : '' )
               . "<br>";
            if( $is_sunday ) $sunday_count++;
        }
    }
    echo "Answer: $sunday_count";
    echo "</pre>";
?>

The solution my code comes up with is 169, which is not correct. Any idea?

Edit 1

The solution is supposed to be 171.

Using Wolfram Alpha and my Windows clock, I’ve doubled checked several of the Sundays which my code reports. All of them check out OK.

So it seems my code is reporting valid and legitimate Sundays, but somehow it has missed two of them.

Edit 2

I made the following minor change to the formatting of the date in my code:

$date = sprintf('%d-%02d-01', $year, $month); // formats yyyy-mm-dd

I then used @MadaraUchiha’s code to generate an array containing the 171 correct dates.

After comparing his dates with mine, these are the two missed dates:

1901-09-01
1901-12-01

Edit 3

Codepad also shows that these dates are not Sundays (but they really should be).

And I am certain that the dates are correctly being interpreted as YYYY-MM-DD because one of the dates my code offers to the solution is 2000-10-01, which would only be a Sunday if 10 is the month, not the day.

Edit 4

So apparently if on a 32 bit system, Unix timestamps won’t work outside of the range:

Fri, 13 Dec 1901 20:45:54 GMT

to

Tue, 19 Jan 2038 03:14:07 GMT
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:53:48+00:00Added an answer on June 13, 2026 at 9:53 pm

    The reason it might not work on some systems using timestamps is that the range of a Unix timestamp on 32-bit systems is from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT, so you miss almost all months in the first year.

    64-bit systems have larger integers which makes the range bigger (in PHP).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You are given the following information, but you may prefer to do some research
Warning! Spoilers ahead! You are given the following information, but you may prefer to
Problem Given the following two tables, I'd like to select all Ids for Posts
Please help me out with an algorithm for the following problem - Given a
Given the following problem , I'd appreciate for any corrections since I have no
Given the following html table and script shown below I am having a problem
I have the following problem, given the following service contract, data contract, and service
Problem One friend suggested an interesting problem. Given the following code: public class OuterClass
I have a problem with nested templates and their template specialization. Given the following
I have the following problem: I am given a tree with N apples, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.