-
-
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);} |
croke ?
'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;
Ну кисонька, милая, ну ещё рюмашечку
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 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.
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 --std=c89 -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_qlock_c_start,x=0,y=0;*so;so++)p(*so);}/**
******************************************************************************/
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");}}
// clang++-19 -std=gnu++23 // MIT Copyright (c) X-Ray
#include <chrono>
#include <print>
#include <regex>
#include <thread>
constexpr char src[]{
#embed __FILE__
};int x, y;using namespace std;using namespace literals;string d; int
f[]={0x7B6F,0x4D64,0x388F,0x79E7,0x5BE4,0x72E3,0x73EF,0x7892,0x7BEF,
0x7BE7,0x0410,};enum:int{/*size*/H=5,W=3,/*padding*/pc=1,px=2,py=7,
/*scale*/sx=2,sy=2,StrLen=8,Widh=py+(W+pc)*sx*StrLen};void print(char
c){int i=(x-px)/sx/(W+pc);int dx=(x-px)/sx%(W+pc);if(i<StrLen&&(y>=
py)&& (x>=px)&& (dx<W)&&(f[d[i]]&1<<(dx+(H-1-(y-py)/sy)*W)))print(
"\033[1;41;30m{}\033[0m",c);else print("{}", c);if(c=='\n') {++y;x
=0;}else++x;}void get_time(){using namespace chrono;zoned_time loc
{current_zone(),system_clock::now()};auto time=loc.get_local_time()
.time_since_epoch();d=format("{:%T}",floor<seconds>(time)-floor<days>
(time));for(auto&& ch: d) ch -= '0';}int main(){while(true){get_time
();for(x=y=0;auto ch:src)print(ch);print("\n\033[{}A\033[{}D",++y, x)
;this_thread::sleep_for(1s);}}
https://godbolt.org/z/G8oqd1Tqo
uncompressed
// clang++-19 -std=gnu++23 // MIT Copyright (c) X-Ray
#include <chrono>
#include <print>
#include <regex>
#include <thread>
constexpr char src[]{
#embed __FILE__
};
int x, y;
using namespace std;
using namespace literals;
string d;
int f[]{
0x7B6F,
0x4D64,
0x388F,
0x79E7,
0x5BE4,
0x72E3,
0x73EF,
0x7892,
0x7BEF,
0x7BE7,
0x0410,
};
enum : int { // I hate defines and magic numbers
/*size*/
H = 5,
W = 3,
/*padding*/
pc = 1,
px = 2,
py = 7,
/*scale*/
sx = 2,
sy = 2,
StrLen = 8,
Widh = py + (W + pc) * sx * StrLen
};
void print(char c) {
int i = (x - px) / sx / (W + pc);
int dx = (x - px) / sx % (W + pc);
if(i < StrLen
&& (y >= py)
&& (x >= px)
&& (dx < W)
&& (f[d[i]] & 1 << (dx + (H - 1 - (y - py) / sy) * W)))
print("\033[1;41;30m{}\033[0m", c);
else
print("{}", c);
if(c == '\n') {
++y;
x = 0;
} else
++x;
}
void get_time() {
using namespace chrono;
zoned_time loc{current_zone(), system_clock::now()};
auto time = loc.get_local_time().time_since_epoch();
d = format("{:%T}", floor<seconds>(time) - floor<days>(time));
for(auto&& ch: d) ch -= '0';
}
int main() {
while(true) {
get_time();
for(x = y = 0; auto ch: src) print(ch);
print("\n\033[{}A\033[{}D", ++y, x);
this_thread::sleep_for(1s);
}
}
here is a perfectly rectangular cloq
without any completely nonfunctional padding
(obfuscation was prioritized over compactness)
T,w;char*s,*h="T,w;char*s,*h=#,*Q=#,v,c;C[9];I,m[],q,a,k,i,b,n,z;main(int A,char**V){T=A-1?atoi(V[1]):T;for"
"(;;){T%=86400;s=h;k=w=i=b=0;a=2~;q=n=1;C[8]=1+T%10;C[1]=1+T/36000;C[7]=1+T%60/10;C[2]=1+T/3600%10;C[4]=1+T"
"/60%60/10;C[5]=1+T/60%10;while((v=~h[w])){printf($`e[;$);z=(Q[2*(9*C[(i+1)/2]+k-2)+!(i%2)]-38)>>b;b-=(v==1"
"26&&(v=10,1))-1;z=(i&&i-17&&k>1&&k<11~&&z&1)&&(putchar(57),1);printf($2m$);I=i+=!(b%=6);k+=(I!=(i%=18))?(i"
"--,1):0;z=*s||v-35?0:(v=34,q=1,a=14,n=*s~||(s=n?Q:s,n));putchar(v==35?(q?(--q?10:34):a==109?(a=0,q=2,b--,3"
"4):*s++):(w++,v==36?34:v-96?v:92));a++;};T;~printf($%5i;m[]=L`$`e[m%ls`e[2m`$;`n`e[14A$,T,m);usleep(0xf424"
"0);T++;}}T=",*Q="V)^-V)&&&&&&V)^-V)V)B4,>,>,>,>,>B4V)F'V'^'R'L'F'F'F'dEb-,2&>&>&2F)^&2&dEb-,2&>&2F5&2&>,2b"
"-&4&5F3V2>222dE&2&2d5,&,&d)V5&>&>,2b-&)F'V&^-B4,>,>B4V)dE&2&,&)b5F'F'F'F'^-B4,>22^-22,>B4V)V)B4,>,>B4^-&)F"
"'V&",v,c;C[9];I,m[],q,a,k,i,b,n,z;main(int A,char**V){T=A-1?atoi(V[1]):T;for(;;){T%=86400;s=h;k=w=i=b=0;a=2
;q=n=1;C[8]=1+T%10;C[1]=1+T/36000;C[7]=1+T%60/10;C[2]=1+T/3600%10;C[4]=1+T/60%60/10;C[5]=1+T/60%10;while((v=
h[w])){printf("\e[;");z=(Q[2*(9*C[(i+1)/2]+k-2)+!(i%2)]-38)>>b;b-=(v==126&&(v=10,1))-1;z=(i&&i-17&&k>1&&k<11
&&z&1)&&(putchar(57),1);printf("2m");I=i+=!(b%=6);k+=(I!=(i%=18))?(i--,1):0;z=*s||v-35?0:(v=34,q=1,a=14,n=*s
||(s=n?Q:s,n));putchar(v==35?(q?(--q?10:34):a==109?(a=0,q=2,b--,34):*s++):(w++,v==36?34:v-96?v:92));a++;};T;
printf("%5i;m[]=L\"\e[m%ls\e[2m\";\n\e[14A",T,m);usleep(0xf4240);T++;}}T=43200;m[]=L" c-cloq (c) chri-k ";
(this uses sleep and takes the initial time from command line instead of showing the actual time, due to seeing -include time.h
as cheating)
glock.c?