5 ms·
The current world record for the shortest C program that prints 12 Days of Christmas lyrics is 431 bytes: https://code.golf/12-days-of-christmas#c https://code.
by JayXon 3y ago
The current world record for the shortest C program that prints 12 Days of Christmas lyrics is 431 bytes:
https://code.golf/12-days-of-christmas#c https://code.golf/12-days-of-christmas#c
- AaronM 3y agoIs it broken for anyone else the code prints hello world and then some numbers
- JayXon 3y agoThe leaderboard is public but the actual code is private, that hello world is just an example c program.
- Tiberium 3y agoTo be honest, I understand code.golf's premise, but still, code being public (maybe optionally?) would be nice.
- hddqsb 3y agoI agree. Stack Exchange's Code Golf has public source, but the best there is 644 bytes: https://codegolf.stackexchange.com/a/4198 https://codegolf.stackexchange.com/a/4198
- kolleykibber 3y agoWell that post just cost me a couple of hours. And still 136 bytes off 431: #define p printf int main(){const char *g[]={"A Partridge in a Pear Tree.\n","Two Turtle Doves, and","Three French Hens,","Four Calling Birds,","Five Gold Rings,"," Geese-a-Lay"," Swans- a-Swimm","t Maids-a-Milk","e Ladies Danc"," Lords-a-Leap"," Pipers Pip","Twelve Drummers Drumm"}; const char *d[{"First","Second","Third","Four","Fif","Six","Seven","Eigh","Nin","Ten","Eleven","Twelf"};for(int i=0,j;i<12;i++){p("On the %s%s day of Christmas\nMy true love sent to me\n",d[i],i>2?("th"):""); for(j=i;j>=0;j--){p("%s%s%s\n",j>4&&j<11? d[j]:"",g[j],j>4?"ing,":"");}}}
- tgv 3y agoAre those consts really necessary? There are also a few character missing after char *d.
- junon 3y agowhich characters are missing?
- huhtenberg 3y ago"]=" after "*d["
- junon 3y agoIt's not necessary in C.
- tgv 3y agoYou should tell my compiler.
- huhtenberg 3y agoconst char *d[{"First","Second",...,"Twelf"}; is not a valid C unconditionally.
- mananaysiempre 3y ago> Are those consts really necessary? Technically yes, initializing a plain char * from a const char * (from array decay) is a constraint violation (an error the standard requires the compiler to detect and complain about) even in C89. Many compilers will let you off with a warning though.
- huhtenberg 3y agoYou can shave 25 more by using printf as is, removing "const", removing spaces between char and *, and removing parenthesis around "th".