7 ms·
Xmas.c (1988)
- queuebert 3y agoOne of my favorite things about the IOCCC is that Larry Wall won it twice and then went on to design Perl, which explains a lot.
- deleted 3y ago[deleted]
- someplaceguy 3y agoRelated: https://www.mcmillen.dev/sigbovik/ https://www.mcmillen.dev/sigbovik/
- FredPret 3y agoI'd love to see what obfuscated Perl looks like!
- NelsonMinar 3y agoI'm still hoping to see unobfuscated Perl.
- codetrotter 3y ago(Insert “The Office” meme with Pam saying “they are the same picture”.)
- deleted 3y ago[deleted]
- rwmj 3y agoThat time we managed to sneak some (semi-)obfuscated Perl into the very serious Red Hat Enterprise Linux 6 customer documentation: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html-single/virtualization_administration_guide/index#sect-virt-win-reg-use https://access.redhat.com/documentation/en-us/red_hat_enterp...
- thomasjudge 3y ago"this simple Perl script"
- deleted 3y ago[deleted]
- bewuethr 3y agoThere's https://www.perlmonks.org/?node_id=45213 https://www.perlmonks.org/?node_id=45213 (see https://gist.github.com/cgoldberg/4332167 https://gist.github.com/cgoldberg/4332167 for the output)
- FredPret 3y agoThat’s amazing!
- chris_wot 3y agoThat’s a very old version of C. The function signature of main uses the old K&R style for function parameters. I doubt it would compile currently!
- bawolff 3y agoIt literally has 1988 in the title.
- chris_wot 3y agoOne self evident statement does not invalidate the other :-)
- uxp8u61q 3y agoIt does compile, even with `-std=c17` under GCC. With a few warnings about implicit `int`s, of course. Even `-Wall` only adds a single warning (about !0<t not meaning what you could think it means.)
- deleted 3y ago[deleted]
- arp242 3y ago> I doubt it would compile currently! It compiles (and runs!) fine with just "gcc a.c"; nothing more needed. clang does throw some fatal errors, but there's probably some combination of flags to make it work; I couldn't be bothered to look further. I've compiled plenty of code from the 80s; I can't recall a single example where it didn't work that wasn't due to OS-specific stuff. Tons of warnings and maybe some special-flags? Sure. But it works. There's even some modern (well, "modern") code around today that uses K&R style function parameters.
- sdkgames 3y ago>The program is smaller than even the 'compressed' form of its output, >and thus represents a new departure in text compression standards. 7z and gzip disagree with this statement.
- theideaofcoffee 3y agoThis particular entry to the IOCCC was for 1988, those two algorithms didn’t come about for a few more years after that, gzip in the early nineties and 7z later that decade. The note is probably correct when comparing against the state of the art at the time.
- sdkgames 3y agogzip is based on the DEFLATE algorithm, which is a combination of LZ77(1977) and Huffman coding(1952).( https://en.wikipedia.org/wiki/Gzip https://en.wikipedia.org/wiki/Gzip )
- acqq 3y agoYou are right. Here is the source of "compress" that existed at that time. It compresses the produced song to 1048 bytes, not less. https://www.nic.funet.fi/index/minix/compress.c https://www.nic.funet.fi/index/minix/compress.c The program that produces the song, without the introductory comment, is 913 bytes, as presented in the article. Removing whitespaces it uses just 800 bytes and produces the song which is 2359 chars here. The whole C is: main(t,_,a)char*a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_, main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t== 2?_<13?main(2,_+1,"%s%d%d\n"):9:16:t<0?t<-72?main(_,t, "@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;\ #q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;\ q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; \ r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#\ \ n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;\ {nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;\ #'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/") :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1): 0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);} It compiles and links even without #include.
- magerleagues 3y agoGreat explanation! And looks like the IOCCC is still going strong in 2023: https://www.ioccc.org/years.html https://www.ioccc.org/years.html
- NelsonMinar 3y agoThat page shows the last IOCCC was 2020. But the home page has an update from May 2023: "We do plan to hold a 28th IOCCC." Much like Nethack releases, some things are worth waiting for.
- anonymousiam 3y agoI grabbed this when it was originally published, but somehow the file name I have is different from the one in this article. Mine is called "carol.c" and I just compiled and ran it on a modern system. The compiler spat out the following warnings: gcc -o carol carol.c carol.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int] 2 | main(t,_,a ) | ^~~~ carol.c: In function ‘main’: carol.c:2:1: warning: type of ‘t’ defaults to ‘int’ [-Wimplicit-int] carol.c:2:1: warning: type of ‘_’ defaults to ‘int’ [-Wimplicit-int]
- sebtron 3y agoSurprisingly few warnings, and all on the same line!
- rwmj 3y agoGCC 14 won't permit implicit int any more ... https://fedoraproject.org/wiki/Changes/PortingToModernC#Removal_of_implicit_int https://fedoraproject.org/wiki/Changes/PortingToModernC#Remo...
- darknavi 3y agoGood. It's almost as bad as not returning a value from a function being a warning and not an error.
- bonzini 3y agoJust compile with -std=c89
- anonymousiam 3y agoI guess I got lucky then. This Ubuntu 23.10 install has gcc 13.2.0-4ubuntu3 installed from the repo. Given that the code is pre-ANSI C, and that it won in the category of "Least likely to compile successfully", it's surprising that there are no other issues. I wouldn't normally run such a radioactive distro, but this laptop is so new that there is no LTS distro that works on it. (AMD Ryzen 7 PRO 7840U w/ Radeon 780M Graphics)
- ramesh31 3y ago
- shimonabi 3y agoOur professor in college got us this in the printed study materials about the C language, so I remember that I typed it in by hand once.
- freedomwalker 3y ago[flagged]
- kazinator 3y agoThere is a similar task in Rosetta Code: a program to produce the "Old Lady Swallowed a Fly" iteratively growing song. https://rosettacode.org/wiki/Old_lady_swallowed_a_fly https://rosettacode.org/wiki/Old_lady_swallowed_a_fly
- merelysounds 3y agoI like how Tcl is just the lyrics, compressed: > puts [zlib inflate [binary decode base64 "7VRNa8MwDL3nV2(...)"]] https://rosettacode.org/wiki/Old_lady_swallowed_a_fly#Tcl https://rosettacode.org/wiki/Old_lady_swallowed_a_fly#Tcl Python, Nim, Julia and likely others have similar versions too.
- GrabbinD33ze69 3y agoThis resurfaced a good memory of my last two semesters of university (2022), professor showed us this code snippet right at the start of one lecture.
- dylan604 3y ago"I remember my last two semesters of university. All the way back to last year!" It's kind of fuzzy being such a long time ago (or maybe all of the beer and other consumables), but if I recall correctly (from last year),...." I can't tell if you were being serious or just a damn good understated bit of comedy
- svat 3y agoThe equivalent from the TeX world is `xii.tex`: \let~\catcode~`76~`A13~`F1~`j00~`P2jdefA71F~`7113jdefPALLF PA''FwPA;;FPAZZFLaLPA//71F71iPAHHFLPAzzFenPASSFthP;A$$FevP A@@FfPARR717273F737271P;ADDFRgniPAWW71FPATTFvePA**FstRsamP AGGFRruoPAqq71.72.F717271PAYY7172F727171PA??Fi*LmPA&&71jfi Fjfi71PAVVFjbigskipRPWGAUU71727374 75,76Fjpar71727375Djifx :76jelse&U76jfiPLAKK7172F71l7271PAXX71FVLnOSeL71SLRyadR@oL RrhC?yLRurtKFeLPFovPgaTLtReRomL;PABB71 72,73:Fjif.73.jelse B73:jfiXF71PU71 72,73:PWs;AMM71F71diPAJJFRdriPAQQFRsreLPAI I71Fo71dPA!!FRgiePBt'el@ lTLqdrYmu.Q.,Ke;vz vzLqpip.Q.,tz; ;Lql.IrsZ.eap,qn.i. i.eLlMaesLdRcna,;!;h htLqm.MRasZ.ilk,% s$;z zLqs'.ansZ.Ymi,/sx ;LYegseZRyal,@i;@ TLRlogdLrDsW,@;G LcYlaDLbJsW,SWXJW ree @rzchLhzsW,;WERcesInW qt.'oL.Rtrul;e doTsW,Wk;Rri@stW aHAHHFndZPpqar.tridgeLinZpe.LtYer.W,:jbye Put that in a .tex file and run `pdftex` on it, then look at the resulting PDF file, which will look like this: https://shreevatsa.net/post/xii/ https://shreevatsa.net/post/xii/
- fdsasd 3y agoYeah but that's not obfuscated, it just looks like normal TeX to me.
- svat 3y agoThere's a reason there's no IOCCC for Perl or TeX. :-) BTW there's a 2017 followup called xii-lat.tex: https://github.com/davidcarlisle/dpctex/tree/main/xii-lat https://github.com/davidcarlisle/dpctex/tree/main/xii-lat (https://mirrors.ctan.org/macros/plain/contrib/xii-lat/xii-lat.tex https://mirrors.ctan.org/macros/plain/contrib/xii-lat/xii-la...) — having been done nearly 20 years later, it has even more tricks, so is more "fun" to unpack.
- nullhole 3y agoIt's like a form of especially logical compression
- mattgodbolt 3y agoStill works on trunk (if you turn off the warning :)) https://compiler-explorer.com/z/hGvs1e9jo https://compiler-explorer.com/z/hGvs1e9jo
- fbodz 3y agoThis makes me think about kolmogorov complexity. The program here looks like gibberish but produces the desired output, would there be even shorter programs that don't look like they make sense but produce the same output? How would you search for these programs?
- tysam_and 3y agoI think it's honestly quite hard to know, as it's really (generally speaking, AFAIPK) impossible to directly compute the KC in most cases, only really from the feasibility standpoint we can check that it's slower than some other version/value. Which is quite exciting, it sets us up nicely for long-running competitions and the like due to the logarithmic-like growth curve (with sometimes some very fun discoveries on the ultra-tail-end of things! <3 :D) Am currently running a mini-competition with a current prize bounty of $100 (distributed proportionally by % contribution in logspace) for an LLM that can memorize the most digits of Pi by March of next year. Pi is nice as it actually is quite compressible in theory and seeing if a model is able to learn a sufficiently-close-to-the-MDL set of weights that recovers a highly-compressed algorithm from the data would be extremely nice, indeedy! However, whether this is feasible or not with off-the-shelf models and such is not entirely easy to know, so for now, it's just a digits-memorizing competition, and we shall see where it goes from there!!! <3 :'))))
- JayXon 3y agoThe 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
- nickdothutton 3y agoIanP was a colleague of mine a lifetime ago. Thanks for reminding me.
- IgorPartola 3y agoFun thing I learned recently about the 12 days of Christmas: every gift is a type of bird. Leaping ladies, lords, all of them.
- telcal 3y agoI'm not so sure about this. Wikipedia says "The earliest known publications of the words to The Twelve Days of Christmas were an illustrated children's book, Mirth Without Mischief, published in London in 1780" https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(song) https://en.wikipedia.org/wiki/The_Twelve_Days_of_Christmas_(... This site https://www.birdspot.co.uk/culture/the-birds-of-the-twelve-days-of-christmas https://www.birdspot.co.uk/culture/the-birds-of-the-twelve-d... tries hard to link them all to birds but it's a far stretch, considering it falls apart at "Five Gold Rings". "However, Mirth and Mischief includes an illustration that clearly depicts the rings as jewelry." Archive.org even has a scan of the book: https://archive.org/details/mirth_without_mischief/page/n7/mode/2up https://archive.org/details/mirth_without_mischief/page/n7/m...
- deprave 3y agoI learned that from The Office :D
- willswire 3y agoWow! A University of Delaware link on Hacker News? Go Hens!
- mdnahas 3y agoMy own investigation, from 20+ years ago: http://michaeldnahas.com/xmassong/index.html http://michaeldnahas.com/xmassong/index.html
- eek2121 3y agoMy brain hurts.
- usremane 3y agoHere's what Chat GPT came up with: #include <stdio.h> #define o putchar #define p main #define q(a) return a; #define r ) { #define s { #define t for #define u if #define v else #define w while char x="a partridge in a pear tree.\ntwo turtle doves\nand three french hens, four calling birds, five gold rings;\nsix geese a-laying, seven swans a-swimming,\neight maids a-milking, nine ladies dancing, ten lords a-leaping,\neleven pipers piping, twelve drummers drumming, "; char y[]={"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eigth", "ninth", "tenth", "eleventh", "twelfth"}; int p() s int i=0, j, k, l; t(;i<12;i++) s printf("On the %s day of Christmas my true love gave to me\n", y[i]); j=0, k=0, l=0; t(;x[j];j++) s u(x[j]==' ' && (l==i || (l<i && x[j+1]=='\n'))) s u(!k)r k=1; o('and '); } v u(x[j]!='\n')r o(x[j]); } v r k=0; l++; } } o('\n'); } q(0) }