|
create or replace package easter as
procedure showAllEasterDay;
procedure showMaxOccurenceEasterDay;
procedure showLeapEasterDay;
procedure showFoolEasterDay;
end;
/
create or replace package body easter as
subtype w is varchar2(99);
type s is table of w index by w;
u s;
r s;
t w;
q w := 0;
m w := 0;
n w := 0;
procedure p(a w)as begin dbms_output.put_line(a); end;
procedure showAllEasterDay as
d w;
a w;
c w;
b w;
e w;
begin
u.delete;
t := 0;
p('YEAR DAY');
for i in 1900 .. 2099 loop
d := i - 1900;
a := mod(d,19);
c := mod(11 * a + 4 - trunc((7 * a + 1)/19), 29);
b := 25-c-mod(d + trunc(d/4) + 31 - c, 7);
if b > 0
then a := '04'; c := b;
else a := '03'; c := 31+b;
end if;
c := lpad(c,2,0);
b := a||'-'||c;
p(i || ' ' || b);
if b = '04-01' then r(t) := i; t := t + 1; end if;
if u.exists(b) then
e := u(b) + 1;
if e > q then
q := e;
end if;
if b like '03%' then
m := greatest(e,m);
else
n := greatest(e,n);
end if;
else e := 1;
end if;
u(b) := e;
end loop;
end;
procedure showMaxOccurenceEasterDay as
d w;
e w;
f w;
i w := u.first;
g w;
begin
while i is not null loop
g := u(i);
if g = q then
d := d || '/' || i;
end if;
if i like '03%' and g = m then
e := e || '/' || i;
elsif g = n then
f := f || '/' || i;
end if;
i := u.next(i);
end loop;
p('MAXOCC MO_CNT MAXOCC_3 MO3_CNT MAXOCC_4 MO4_CNT ');
p(ltrim(d,'/') || ' ' || q || ' ' ||
ltrim(e,'/') || ' ' || m || ' ' ||
ltrim(f,'/') || ' ' || n);
end;
procedure showLeapEasterDay as
b w;
e w;
a w;
c w := 0;
begin
p('ABSENT_START ABSENT_END');
for i in 0 .. date'1-4-25' - date'1-3-22' + 1 loop
a := to_char(date'1-3-22' + i, 'mm-dd');
if u.exists(a) then
if c = 1 then
p(b || ' ' || e);
end if;
c := 0;
else
e := a;
if c = 0 then
b := a;
end if;
if a = '04-25' then
p(b || ' ' || e);
end if;
c := 1;
end if;
end loop;
end;
procedure showFoolEasterDay as
begin
p('YEAR TOTAL');
for i in 0 .. r.count-1 loop
p(r(i) || ' ' || t);
end loop;
end;
end;
/ |
|