1
\$\begingroup\$

Your goal is to write an obfuscated program that displays the current time.

Guidelines: The program can print local or global time. You are allowed to draw ASCII numbers, display an analog clock, etc. No input should be needed. Whether you include 12 or 24 hour, including AM/PM, milliseconds and seconds or not, it all doesn't matter. This is a popularity contest.

Inspired by sykes2.c, an impressive display of confusing naming, obscure language features, and clever tricks.

\$\endgroup\$

closed as off-topic by Peter Taylor, Justin, Konrad Borowski, ProgramFOX, Mhmd May 13 '14 at 18:40

  • This question does not appear to be about programming puzzles or code golf within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Why does the search feature on "Mark as duplicate" never work? \$\endgroup\$ – TheDoctor May 2 '14 at 21:48
  • \$\begingroup\$ @TheDoctor Find me a duplicate, and I will delete or modify. \$\endgroup\$ – qwr May 2 '14 at 21:50
  • \$\begingroup\$ It is just not a very interesting challenge. No restrictions on using built-in time functions. \$\endgroup\$ – TheDoctor May 2 '14 at 21:57
  • 1
    \$\begingroup\$ I would retract my downvote if that were stated clearly in the question; i misunderstood. \$\endgroup\$ – TheDoctor May 2 '14 at 22:02
  • 3
    \$\begingroup\$ This question appears to be off-topic because it doesn't have an objective spec. One person's "obfuscated" is another person's "I just prefer this style". \$\endgroup\$ – Peter Taylor May 6 '14 at 22:14
5
\$\begingroup\$

Analog clock, JS

Analog clock? Challenge accepted.

Golfed/Obfuscated into the zone of not-exactly-understanding-what-it-does-even-after-reading-through-a-few-times:

for(var a=new Date,b=a.getMinutes(),c=a.getHours()+b/60,d=[],e=Math.round,f=Math.PI,g=Math.sin,h=Math.cos,k=0;11>k;k++)d[k]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(var l=0;l<f;l+=0.05){var m=e(17/11*5*h(2*l)),n=e(5*g(2*l));d[n+5][m+8]=1}for(var p=0;2.5>=p;p+=0.5){var q=e(17/11*p*h(-(c*f/6)+f/2)),r=e(p*g(-(c*f/6)+f/2));d[r+5][q+8]=2}for(p=0;4.5>=p;p+=0.5){var s=e(17/11*p*h(-(b*f/30)+f/2)),t=e(p*g(-(b*f/30)+f/2));d[t+5][s+8]=3}d[5][8]=1;a="";for(k=d.length-1;-1<k;k--)a+=d[k].join("").replace(/0/g,".").replace(/1/g,"O").replace(/2/g,"h").replace(/3/g,"m")+"\n";console.log(a);

Outputs something like:

.....OOOOOOO......
...OO.......OO....
.OO...........O...
.O...h.........O..
O.....hh.......OO.
O......hOmmmmmmmO.
OO.............OO.
.O.............O..
.OO...........O...
...OO.......OO....
.....OOOOOOO......

...yeah, guess what time it is here. (Hint hint not AM)

Human readable version:

var date = new Date();
var min = date.getMinutes();
var hrs = date.getHours()+(b/60); // set up date
var a=[];
for(var i=0;i<11;i++)a[i]=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; // set up array
function putX(x,y,i){a[y+5][x+8]=i;} // just for source neatness; this is expanded out in the obfuscated version
for(var p=0;p<Math.PI;p+=0.05){ // draw clock border
    putX(Math.round((17/11)*5*Math.cos(2*p)), Math.round(5*Math.sin(2*p)), 1);
}
for(var p=0;p<=2.5;p+=0.5){ // draw hour hand (transforming the angle to work)
    putX(Math.round((17/11)*p*Math.cos(-(hrs*2*Math.PI/12)+(Math.PI/2))), Math.round(p*Math.sin(-(hrs*2*Math.PI/12)+(Math.PI/2))), 2);
}

for(var p=0;p<=4.5;p+=0.5){ // draw the minute hand like the hour hand
    putX(Math.round((17/11)*p*Math.cos(-(min*2*Math.PI/60)+(Math.PI/2))), Math.round(p*Math.sin(-(min*2*Math.PI/60)+(Math.PI/2))), 3);
}

putX(0,0,1); // set the center point

date=""; // reuse date for maximum confusion :)
for(var i=a.length-1;i>-1;i--)date+=a[i].join("").replace(/0/g, ".").replace(/1/g, "O").replace(/2/g, "h").replace(/3/g, "m")+"\n"; // output ASCII art to string
console.log(date); // output string to console
\$\endgroup\$
  • \$\begingroup\$ Whoa, I just realized the hour hand doesn't actually move during the hour. Fixing... \$\endgroup\$ – DankMemes May 3 '14 at 2:12
  • \$\begingroup\$ It's fixed. Hopefully there aren't any more bugs \$\endgroup\$ – DankMemes May 3 '14 at 2:19
3
\$\begingroup\$

Python

Might as well.

exec(lambda s:s[::2]+s[1::2])('ipmepno r(t" hwtetbpb:r/o/wtsiemre;.wgeobvb/rHoTwMsLe5r/."o)')
\$\endgroup\$
1
\$\begingroup\$

JavaScript / HTML (757 bytes)

Prints an analog clock on an HTML5 canvas. There's probably a lot more efficient ways to do this, but I think it turned out looking nice.

<canvas><script>S=150;c=document.currentScript.parentNode;c.width=c.height=2*S;t=c.getContext("2d");z=Math;r=2*z.PI;o=r/4;h=[[1,0.93],[4,0.9],[8,0.7]];m=[0,0,0];function d(){t.clearRect(0,0,c.width,c.height);t.lineWidth=2;t.beginPath();t.moveTo(2*S,S);    t.arc(S,S,0.99*S,0,r);for (i=0;i<60;++i){a=r*(i/60)+o;x=0.99*S*z.cos(a);    y=0.99*S*z.sin(a);t.moveTo(S+x,S+y);s=0.96;if (!(i%5)) s=0.90;t.lineTo(S+s*x,S+s*y);}t.stroke();u=new Date();m[0]=r*u.getSeconds()/60-o;m[1]=r*u.getMinutes()/60-o;m[2]=r*(u.getHours()%12)/12+(m[1]+o)/12-o;for(g=0;g<3;g++){t.beginPath();t.lineWidth=h[g][0];t.strokeStyle="black";if (!g) t.strokeStyle="red";x=h[g][1]*S*z.cos(m[g]);  y=h[g][1]*S*z.sin(m[g]);t.moveTo(S+x,S+y);t.lineTo(S,S);t.stroke();}setTimeout(d,500);}d();</script>

Human readable version on JSFiddle here.

\$\endgroup\$
0
\$\begingroup\$

GolfScript

The ultimate example of a magic number!

230140410535893441750932406053255553

23/`3/{~}%+'"#{'\+'}"'+~

Explanation coming soon.

\$\endgroup\$
0
\$\begingroup\$

CJam

"et phone home"S/_,_@T=~><{_A<{R_,+\+}*':}/;

Prints the local time as HH:mm:ss (24-hour)

Spoilers:

S/ splits by space (S=" ")
_,_ gets the resulting array length (3) twice
@T= extracts the "et" part (T=0)
~ evaluates et, which gives the current date and time in an array
>< extracts the time part (starting at index 3, length 3)
_A< checks if a value is less than 10 (A=10)
R_,+ evaluates to "0" (R="")
\+ prepends "0" to the number
{...}* executes the block if the condition (<10) was true
': is the colon character
{...}/ executes the block for each array element (hour, min, sec)
; pops the last value (a colon)

\$\endgroup\$
0
\$\begingroup\$

SVG + JavaScript (272 937 bytes)

I'm sorry; couldn't help myself. The SVG is probably way too big to fit on StackExchange, so you can access a live demo here (please note, it could lag your browser; do it at your own risk): http://varden.info/~mlindvall/jstime.obf.svg

Viewing the source code might crash your browser; do it at your own risk. Otherwise, downloading it and opening it in Notepad++ should be safe.

Since there are no rules, I'll have to admit I got huge help from an obfuscator, so this is more like a proof of concept rather than a real submission. Still, it was kind of fun to see this work.

Human readable version:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="44" width="110" version="1.1" xmlns="http://www.w3.org/2000/svg">
<text x="10" y="14" style="font-size: 14px;">Current time is:</text>
<text id="id" x="0" y="44" style="font-size: 30px;"></text>
<script type="text/javascript">
function t() {
    var a = new Date(), timeArray=[a.getHours(), a.getMinutes(), a.getSeconds()], delimiter='', result='';
    for (c = 0; c != 3; c++) {
        while (('' + timeArray[c]).length != 2) {
            timeArray[c] = '0' + timeArray[c];
        }
        result += delimiter + b[c];
        delimiter = ':';
    }
    document.getElementById("id").textContent = result;
}
t();
setInterval("t()", 1000); // Run every second for an updating clock
</script>
</svg>
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.