Skip to content

Instantly share code, notes, and snippets.

@rexim
Created June 13, 2024 18:25
Show Gist options
  • Save rexim/f582098611b2be202051ba543e21da05 to your computer and use it in GitHub Desktop.
Save rexim/f582098611b2be202051ba543e21da05 to your computer and use it in GitHub Desktop.
// cc -w -include time.h -o qlock qlock.c // MIT Copyright (c) Tsoding
char*s="// cc -w -include time.h -o qlock qlock.c // MIT Copyright (c) Tsoding\n"
"char*s=\"?\";x,y,d[8],i,dx;f[]={31599,19812,14479,31207,23524,29411,29679,\n"
"30866,31727,31719,1040};char*so,*si;p(ch){i=x/2/(3+2);dx=x/2%(3+2);if(i<8&&(y-5)\n"
"/2<5&&dx<3&&(f[d[i]]>>((5-(y-5)/2-1)*3+dx))&1)printf(\"\\033[1;41;30m%c\\033[0m\",ch\n"
");else printf(\"%c\",ch);if(ch=='\\n'){y+=1;x=0;}else x+=1;}gd(){time_t t=time(NULL);struct\n"
" tm*tm=localtime(&t);d[0]=tm->tm_hour/10;d[1]=tm->tm_hour%10;d[2]=10;d[3]=tm->tm_min\n"
"/10;d[4]=tm->tm_min%10;d[5]=10;d[6]=tm->tm_sec/10;d[7]=tm->tm_sec%10;}main(){for\n"
"(gd();;printf(\"\\n\\033[%dA\\033[%dD\",y+1,x),sleep(1),gd())for(so=s,x=0,y=0;*so;so++\n"
")if(*so==63)for(si=s;*si;si++)switch(*si){case'\\n':p('\\\\');p('n');p('\"');p('\\n')\n"
";p('\"');break;case'\"':p('\\\\');p('\\\"');break;case'\\\\':p('\\\\');p('\\\\');break;default\n"
":p(*si);}else p(*so);}";x,y,d[8],i,dx;f[]={31599,19812,14479,31207,23524,29411,29679,
30866,31727,31719,1040};char*so,*si;p(ch){i=x/2/(3+2);dx=x/2%(3+2);if(i<8&&(y-5)
/2<5&&dx<3&&(f[d[i]]>>((5-(y-5)/2-1)*3+dx))&1)printf("\033[1;41;30m%c\033[0m",ch
);else printf("%c",ch);if(ch=='\n'){y+=1;x=0;}else x+=1;}gd(){time_t t=time(NULL);struct
tm*tm=localtime(&t);d[0]=tm->tm_hour/10;d[1]=tm->tm_hour%10;d[2]=10;d[3]=tm->tm_min
/10;d[4]=tm->tm_min%10;d[5]=10;d[6]=tm->tm_sec/10;d[7]=tm->tm_sec%10;}main(){for
(gd();;printf("\n\033[%dA\033[%dD",y+1,x),sleep(1),gd())for(so=s,x=0,y=0;*so;so++
)if(*so==63)for(si=s;*si;si++)switch(*si){case'\n':p('\\');p('n');p('"');p('\n')
;p('"');break;case'"':p('\\');p('\"');break;case'\\':p('\\');p('\\');break;default
:p(*si);}else p(*so);}
@andriemc
Copy link

glock.c?

@gusteivos
Copy link

croke ?

@CHEpachilo
Copy link

'i=x/2/(3+2);dx=x/2%(3+2);'

Why not i=x/10;dx=x/2%5;?

(5-(y-5)/2-1)*3

Basically 12-(y-5)/2*3

Also k=10; will save some space and x=y=0; instead of x=0,y=0;

Ну кисонька, милая, ну ещё рюмашечку

@tralph3
Copy link

tralph3 commented Jun 16, 2024

I can't believe nobody yet suggested to assign the values of d with braces like so:

d[8] = {
    tm->tm_hour/10,
    tm->tm_hour%10,
    [...]
}

Instead of assigning by index.

@CHEpachilo
Copy link

I can't believe nobody yet suggested to assign the values of d with braces like so:

d[8] = {
    tm->tm_hour/10,
    tm->tm_hour%10,
    [...]
}

Instead of assigning by index.

I thought about it. I didn't touch C for almost 10 years, but I believe this will work only with dynamic array, witch need a little more typing to work.

@alexlnkp
Copy link

alexlnkp commented Jun 22, 2024

it's too small now i have to add copious amounts of padding just so the clock isn't cropped 😔

/**********************ld -r -b binary -o qlock.o qlock.c*********************/
/*****************cc -w -include time.h -o out qlock.c qlock.o****************/
extern char _binary_qlock_c_start[];x,y,d[8],i,dx;f[]={31599,19812,14479,31207,\
23524,29411,29679,30866,31727,31719,1040};char*so,*si;p(ch){i=x/2/(3+1);dx=x/2\
%(3+1);if(i<8&&(y-1)/2<5&&dx<3&&(f[d[i]]>>((5-(y-1)/2-1)*3+dx))&1)printf(/****/
"\033[1;41;30m%c\033[0m",ch);else putchar(ch);if(ch=='\n'){y+=1;x=0;}else/****/
x+=1;}gd(){time_t t=time(NULL);struct tm*tm=localtime(&t);d[0]=tm->tm_hour/10;\
d[1]=tm->tm_hour%10;d[2]=10;d[3]=tm->tm_min/10;d[4]=tm->tm_min%10;d[5]=10;d[6]\
=tm->tm_sec/10;d[7]=tm->tm_sec%10;}main(){for(gd();;printf("\n\033[%dA\033[%dD"
,y+1,x),sleep(1),gd())for(so=_binary_main_c_start,x=0,y=0;*so;so++)p(*so);}/***
******************************************************************************/

@a17sol
Copy link

a17sol commented Jul 27, 2024

My own compact version without cheating like linker source code embedding. 911 bytes.
Compile: gcc -include stdio.h -include string.h -include time.h -include unistd.h quine_clock.c

char *s="char *s=%c%s%c; char S[1024];int d[] = {32319,31812,19129,32437,31879,991\
1,30399,4001,32447,32439,320};void main(){sprintf(S,s,34,s,34,34,92,34,34,34,34,34\
,34,92,34,10);for(;;){int lin=-3,G=-5,i=0;for(i;i<strlen(S);i++){time_t t=time(0);\
printf(%c%cx1b[%%s%c,(d[ctime(&t)[G/4+11]-48]>>(lin+(G%4)*5))&1&&!((G-15)/16)&&!((\
lin-2)/3)?%c31m%c:%c90m%c);putchar(S[i]);G+=i%2;if(G>35){putchar(lin<2?92:0);putch\
ar(10);lin++;G=-5;}}sleep(1);printf(%c%cx1b[11A%c);}}%c"; char S[1024];int d[] = {
32319,31812,19129,32437,31879,9911,30399,4001,32447,32439,320};void main(){sprintf
(S,s,34,s,34,34,92,34,34,34,34,34,34,92,34,10);for(;;){int lin=-3,G=-5,i=0;for(i;i
<strlen(S);i++){time_t t=time(0);printf("\x1b[%s",(d[ctime(&t)[G/4+11]-48]>>(lin+(
G%4)*5))&1&&!((G-15)/16)&&!((lin-2)/3)?"31m":"90m");putchar(S[i]);G+=i%2;if(G>35){
putchar(lin<2?92:0);putchar(10);lin++;G=-5;}}sleep(1);printf("\x1b[11A");}}

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