Inspiration. Posted with permission.

Print one of the possible XKCD calendar "facts":

XKCD Calendar Facts

You can get the raw text and structure from my APL reference implementation or from Explain XKCD's transcript (including the title text just under the illustration).


At every decision node, there must be an equal (pseudo-)random chance of each choice.

You may use all uppercase.

You must generate three sentences; a question, a reason, and a title text.

The three sentences should be ended by ?, ., and . respectively, and separated from each other by a single space.

The only extra white-space you may include is one trailing space and/or line break.


Did you know that the Latest Sunset drifts out of sync with the Zodiac because of time zone legislation in Indiana? Apparently it's getting worse and no one knows why. While it may seem like trivia, it has to be corrected for by GPS satellites.

Did you know that Leap Year happens later every year because of precession of the equator? Apparently scientists are really worried. While it may seem like trivia, it is taken advantage of by high-speed traders.

Did you know that Easter drifts out of sync with the atomic clock in Colorado because of a decree by the pope in the 1500s? Apparently scientists are really worried. While it may seem like trivia, it causes huge headaches for software developers.

  • \$\begingroup\$ @Rod I never said anything about the chart. I said to get the text from my reference implementation (which includes it) or from Explain XKCD (with a note to include the title text). \$\endgroup\$ – Adám Dec 19 '17 at 13:14
  • \$\begingroup\$ Are leading spaces in the output allowed? \$\endgroup\$ – Erik the Outgolfer Dec 19 '17 at 14:30
  • \$\begingroup\$ @EriktheOutgolfer No. \$\endgroup\$ – Adám Dec 19 '17 at 14:31
  • \$\begingroup\$ Related \$\endgroup\$ – FryAmTheEggman Dec 19 '17 at 16:05
  • \$\begingroup\$ Did you know that shark week happens at the wrong time every year because of an arbitrary decision by Benjamin Franklin? Apparently it causes a predictable increase in car accidents. I... I mean... I... Okay. \$\endgroup\$ – Magic Octopus Urn Dec 19 '17 at 16:54

Befunge-93, 1959 1930 bytes

#<<<*2\>#$$:0\`#$_\$55++:64*g48*-90^https://xkcd.com/1930/^<<<<<<>#\\:#< >#<>#<^

3Did you know that %the %fall'spring) equinox'winter'summer" )solstice)Olympics!
)earliest'latest(sunrise'sunset0daylight saving"s& time&leap $day%year'Easter(ha
rvest&super&blood& moon3Toyota Truck Month+Shark Week)happens (earlier&later2at
the wrong time, every year=drifts out of sync with the $sun%moon'zodiac*Gregoria
n&Mayan&lunar'iPhone* calendar9atomic clock in Colorado'might +not happen-happen
 twice+ this year- because of :time zone legislation in (Indiana(Arizona'RussiaB
a decree by the Pope in the 1500s+precession*libration)nutation)libation-eccentr
icity*obliquity) of the -earth's axis(equator/Prime Meridian3International Date,
Mason-Dixon& Line8magnetic field reversal:an arbitrary decision by 2Benjamin Fra
nklin-Isaac Newton$FDR.? Apparently Rit causes a predictable increase in car acc
idents@that's why we have leap seconds>scientists are really worriedEit was even
 more extreme during the +Bronze Age(Ice Age+Cretacious&1990sFthere's a proposal
 to fix it, but it 2will never happen;actually make things worse7is stalled in C
ongress:might be unconstitutionalHit's getting worse and no one knows whyE. Whil
e it may seem like trivia, it Ncauses huge headaches for software developersLis
taken advantage of by high-speed tradersFtriggered the 2003 Northeast BlackoutJh
as to be corrected for by GPS satellitesRis now recognized as a major cause of W
orld War I" "# "$) (6DLTV`b$ "$&% "$&2# *B& "$&(*% *,PR& "$&2>% "$&(

Try it online!


In the first three lines, we start by building up a kind of state table on the stack, representing the graph of all possible sentences. These stack entries are grouped into pairs, so there is first a string item, and then a jump or branch. Where necessary, the graph is padded with empty strings and zero-length jumps in order to meet this requirement.

Our main loop then begins by popping a number, representing a string item, off the stack. This number is interpreted as an offset into the string table in the lower section of the source. The string table is essentially a kind of linked list, wrapped over multiple lines to fit into Befunge's constrained memory space.

After outputting a string, the next item on the stack is either a jump or branch. If the number is less than 32, it's a jump, which we interpret by dropping that many pairs of items from the stack. If the number is 32 or more, it's a branch, and we use the value (minus 32) to lookup the branch details from the table on the last line of the source.

The entries in the branch table each consist of a count, followed by a list of offsets. Once we know which branch to use, we simply generate a random number, modulo the branch count, to lookup the appropriate offset. This offset is then interpreted as a jump, dropping the required number of items from the stack.

We repeat this process, outputting a string, then performing a jump or branch, until we run out of stack entries. At that point, we simply output a "." to mark the end of the final sentence, and then exit.

  • 2
    \$\begingroup\$ What is the URL doing in there? \$\endgroup\$ – Adám Dec 21 '17 at 9:19
  • 3
    \$\begingroup\$ @Adám I had a bit of space in the middle of the line and thought it would be a neat way to credit the original comic. The byte count also kind of references the comic, but that was entirely coincidental. \$\endgroup\$ – James Holderness Dec 21 '17 at 10:30
  • \$\begingroup\$ This is surprisingly fast... \$\endgroup\$ – Erik the Outgolfer Dec 24 '17 at 12:52

Javascript (ES6), 1698 1510 1506 1501 bytes

Thanks to 12Me21 for fixing a bug in the code, which added 2 bytes

f= and document.write(f()) are not part of the byte count

f=_=>eval(`"Did you know that {the {Fall;Spring} Equinox;the {Wint;Summ}er {Solstice;Olympics};the {Earli;Lat}est Sun{rise;set};Daylight Saving{;s} Time;Leap {Day;Year};Easter;the {Harvest;Super;Blood} Moon;Toyota Truck Month;Shark Week} {happens {earlier;later;at the wrong time} every year;drifts out of sync with the {Sun;Moon;Zodiac;{Gregorian;Mayan;Lunar;iPhone} Calendar;atomic clock in Colorado};might {not happen;happen twice} this year} because of {time zone legislation in {Indian;Arizon;Russi}a;a decree by the pope in the 1500s;{{precession;eccentricity;obliquity};{lib;liber;nut}ation} of the {Moon;Sun;Earth's axis;equator;prime meridian;{international date;mason-dixon} line};magnetic field reversal;an arbitrary decision by {Benjamin Franklin;Isaac Newton;FDR}}? Apparently {it causes a predictable increase in car accidents;that's why we have leap seconds;scientists are really worried;it was even more extreme during the {{Bronz;Ic}e Age;{Cretaceou;1990}s};there's a proposal to fix it, but it {will never happen;actually makes things worse;is stalled in congress;might be unconstitutional};it's getting worse and no one knows why}. While it may seem like trivia, it {causes huge headaches for software developers;is taken advantage of by high-speed traders;triggered the 2003 Northeast Blackout;has to be corrected for by GPS satellites;is now recognized as a major cause of World War I}."`.split`{`.join`"+(a=>a[Math.random()*a.length|0])(["`.split`}`.join`"])+"`.split`;`.join`","`)


Python 2, 1297 bytes

-419 bytes thanks to ovs.


Try it online!

The actual code:

from random import*
print'Did you know that '+c('the '+c('fall','spring')+' equinox','the '+c('winter','summer')+' '+c('solstice','olympics'),'the '+c('earliest','latest')+' '+c('sunrise','sunset'),'daylight saving'+c('','s')+' time','leap '+c('day','year'),'easter','the '+c('harvest','super','blood')+' moon','toyota truck month','shark week')+' '+c('happens '+c('earlier','later','at the wrong time')+' every year','drifts out of sync with the '+c('sun','moon','zodiac',c('gregorian','mayan','lunar','iPhone')+' calendar','atomic clock in colorado'),'might '+c('not happen','happen twice')+' this year')+' because of '+c('time zone legislation in '+c('indiana','arizona','russia'),'a decree by the Pope in the 1500s',c('precession','libation','nutation','libation','eccentricity','obliquity')+' of the '+c('moon','sun',"earth's axis",'equator','prime meridian',c('international date','mason-dixon')+' line'),'magnetic field reversal','an arbitrary decision by '+c('Benjamin Franklin','Isaac Newton','FDR'))+'? Apparently '+c('it causes a predictable increase in car accidents',"that's why we have leap seconds",'scientists are really worried','it was even more extreme during the '+c('bronze age','ice age','cretacious','1990s'),"there's a proposal to fix it, but it "+c('will never happen','actually make things worse','is stalled in Congress','might be unconstitutional'),"it's getting worse and no one knows why")+'. While it may seem like trivia, it '+c('causes huge headaches for software developers','is taken advantage of by high-speed traders','triggered the 2003 Northeast Blackout','has to be corrected for by GPS satellites','is now recognized as a major cause of World War I')+'.'

That was tiring. I haven't even done basic golfing. Somebody please write a script to golf this.

  • \$\begingroup\$ I think this fails the spec of an equal pseudo-random chance at each decision node at the Gregorian/Mayan/Lunar/iPhone calendar node. You have a choice function for those four calendar types embedded within another choice. This means that "Gregorian calendar" will be a quarter as likely as "atomic clock in Colorado". \$\endgroup\$ – Sellyme Dec 19 '17 at 13:43
  • 3
    \$\begingroup\$ I think those are separate decision nodes. "Drifts out of sync with" connects to "Sun" "Moon" "Zodiac" "_ Calendar" and "Atomic clock in Colorado", and the choice between "Gregorian" "Mayan" "Lunar" and "iPhone" is only done if the "Calendar" branch is chosen. EDIT: Also, the reference implementation has the same behavior. \$\endgroup\$ – 12Me21 Dec 19 '17 at 13:48
  • \$\begingroup\$ Yes, each node splits even, no matter how many sub-nodes it has. \$\endgroup\$ – Adám Dec 19 '17 at 14:01
  • \$\begingroup\$ It looks like you've got 'libation' twice - one of them should be 'libration'. At least in the uncompressed code - not sure if the compressed version is the same. \$\endgroup\$ – James Holderness Dec 20 '17 at 1:08

Charcoal, 806 bytes

≔”}‽÷⌊&β¶&⁰5EYB∕¤ⅉ‖≧I2[y·↔m⁷b∕¶⎆w‹ta≔Þ…¤eN⌕⟦1H}⁷φb$≧xζ→j5⮌↗2Σ↶C$JiψT↧⊘ν;{Fκⅉ⊘V⁵)}LZ)←‴F9cCIj+FJ➙N¶℅Pφ⦄≧πΦjt/;⊗…→⎇↓y⁻OD¤HRw2◧eE≦⊗▶⁴Uμ4⁶⊟P}⁼Ruf→u≧″℅9ξ→W⊗7≧↨↥ω⎚,_-,*U∕$⊖τJb4%L'⪪*⎇⊕>Þ↨IQ.&XVSv⧴×↑N:εγC~f≔hI¶⊖⎇N6ydy"⁸?⁷∕Oυ⁻~Þ⁶πv″ZOgΦ✂⊘qV↓Y5U,fν¶⁼⟲Y⁺⪪“↓‹5Hψ.>⊕LS⁸◨›±3¤�[<⊟D´YυΣOR↓↓g⟧⎈″:;9≧¿×➙ρlZσ31‴8↖HXυ3@⁺�@δIΣ≔⁺@ⅉCX⎇",H²⁻↥uνu⎚⌊ÀW⊘∕U ψu]q➙⟲BoF⧴Qψ8)Zk⌕⊗ü;≡N±$⊞QU≕⁹↘NYFY?⊗↖\≦∧₂!Fd⌈B"η№⁻⎈O2jηQμfÞωσdJ↧Àκ«ⅈ∕+¤êE�№F´⟲τ₂Gξr1⦃:>Oa²O[)¬X⎚∧V⊖«⪫J⁼0✂⦄Blν≦&C₂?⁹κIWÞ⁶≕>u/EKπd4ζ¤h]≕D@;VWR$▷ω≔BU″″◧⁸|%↔φ;Φ?@R:↙!,⧴¹3H%⁸⧴↨⁵&⁼E¶N V⬤⌊←}⁸⁺aw⌈Vς2A§A⟦W3«;{aZKl⊞Lξd⌊2≦2?⎈OM↔ü?⎚_Q▶δMp>{✂Mx§+↔⎆}Cκ·W∧Sd⎇⁹_ςCüI.G↓x≕χ«]n⦄&➙{‽ι⦃⁺^⦃Jk⎈O+oκs◧¿#W↙QR[Lα±´@⁰¶◧⊗βυ⊕⁴…«✳τi"TWι&=l¦⦄Þ⪪Þ▷‴υγ±A↥2⭆⁴≕↖≔…L¦ê⊘↥Bwψ¦⊘⊕*YkxAyg-'≦sΦd4◨υÀ?⁶[)…WS×∧ηt\e↗⊕Xκ≕№q₂‽Az←ERT◨⟦◨<1↧Φ…⊗E›c*«R↥M6-±⌀↑F⟲#π'F5/±κ;↗~&ζTUI⁺U⦃⸿?^↙i⧴t”θFβ≔⁺⁺§⪪θι⁰‽✂⪪θι¹±¹¦¹⊟⪪θιθθ

Try it online! Link is to verbose version of code. Explanation:

 ”....”                             Compressed string
≔      θ                            Assign to `q`
         β                          Lowercase letters
        F                           Loop over each letter
              ⪪θι   ⪪θι      ⪪θι    Split `q` at that letter
             §   ⁰                  First string in split (i.e. prefix)
                   ✂   ¹±¹¦¹        Slice split excluding prefix and suffix
                  ‽                 Select random element
                            ⊟       Pop last string (i.e. suffix)
           ⁺⁺                       Concatenate
          ≔                     θ   Assign to `q`
                                 θ  Print `q`

R, 1903 1751 1743 bytes

A simple brute-force solution. Might be some way to golf it down some more.

P(p('Did you know that',s(p(T,s('Fall','Spring'),'Equinox'),p(T,s('Winter','Summer'),s('Solstice','Olympics')),p(T,s('Earliest','Latest'),s('Sunrise','Sunset')),P('Daylight Saving',s('s',''),' Time'),p('Leap',s('Day','Year')),'Easter',p(T,s('Harvest','Super','Blood'),'Moon'),'Toyota Truck Month','Shark Week'),s(p('happens',s('earlier','later','at the wrong time'),'every year'),p('drifts out of sync with the',s('Sun','Moon','Zodiac',p('Gregorian',C),p('Mayan',C),p('Lunar',C),p('iPhone'),'atomic clock in Colorado')),p('might',s('not happen','happen twice'),'this year')),'because of',s(p('time zone legislation in',s('Indiana','Arizona','Russia')),'a decree by the pope in the 1500s',p(s('precession','libration','nutation','libation','eccentricity','obliquity'),'of the',s('Moon','Sun',"Earth's axis",'equator','prime meridian','international date line','mason-dixon line')),'magnetic field reversal',p('an arbitrary decision by',s('Benjamin Franklin','Isaac Newton','FDR')))),'? Apparently ',s('it causes a predictable increase in car accidents',"that's why we have leap seconds",'scientists are really worried',p('it was even more extreme during the',s('Bronze Age','Ice Age','Cretaceous','1990s')),p("there's a proposal to fix it, but it",s('will never happen','actually makes things worse','is stalled in congress','might be unconstitutional')),"it's getting worse and no one knows why"),'. While it may seem like trivia, it ',s('causes huge headaches for software developers','is taken advantage of by high-speed traders','triggered the 2003 Northeast Blackout','has to be corrected for by GPS satellites','is now recognized as a major cause of World War I'),'.')

Try it online!


JavaScript (ES6), 1275 bytes

f=(s=btoa`...`)=>/h/.test(s)?f(s.replace(/g([^gi]+)i/,(_,x)=>` ${(x=x.split`h`)[Math.random()*x.length|0]} `)):s.replace(/[a-f]/g,x=>" '-?,."['0x'+x-10]).replace(/ +(\W)/g,'$1')

where the ... represents the result of running atob() on this string and replacing \ with \\, ` with \`, 0x00 with \0, and 0x0D with \r:


Try it here, minus the btoa:



APL (Dyalog), 1302 bytes


Try it online!

Adám helped with this one...then challenged me to finish it. :P

-11 thanks to Adám (using his new SBCS tool I can abuse the encoding without extra cost).


Haskell, 1949 1938 bytes

import System.Random
data T a=N a[T a](T a)|P Char(T a)|E
l s=N s[]E
w=map l.words
k=map l.lines
g!a|(i,h)<-randomR(0,length a-1)g=(a!!i,h)
g#(P c n)|(e,v)<-g#n=(c:e,v)
g#(N s[]n)|(e,v)<-g#n=([' '|s>""]++s++e,v)
g#(N s c n)|(p,q)<-g!c,(m,h)<-q#p,(e,v)<-h#n=([' '|s>""]++s++m++e,v)
tail.fst.(#N"Did you know that"[t(w"fall spring")$l"equinox",t(w"winter summer")$d(w"solstice olympics")E,t(w"earliest latest")$d(w"sunrise sunset")E,N"daylight"(w"saving savings")$l"time",N"leap"(w"day year")E,l"easter",t(w"harvest super blood")$l"moon",l"Toyota truck month",l"shark week"](d[N"happens"(k"earlier\nlater\nat the wrong time")$l"every year",N"drifts out of sync with the"[l"sun",l"moon",l"zodiac",d(w"gregorian mayan lunar iPhone")$l"calendar",l"atomic clock in Colorado"]E,N"might"(k"not happen\nhappen twice")$l"this year"]$N"because of"[N"time zone legislation in"(w"Indiana Arizona Russia")E,l"a decree by the Pope in the 1500s",d(w"precession libration nutation libation eccentricity obliquity")$N"of the"(k"moon\nsun\nEarth's axis\nequator\nprime meridian\ninternational date line\nMason-Dixon line")E,l"magnetic field reversal",N"an arbitrary decision by"(k"Benjamin Franklin\nIsaac Newton\nFDR")E]$P '?'$N"Apparently"[l"it causes a predictable increase in car accidents",l"that's why we have leap seconds",l"scientists are really worried",N"it was even more extreme during the"[l"bronze age",l"ice age",l"cretaceous",l"1990's"]E,N"there's a proposal to fix it, but it"(k"will never happen\nactually makes things worse\nis stalled in congress\nmight be unconstitutional")E,l"it's getting worse and no one knows why"]$P '.'$N"While it may seem like trivia, it"(k"causes huge headaches for software developers\nis taken advantage of by high-speed traders\ntriggered the 2003 Northeast Blackout\nhas to be corrected for by GPS satellites\nis now recognized as a major cause of World War I")$P '.'E))<$>newStdGen

Try it online! (Has an extra 2 bytes for f=)

Mostly wrote this just so I could create the data structure. This could definitely be improved but I'm tired and I have to leave soon anyway. I think capitalization is mostly right but I'll convert it all to caps if it's wrong. That won't change the byte count or anything since I haven't done anything weird with the string data.

Basic idea is a linked list of trees where each node is either empty (E), a punctuation mark (P) or a string label with children. All nodes except E nodes have a "follower" node that comes after them.

EDIT: just noticed a spelling mistake (I wrote "no one know why" instead of "no one knows why") so I had to add a byte to fix it but I also found some code that could be cut out


APL (Dyalog Unicode), 1593 bytes

∊'Did you know that '(C('the '(S'Fall|Spring')' Equinox ')('the '(S'Winter |Summer ')(S'Solstice |Olympics '))('the '(S'Earliest |Latest ')(S'Sunrise |Sunset '))('Leap ',S'Day |Year ')'Easter '('the '(S'Harvest|Super|Blood')' Moon ')'Toyota Truck Month '('Daylight Savings Time '~C's∘')'Shark Week ')(C('happens '(S'earlier|later|at the wrong time')' every year ')('drifts out of sync with the '(S'Sun |Moon |Zodiac |atomic clock in Colorado|',' Calendar ',⍨S'Gregorian|Mayan|Lunar|iPhone'))('might '(S'not happen|happen twice')' this year '))'because of '(C('time zone legislation in ',S'Indiana|Arizona|Russia')'a decree by the pope in the 1500s'((S'precession|libration|nutation|libation|eccentricity|obliquity')' of the '(S'Moon|Sun|Earth''s axis|equator|prime meridian|',' line',⍨S'international date|mason-dixon'))'magnetic field reversal'('an arbitrary decision by ',S'Benjamin Franklin|Isaac Newton|FDR'))'? Apparently '(C'it causes a predictable increase in car accidents'('it was even more extreme during the ',S'Bronze Age|Ice Age|Cretaceous|1990s')'that''s why we have leap seconds'('there''s a proposal to fix it, but it ',S'will never happen|actually makes things worse|is stalled in congress|might be unconstitutional')'scientists are really worried' 'it''s getting worse and no one knows why')'. While it may seem like trivia, it '(S'causes huge headaches for software developers|is taken advantage of by high-speed traders|triggered the 2003 Northeast Blackout|has to be corrected for by GPS satellites|is now recognized as a major cause of World War I')'.'

Try it online!

Defines two helper functions and then uses them in one giant expression:

C← C (for Choose) is
?∘≢ a random number up to the number of elements in the argument
 from the arguments

S← S (for Split and Select) is
C choose among
'|'∘≠ the where-not-pipe

ϵnlist (flatten)
C chooses from a list of strings and S chooses from the substrings of a | delimited string, and these are just used in combination to construct a "fact".


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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