Advertisement
jo5h

Friday Puzzler: The Days of The Week

Oct 14th, 2011
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Note that this code is needlessly complicated - it was part of the requirements.
  3. */
  4.  
  5. function GetDaysTheHardWay(d){
  6.  
  7.     // Get ordinal date
  8.     var m = dateformat(d,"ddd");
  9.    
  10.     var w = '{"DAYS":{"SUN":["1"],"MON":["2"],"TUE":["3"],"WED":["4"],"THU":["5"],"FRI":["6"],"SAT":["7"]}}';
  11.     w = DeserializeJSON(w);
  12.    
  13.     // I could stop here, but why? Let's make EXTRA sure we're right.
  14.     var o = w.DAYS[m][1];
  15.    
  16.     // E's are important - let's get one from a reliable source
  17.     var h = new http();
  18.     h.setMethod("get");
  19.     h.setUrl("http://www.coldfusionjedi.com/index.cfm/2011/10/14/Friday-Puzzler-The-Days-of-The-Week");
  20.     var r = h.send().getPrefix();
  21.     var t = Find("e",r.filecontent,1);
  22.     var v = Mid(r.filecontent,t,1);
  23.    
  24.     // Create an array for the letters of the days of the week
  25.     var l = [];
  26.     l[1] = "S,M,T,W,F";
  27.     l[2] = "u,o," & v & ",h,r,a";
  28.     l[3] = "n," & v & ",d,u,i,t";
  29.     l[4] = "n,s,r,u";
  30.     l[5] = v & ",s,r";
  31.     l[6] = "s";
  32.    
  33.     // Let's suffix everything with "day" just for fun
  34.     var s = "day";
  35.    
  36.     // How many letters do we need?
  37.     if(o==4){
  38.         x = arraylen(l);
  39.     }else if(o==3){
  40.         x = 4;
  41.     }else if(o==5||o==7){
  42.         x = 5;
  43.     }else{
  44.         x = 3;
  45.     }
  46.    
  47.     // If a million monkeys had a million typewriters ...
  48.     do{
  49.         var n = "";
  50.         for(var i=1;i<=x;i++){
  51.             n = n & ListGetAt(l[i],randrange(1,ListLen(l[i])));
  52.         }
  53.     }
  54.     while
  55.     (
  56.         n & s != DayOfWeekAsString(o)
  57.     );
  58.    
  59.     // Whew, that was a lot of work, let's set the stringified weekday now
  60.     var f = n & s;
  61.    
  62.     // Security is important ... let's encode something
  63.     var e = toString(toBinary("U3VuZGF5LE1vbmRheSxUdWVzZGF5LFdlZG5lc2RheSxUaHVyc2RheSxGcmlkYXksU2F0dXJkYXk="));
  64.    
  65.     // Ok, now go get the list position to tell us the ordinal day
  66.     for(var j=1;j<=ListLen(e);j++){
  67.         if(ListGetAt(e,j) == f){
  68.             f = j;
  69.             break;
  70.         }
  71.     }
  72.        
  73.     return f;
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement