Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Note that this code is needlessly complicated - it was part of the requirements.
- */
- function GetDaysTheHardWay(d){
- // Get ordinal date
- var m = dateformat(d,"ddd");
- var w = '{"DAYS":{"SUN":["1"],"MON":["2"],"TUE":["3"],"WED":["4"],"THU":["5"],"FRI":["6"],"SAT":["7"]}}';
- w = DeserializeJSON(w);
- // I could stop here, but why? Let's make EXTRA sure we're right.
- var o = w.DAYS[m][1];
- // E's are important - let's get one from a reliable source
- var h = new http();
- h.setMethod("get");
- h.setUrl("http://www.coldfusionjedi.com/index.cfm/2011/10/14/Friday-Puzzler-The-Days-of-The-Week");
- var r = h.send().getPrefix();
- var t = Find("e",r.filecontent,1);
- var v = Mid(r.filecontent,t,1);
- // Create an array for the letters of the days of the week
- var l = [];
- l[1] = "S,M,T,W,F";
- l[2] = "u,o," & v & ",h,r,a";
- l[3] = "n," & v & ",d,u,i,t";
- l[4] = "n,s,r,u";
- l[5] = v & ",s,r";
- l[6] = "s";
- // Let's suffix everything with "day" just for fun
- var s = "day";
- // How many letters do we need?
- if(o==4){
- x = arraylen(l);
- }else if(o==3){
- x = 4;
- }else if(o==5||o==7){
- x = 5;
- }else{
- x = 3;
- }
- // If a million monkeys had a million typewriters ...
- do{
- var n = "";
- for(var i=1;i<=x;i++){
- n = n & ListGetAt(l[i],randrange(1,ListLen(l[i])));
- }
- }
- while
- (
- n & s != DayOfWeekAsString(o)
- );
- // Whew, that was a lot of work, let's set the stringified weekday now
- var f = n & s;
- // Security is important ... let's encode something
- var e = toString(toBinary("U3VuZGF5LE1vbmRheSxUdWVzZGF5LFdlZG5lc2RheSxUaHVyc2RheSxGcmlkYXksU2F0dXJkYXk="));
- // Ok, now go get the list position to tell us the ordinal day
- for(var j=1;j<=ListLen(e);j++){
- if(ListGetAt(e,j) == f){
- f = j;
- break;
- }
- }
- return f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement