Calendar - for "REAL" programmers: Difference between revisions
Content added Content deleted
imported>Arakov |
imported>Fth No edit summary |
||
Line 1,246: | Line 1,246: | ||
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 |
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 |
||
</pre> |
</pre> |
||
=={{header|Forth}}== |
|||
<syntaxhighlight lang="forth"> |
|||
: WEEKDAY ( D M Y -- U ) |
|||
OVER 3 < IF SWAP 12 + SWAP 1- THEN |
|||
DUP 4 / OVER 100 / - OVER 400 / + + SWAP 1+ 13 * 5 / + + 2 - 7 MOD ; |
|||
: MDAYS ( M Y -- MSIZE MDAY ) |
|||
OVER 12 = IF 31 1 2SWAP WEEKDAY NEGATE EXIT THEN |
|||
2>R 1 2R@ WEEKDAY 1 2R> SWAP 1+ SWAP WEEKDAY OVER - |
|||
7 + 7 MOD 28 + SWAP NEGATE ; |
|||
: .WEEK ( MSIZE MDAY -- MSIZE MDAY' ) |
|||
7 0 DO DUP 0< IF 1+ 3 SPACES ELSE |
|||
2DUP > IF 1+ DUP 2 .R SPACE ELSE 3 SPACES THEN THEN LOOP ; |
|||
: .3MONTHS ( Y M -- ) |
|||
3 0 DO ." MO TU WE TH FR SA SU " LOOP CR |
|||
3 OVER + SWAP DO I OVER MDAYS ROT LOOP DROP |
|||
6 0 DO 2ROT .WEEK 2 SPACES 2ROT .WEEK 2 SPACES 2ROT .WEEK CR LOOP |
|||
2DROP 2DROP 2DROP ; |
|||
: CAL ( Y -- ) |
|||
30 SPACES ." [SNOOPY]" CR |
|||
32 SPACES DUP . CR |
|||
." JANUARY FEBRUARY MARCH" CR |
|||
DUP 1 .3MONTHS |
|||
." APRIL MAY JUNE" CR |
|||
DUP 4 .3MONTHS |
|||
." JULY AUGUST SEPTEMBER" CR |
|||
DUP 7 .3MONTHS |
|||
." OCTOBER NOVEMBER DECEMBER" CR |
|||
10 .3MONTHS ; |
|||
1969 CAL |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
[SNOOPY] |
|||
1969 |
|||
JANUARY FEBRUARY MARCH |
|||
MO TU WE TH FR SA SU MO TU WE TH FR SA SU MO TU WE TH FR SA SU |
|||
1 2 3 4 5 1 2 1 2 |
|||
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9 |
|||
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16 |
|||
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23 |
|||
27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30 |
|||
31 |
|||
APRIL MAY JUNE |
|||
MO TU WE TH FR SA SU MO TU WE TH FR SA SU MO TU WE TH FR SA SU |
|||
1 2 3 4 5 6 1 2 3 4 1 |
|||
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8 |
|||
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15 |
|||
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22 |
|||
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29 |
|||
30 |
|||
JULY AUGUST SEPTEMBER |
|||
MO TU WE TH FR SA SU MO TU WE TH FR SA SU MO TU WE TH FR SA SU |
|||
1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7 |
|||
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14 |
|||
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21 |
|||
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28 |
|||
28 29 30 31 25 26 27 28 29 30 31 29 30 |
|||
OCTOBER NOVEMBER DECEMBER |
|||
MO TU WE TH FR SA SU MO TU WE TH FR SA SU MO TU WE TH FR SA SU |
|||
1 2 3 4 5 1 2 1 2 3 4 5 6 7 |
|||
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14 |
|||
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21 |
|||
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28 |
|||
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 |
|||
</pre> |
|||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
Alas, the header "FORTRAN" is not recognised - REAL programmers were absent that day? Even upon the apperance of lower case, I have preferred to use shouting for programme source, and normal upper/lower case for commentary. Aside from petty details such as 1 and l being nowhere as distinct as 1 and L, this allows the two sorts of blather to be identifiably different without ratiocination as the hours drag past. Further, the names of variables can easily be distinguished from the same word in discussion, as in ... the text in TEXT will be printed as the subtitle to the text in TITLE ... Anyway, in the spirit of old, herewith the source without tedious commentary: |
Alas, the header "FORTRAN" is not recognised - REAL programmers were absent that day? Even upon the apperance of lower case, I have preferred to use shouting for programme source, and normal upper/lower case for commentary. Aside from petty details such as 1 and l being nowhere as distinct as 1 and L, this allows the two sorts of blather to be identifiably different without ratiocination as the hours drag past. Further, the names of variables can easily be distinguished from the same word in discussion, as in ... the text in TEXT will be printed as the subtitle to the text in TITLE ... Anyway, in the spirit of old, herewith the source without tedious commentary: |