Skip to content

Instantly share code, notes, and snippets.

@madrobby
Created March 30, 2013 13:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save madrobby/5276743 to your computer and use it in GitHub Desktop.
Save madrobby/5276743 to your computer and use it in GitHub Desktop.
Easter code golfing! Who can make this smaller? Bonus points for fitting it in a tweet. You can use a different algorithm, but it should work for any gregorian date.
// date of easter, call function with the 4-digit year as argument
function (a,b,c,d,e,f,g,h,i,j,k,l,m){return b=a%19,c=~~(a/100),d=a%100,e=~~(c/4),f=c%4,g=~~((c+8)/25),h=~~((c-g+1)/3),i=(19*b+c-e-h+15)%30,j=~~(d/4),k=d%4,l=(32+2*f+2*j-i-k)%7,m=~~((b+11*i+22*l)/451),a+"-"+~~((i+l-7*m+114)/31)+"-"+((i+l-7*m+114)%31+1)}
// f(2013) -> "2013-3-31"
// f(2012) -> "2012-4-8
// f(1775) -> "1775-4-16"
@codepunkt
Copy link

142 characters, based on a different algorithm (taken from http://www.merlyn.demon.co.uk/estralgs.txt)

function(y){var a=y/100|0,b=a>>2,c=(y%19*351-~(b+a*29.32+13.54)*31.9)/33%29|0,d=56-c-~(a-b+c-24-y/.8)%7;return[y,3+d/32|0,d%31||31].join('-')}

Fiddle: http://jsfiddle.net/gonsfx/QW3DP/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment