Ambiguous wait value

I saw this problem on the website (I will not use the exact wording or mention the website)

Suppose a child receives pocket money on the 15th of each month, depending on what day he is on that date, say, he receives 1 coin Monday, 2 coins on Tuesday ... 7 coins on Sunday. What is the expected number of coins he will receive on the 15th random month?

At first I, although the probability of each of them would be 1/7, so the answer should be 4, but he said the wrong answer.

Then I thought a little more about how to choose a random month, and remembered that the calendar repeats every 400 years, so maybe it has something to do with it, so I wrote the following code:

int Date(int mn,int yr)
{
    if( ( yr%400==0 || (yr%100!=0 && yr%4==0) ) && mn==2)
        return 29;
    if(mn==2)
        return 28;
    if(mn==4 || mn==6 || mn==9 || mn==11)
        return 30;
    return 31;

}

int main()
{
    double coins=0;
    int wk=0;

    for(int yr=1;yr<=400;yr++)
    {
        for(int mn=1;mn<=12;mn++)
        {
            for(int dt=1;dt<=Date(mn,yr);dt++)
            {
                if(dt==15)
                    coins += wk%7 +1;
                wk++;
            }
        }
    }

    cout<<setprecision(10)<<coins/12/400;
}

Output -

4.001666667

! ! , , , , , ? -

int main()
{
    double total=0;

    for(int i=0;i<7;i++)
    {
        int wk=i;
        double coins=0;
        for(int yr=1;yr<=400;yr++)
        {
            for(int mn=1;mn<=12;mn++)
            {
                for(int dt=1;dt<=Date(mn,yr);dt++)
                {
                    if(dt==15)
                        coins += wk%7 +1;
                    wk++;
                }
            }
        }
        cout<<setprecision(10)<<coins/12/400<<endl;
        total += coins;
    }

    cout<<endl<<setprecision(10)<<total/7/12/400;
}

-

4.001666667
3.998333333
4.000833333
3.998958333
4
4.001041667
3.999166667

4

Soooo... ... 4.00666, 1 0001 , - , - ?

?
"" , , ?

+4
3

; .

, , ?

, , .

4.00666, 1 0001 .

"1- . 1" , , .

- , - ?

?

, 4.001666, - , . 1 . 1900 . ( 400- , ) , main

for(int yr=1;yr<=400;yr++)

for(int yr=1900; yr < 1900+400; yr++)

< .


, , , - "" . , 13- , , , .

+3

, 400- .

, 7 , 4 ( ), , , 400 , - , (, -, ).

, : 400 12 , .. . 3600 . 3600 7, , ...

:

int wk=i;
for(int yr=1;yr<=400;yr++)

[0..6]. 7 , 6 ( , , ), , ...).

: , ( ) , , , 1. () , ...

+2

Soooo... ... 4.00666, 1 0001 .

Yes, although, of course, our current calendar system was not used at that time. If you choose a different starting day, you will be calculating for some other calendar system than what we actually use.

Please note that January 1, January 1, January 1, 401, January 1, 801, January 1, 1201, etc. all on one day of the week (again in our current calendar system). You do not need to choose year 1 specifically, but you need to choose the beginning of the period that you choose.

+2
source

Source: https://habr.com/ru/post/1679954/


All Articles