From: superpollo on
pk ha scritto:
> pk wrote:
>
>> Well, an obvious way (which needs GNU date and bash) is something like
>>
>> day=("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")
>>
>> for y in {1585..3000}; do
>> d=$(date +%w -d "1/1/$y")
>> freq[$d]=$((${freq[$d]}+1))
>> done
>>
>> i=0
>> while [ $i -lt 7 ]; do
>> echo "${day[$i]} ${freq[$i]}"
>> i=$((i+1))
>> done
>>
>> Sun 205
>> Mon 198
>> Tue 206
>> Wed 202
>> Thu 202
>> Fri 205
>> Sat 198
>
> Also, this can be implemented with GNU awk, dramatically faster and more
> efficient as there's only one proecess involved:
>
> awk 'BEGIN{split("Sun Mon Tue Wed Thu Fri Sat Sun",day)
> for(y=1585;y<=3000;y++)freq[strftime("%w", mktime(y " 01 01 00 00 00"))]++
> for(i=0;i<7;i++)print day[i+1],freq[i]}'
> Sun 205
> Mon 198
> Tue 206
> Wed 202
> Thu 202
> Fri 205
> Sat 198
>
> (Seeb's remarks about year ranges still apply)

i cannot get the same output:

$ awk 'BEGIN{split("Sun Mon Tue Wed Thu Fri Sat Sun",day)
for(y=1585;y<=3000;y++)freq[strftime("%w", mktime(y " 01 01 00 00 00"))]++
for(i=0;i<7;i++)print day[i+1],freq[i]}'
Sun 19
Mon 20
Tue 19
Wed 20
Thu 1299
Fri 20
Sat 19
$
From: superpollo on
superpollo ha scritto:
> pk ha scritto:
>> pk wrote:
>>
>>> Well, an obvious way (which needs GNU date and bash) is something like
>>>
>>> day=("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")
>>>
>>> for y in {1585..3000}; do
>>> d=$(date +%w -d "1/1/$y")
>>> freq[$d]=$((${freq[$d]}+1))
>>> done
>>>
>>> i=0
>>> while [ $i -lt 7 ]; do
>>> echo "${day[$i]} ${freq[$i]}"
>>> i=$((i+1))
>>> done
>>>
>>> Sun 205
>>> Mon 198
>>> Tue 206
>>> Wed 202
>>> Thu 202
>>> Fri 205
>>> Sat 198
>>
>> Also, this can be implemented with GNU awk, dramatically faster and
>> more efficient as there's only one proecess involved:
>>
>> awk 'BEGIN{split("Sun Mon Tue Wed Thu Fri Sat Sun",day)
>> for(y=1585;y<=3000;y++)freq[strftime("%w", mktime(y " 01 01 00 00
>> 00"))]++
>> for(i=0;i<7;i++)print day[i+1],freq[i]}'
>> Sun 205
>> Mon 198
>> Tue 206
>> Wed 202
>> Thu 202
>> Fri 205
>> Sat 198
>>
>> (Seeb's remarks about year ranges still apply)
>
> i cannot get the same output:
>
> $ awk 'BEGIN{split("Sun Mon Tue Wed Thu Fri Sat Sun",day)
> for(y=1585;y<=3000;y++)freq[strftime("%w", mktime(y " 01 01 00 00 00"))]++
> for(i=0;i<7;i++)print day[i+1],freq[i]}'
> Sun 19
> Mon 20
> Tue 19
> Wed 20
> Thu 1299
> Fri 20
> Sat 19
> $

one more thing:

$ date --date="1902-01-01"
Wed Jan 1 00:00:00 CET 1902
$ date --date="1901-01-01"
date: invalid date `1901-01-01'
$
From: Janis Papanagnou on
superpollo schrieb:
> superpollo ha scritto:
>> pk ha scritto:
>>> pk wrote:
>>>
>>>> Well, an obvious way (which needs GNU date and bash) is something like
>>>>
>>>> day=("Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun")
>>>>
>>>> for y in {1585..3000}; do
>>>> d=$(date +%w -d "1/1/$y")
>>>> freq[$d]=$((${freq[$d]}+1))
>>>> done
>>>>
>>>> i=0
>>>> while [ $i -lt 7 ]; do
>>>> echo "${day[$i]} ${freq[$i]}"
>>>> i=$((i+1))
>>>> done
>>>>
>>>> Sun 205
>>>> Mon 198
>>>> Tue 206
>>>> Wed 202
>>>> Thu 202
>>>> Fri 205
>>>> Sat 198
>>>
>>> Also, this can be implemented with GNU awk, dramatically faster and
>>> more efficient as there's only one proecess involved:
>>>
>>> awk 'BEGIN{split("Sun Mon Tue Wed Thu Fri Sat Sun",day)
>>> for(y=1585;y<=3000;y++)freq[strftime("%w", mktime(y " 01 01 00 00
>>> 00"))]++
>>> for(i=0;i<7;i++)print day[i+1],freq[i]}'
>>> Sun 205
>>> Mon 198
>>> Tue 206
>>> Wed 202
>>> Thu 202
>>> Fri 205
>>> Sat 198
>>>
>>> (Seeb's remarks about year ranges still apply)
>>
>> i cannot get the same output:
>>
>> $ awk 'BEGIN{split("Sun Mon Tue Wed Thu Fri Sat Sun",day)
>> for(y=1585;y<=3000;y++)freq[strftime("%w", mktime(y " 01 01 00 00
>> 00"))]++
>> for(i=0;i<7;i++)print day[i+1],freq[i]}'
>> Sun 19
>> Mon 20
>> Tue 19
>> Wed 20
>> Thu 1299
>> Fri 20
>> Sat 19
>> $
>
> one more thing:
>
> $ date --date="1902-01-01"
> Wed Jan 1 00:00:00 CET 1902
> $ date --date="1901-01-01"
> date: invalid date `1901-01-01'
> $

I confirm your results for the Windows/Cygwin platform.

Please also observe the different distribution if you
restrict your range from ~1900-2030, then extend that,
once to dates 1800-2030, and then to dates 1900-2200.

Janis
From: Laurianne Gardeux on
superpollo à écrit :

> hi.
>
> i had to test an hypothesis about the relative frequencies of weekdays
> on the new-year-day (january 1). i came up with this quickie:
>
> $ echo -ne '\t' ; cal -m | head -2 | tail -1 ; for YEAR in $(seq 1585 1
> 3000) ; do cal -m 01 $YEAR | head -3 | tail -1 ; done | sort -r | uniq
> -c
> Mo Tu We Th Fr Sa Su
> 199 1 2 3 4 5 6 7
> 206 1 2 3 4 5 6
> 202 1 2 3 4 5
> 202 1 2 3 4
> 204 1 2 3
> 198 1 2
> 205 1
> $
>
> any suggestion for improvement?
>
> bye

I know, reinventing the wheel isn't cool. But interested by your
question, and for my own learning purpose, I've get this done (with still
a missing weekday-definition of the first new-year-day in the loop):

awk 'BEGIN { Start=1585; End=3000

for (i = Start; i <= End; i++) {
Counter++
if ( i % 4 == 0 ) { Counter++ }
if ( i >= 1700 ) {
if ( i % 100 == 0 ) { Counter-- }
if ( i % 400 == 0 ) { Counter++ }
}
if (Counter == 1) { Weekday_1++ }
if (Counter == 2) { Weekday_2++ }
if (Counter == 3) { Weekday_3++ }
if (Counter == 4) { Weekday_4++ }
if (Counter == 5) { Weekday_5++ }
if (Counter == 6) { Weekday_6++ }
if (Counter == 7) { Weekday_7++; Counter=0 }
if (Counter == 8) { Weekday_1++; Counter=1 }
}
print Weekday_1
print Weekday_2
print Weekday_3
print Weekday_4
print Weekday_5
print Weekday_6
print Weekday_7
}'
202
203
205
198
205
198
205