Post Reply 
Easter Algorithm Bug
05-11-2017, 05:46 PM
Post: #1
Easter Algorithm Bug
The following code is supposed to output the date of easter for a given year. If I put in 2017 for the year it should output "April 16" but instead it outputs "April569". If anyone can figure out what is wrong with my code, please let me know.

Code:

EXPORT easter(T)
BEGIN
  // Year (1583-9999)
  LOCAL A,B,C,D,EE,K,M,N;
  LOCAL P,Q,OUT;
  IF T<1583 OR T>9999 THEN
    RETURN "Error - Year is invalid.";
  ELSE
    K:=IP(T/100);
    A:=T MOD 19;
    B:=T MOD 4;
    C:=T MOD 7;
    Q:=IP(K/4);
    P:=IP((8*K+13)/25);
    M:=15-P+K-Q MOD 30;
    D:=19*A+M MOD 30;
    N:=4+K-Q MOD 7;
    EE:=2*B+4*C+6*D+N MOD 7;
    IF D+EE<=9 THEN
      D:=22+D+EE;
      M:=3;
    ELSE
      IF D==19 AND EE==6 THEN
        D:=19;
        M:=4;
      ELSE
        IF D==28 AND EE==6 AND A>10 THEN
          D:=18;
          M:=4;
        ELSE
          D:=D+EE-9;
          M:=4;
        END;
      END;
    END;
    IF M==3 THEN
      RETURN cat("April ", STRING(D));
    ELSE
      RETURN cat("April ", STRING(D));
    END;
  END;
  RETURN OUT;
END;
Find all posts by this user
Quote this message in a reply
05-13-2017, 12:05 AM (This post was last modified: 05-13-2017 12:31 AM by Fortin.)
Post: #2
RE: Easter Algorithm Bug
Just a quick guess...

Code:

EXPORT easter(T)
BEGIN
  // Year (1583-9999)
  LOCAL A,B,C,D,EE,K,M,N;
  LOCAL P,Q,OUT;
  IF T<1583 OR T>9999 THEN
    RETURN "Error - Year is invalid.";
  ELSE
    K:=IP(T/100);
    A:=T MOD 19;
    B:=T MOD 4;
    C:=T MOD 7;
    Q:=IP(K/4);
    P:=IP((8*K+13)/25);
    M:=(15-P+K-Q) MOD 30;
    D:=(19*A+M) MOD 30;
    N:=(4+K-Q) MOD 7;
    EE:=(2*B+4*C+6*D+N) MOD 7;
    IF D+EE<=9 THEN
      D:=22+D+EE;
      M:=3;
    ELSE
      IF D==19 AND EE==6 THEN
        D:=19;
        M:=4;
      ELSE
        IF D==28 AND EE==6 AND A>10 THEN
          D:=18;
          M:=4;
        ELSE
          D:=D+EE-9;
          M:=4;
        END;
      END;
    END;
    IF M==3 THEN
      RETURN cat("March ", STRING(D));
    ELSE
      RETURN cat("April ", STRING(D));
    END;
  END;
  RETURN OUT;
END;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)