COIN-OR::LEMON - Graph Library

source: lemon-project-template-glpk/deps/glpk/examples/cal.mod @ 10:5545663ca997

subpack-glpk
Last change on this file since 10:5545663ca997 was 9:33de93886c88, checked in by Alpar Juttner <alpar@…>, 13 years ago

Import GLPK 4.47

File size: 1.4 KB
Line 
1/* cal.mod - print an ASCII calendar of the given year */
2
3/* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
4
5param year, integer, >= 0001, <= 3999, default 2010;
6
7param first_day{m in 1..12}, integer, >= 0, <= 6, :=
8      time2str(str2time(year & "-" & m & "-01", "%Y-%m-%d"), "%w");
9
10param days_in_month{m in 1..12}, integer, >= 28, <= 31, :=
11      (str2time(year + (if m < 12 then 0 else 1) & "-" &
12         (if m < 12 then m+1 else 1) & "-01", "%Y-%m-%d") -
13      str2time(year & "-" & m & "-01", "%Y-%m-%d")) / 86400;
14
15param foo{m in 1..12, k in 0..5, d in 0..6}, integer, :=
16      7 * k + d + 1 - first_day[m];
17
18param cal{m in 1..12, k in 0..5, d in 0..6}, integer, :=
19      if 1 <= foo[m,k,d] and foo[m,k,d] <= days_in_month[m] then
20         foo[m,k,d];
21
22printf "\n";
23printf "%33s%04d\n", "", year;
24printf "\n";
25for {t in 1..12 by 3}
26{     for {m in t..t+2}
27      {  printf "%7s%-14s", "", time2str(str2time(m, "%m"), "%B");
28         printf{0..0: m < t+2} "   ";
29      }
30      printf "\n";
31      for {m in t..t+2}
32      {  printf "  S  M Tu  W Th  F  S";
33         printf{0..0: m < t+2} "   ";
34      }
35      printf "\n";
36      for {k in 0..5}
37      {  for {m in t..t+2}
38         {  for {d in 0..6}
39            {  printf{0..0: cal[m,k,d]  = 0} "   ";
40               printf{0..0: cal[m,k,d] != 0} " %2d", cal[m,k,d];
41            }
42            printf{0..0: m < t+2} "   ";
43         }
44         printf "\n";
45      }
46}
47printf "\n";
48
49end;
Note: See TracBrowser for help on using the repository browser.