Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

This idea is not mine, though I don't know where it originated. I once met it in a programming contest very long ago (1998, if I remember correctly). The task is to write a program in your favorite language that outputs 2012 and only 2012. The catch is that the program must still output 2012 after any one of its characters is modified. The modification can be either insertion, deletion or replacement. Of course, the modification will be such that the program is still syntactically valid.

Since I don't know all the programming languages, I have to ask the audience to help me and test the answers submitted.

Added: Many have commented that my definition of acceptable modifications is too vague. Here's my second attempt: The allowed modifications will leave your program syntactically valid and will not cause it to crash. There, I think that should cover all the compile-time, link-time and run-time errors. Though I'm sure that there will be some odd edge case in some language anyway, so when that comes up we'll look at it individually.

share|improve this question
How about runtime errors like reading a most likely invalid address? –  eBusiness Jan 2 '12 at 21:15
@PeterTaylor - There are 3 answers already, the C one with heavy revising. You can look for inspiration there. –  Vilx- Jan 2 '12 at 21:58
Anyone figured out if this is impossible in APL or GolfScript or similarly terse? –  Jeff Burdges Jan 3 '12 at 8:03
This has got me thinking about DNA and redundancy and the potential for cosmic rays to flip bits in my programs. Interesting stuff. –  Jon Purdy Jan 3 '12 at 8:55
... You need some sleep. –  Vilx- Jan 3 '12 at 8:57

37 Answers 37

up vote 50 down vote accepted

C, 53 characters


A bit longer than the scripting language answers, and follows the same basic principle. Relies on the fact that due to the constraints of C's syntax, the only letters that would be possible to change without making the program invalid are within the strings!

Edit: Shaved off 4 characters.

Reedit: Robustness increased, shaved off one character.

Re-redit: Longer, but more robust. Just try your & now! (Correctly this time).

Update: Shortened a bit; defeats most approaches seen so far.

Update: Changed int to void; should defeat the last possible approach to break it I can think of.

Update: I thunk of another approach; replacing the last a (may it rot) with 0; using two-letter names should deal with that problem.

Update: Last update revoked; assuming changes causing runtime errors are disallowed; a will work just fine.

Update: Backtracking some more; attempting to dereference *a will also segfault; so using void to tease a compile error out of it should not be necessary.

Update: And a final shortening; that relies on the string "2012" being placed at but one address (which is common); and that literal strings are read-only (also common).

Update: It cost me two characters, but I defeated your puny semi-colon!

share|improve this answer
main(){int a="2012";puts(strcmp(a,"2012")?"2012":&a);} –  M. Joanis Jan 2 '12 at 20:50
@PaulR: Now changed to register void; The register is there to prevent &; the void is there to prevent *. –  Williham Totland Jan 2 '12 at 21:38
OK... correct me if this is invalid C, but it just worked on my VS2010. Insert a ; between puts and (. –  Vilx- Jan 3 '12 at 10:58
+1, Congratulations, I think you've nailed it. I wrote a simple test harness that tried to compile and run every possible one-char variation of your code, and every single one of them either did not compile, crashed or printed 2012! (I only used printable ASCII characters for the insertion and substitution tests, but I doubt expanding the repertoire would help.) –  Ilmari Karonen Jan 3 '12 at 14:06
@IlmariKaronen: Heh, that's a lot of effort; thanks for going through all that. :) –  Williham Totland Jan 3 '12 at 14:14

Haskell, 19


or, as a full program,



For a bit more fun:


To get one that can't be modified in such a way that yields merely a runtime error, we can encode the information in the lengths of lists which can't be modified using just one-character-changes, i.e.


To make it more modifiable (safely), we can also use the number itself as list element – just need to make it strings to prevent exchanging commas for plus':


As this string is just the result of the expression, we can also again substitute it with that – not a problem thanks to Haskell's lazyness


main=putStrLn a

The init does nothing but ensure we get an empty list there.

We can also include the type system in the redundancy scheme and then write the number in a way that could be modified with one-character changes...

u :: Enum a => (a,[b])->(a,b)
u(a,[b]) = (succ a , b)
p :: (a,b)->(a,[b])
p(a,b) = (a,[b])

ι :: (Int,())           -- Integral type to make sure you can't make it 0/0
ι = (\n -> (n-n,()))0

twothousandandtwelve = map(head.show.fst) [ u.p.u.p$ι , ι , u.p$ι , u.p.u.p$ι ]

(GHCi> twothousandandtwelve ≡> "2012")

You could now change any one u to p vice versa, but that would always mess up the deepness of list stackings in the second tuple element and thereby trigger a compile-time error.

This idea could be expanded further in such a way that whole texts could be encoded compactly, easy to read and edit, and still safe from modifing single characters.

And yet another one...

main = print N2012
data Counter = Τv |Πy |Υj |Cε |Ho |Φϑ |Ωm |Sg |Πl |Pt |Yϑ |Γσ |Km |Φz |Εα |Av |Ζρ |Ηρ |Εv |Κs |Rζ |Γϑ |Οc |Dι |Rυ |Λd |Bγ |Wt |Xε |Ωη |Ιa |Hζ |Ed |Qj |Wπ |Κw |Qu |Γο |Oι |Mσ |Ωκ |Yg |Kυ |Aj |Du |Λζ |Nζ |Θτ |Pε |Yf |Βa |Τγ |Qx |Jη |Pδ |Iq |Ωn |Fv |Kl |Ψη |Δj |Θσ |Hd |Θq |Υs |Ht |Fρ |Jh |Lζ |Hμ |Υι |Ρζ |Ρv |Dυ |Wo |Iχ |Iζ |Γy |Kr |Sσ |Iμ |Μο |Xw |Εμ |Cσ |Yξ |Aq |Jf |Hσ |Oq |Hq |Nυ |Lo |Jκ |Ρz |Οk |Θi |Θα |Αη |Gh |Lξ |Jm |Ων |Zu |Μc |Qη |Κγ |Αψ |Χζ |Hρ |Γρ |Uϑ |Rj |Χγ |Rw |Mω |Πζ |Θρ |Ωd |Υh |Nt |Tη |Qψ |Θω |Εχ |Iw |Σx |Ηn |Mτ |Xt |Yx |Φε |Hh |Wη |Mf |Ψχ |Νγ |Βξ |Aϑ |Qp |Τϑ |Φm |Uy |Gy |Cd |Bχ |Λl |Οτ |Εa |Df |Li |Aι |Yi |Νκ |Vc |Γx |Φρ |Φp |Nξ |Kf |Tw |Λξ |Φn |Λa |Oψ |Υχ |Fψ |Xω |Τq |Οσ |Σj |Θψ |Το |Νr |Ιπ |Τi |Dτ |Φf |Μn |Χm |Ηε |Wa |Αχ |Uδ |Λf |Ρu |Qk |Wα |Uρ |Τζ |Lg |Qy |Τν |Jϑ |Βδ |Mε |Μι |Πβ |Bη |Eκ |Κz |Ηh |Fδ |Σp |Εγ |Qφ |Μτ |Νχ |Ψν |Pw |Χz |Εϑ |We |Nπ |Tυ |Wg |Bh |Tρ |Ζν |Λm |Ag |Dσ |Πι
                |Oη |Nν |Χl |Χp |Sξ |Πt |Οϑ |Wο |Yη |Cp |Tm |Ξs |Εβ |Ιb |Ρρ |Fs |Um |Ep |Jλ |Rρ |Ρξ |Ua |Οq |Γξ |Zη |Nη |Qτ |Nc |Ez |Xσ |Yφ |Ρy |Yε |Ετ |Φκ |Λω |Ωα |Μκ |Φw |Mt |Tk |Sf |Ηξ |Οb |Νπ |Κε |Mι |Kz |Vi |Ξx |Ψs |Αο |Qδ |Kt |Aσ |Οm |Ψδ |Λγ |Ακ |Hα |Wϑ |Τμ |Γγ |Jδ |Ικ |Ηϑ |Μp |Zo |Κn |Qz |Δe |Pe |Jο |Qι |Tu |Jν |Ξμ |Πω |Αm |Θw |Nε |Dy |Zξ |Υα |Dβ |Hο |Χv |Gr |Ωl |Jb |Σl |Vζ |Ξ  |Nx |Qs |Βh |Qg |Νx |Co |Rσ |Νυ |Χg |Ρt |Wy |Ηκ |Οa |Yμ |Uj |Uξ |Op |Μr |Ζα |Ξw |Mυ |Ar |Ργ |Zζ |Sv |Vy |Βo |Κι |Vϑ |Ξι |Uζ |Fμ |Su |Ιξ |Fϑ |Hi |Hw |Mv |Χχ |Θg |Sν |Pp |Mπ |Pk |Bκ |Lυ |Ρλ |Ιr |Uλ |Νo |Κο |Nh |Lε |Sw |Ξλ |Zυ |Mr |Bv |Κπ |Aγ |Dv |Pd |Ξσ |Μg |Oπ |Χξ |Nj |Kψ |Ξπ |Mκ |Gn |Ωe |Gγ |Pν |Yz |Nl |Οο |Ic |Pz |Ξf |Νω |Υμ |Ηq |Nw |Θm |Μx |Jε |Φy |Οz |Ξz |Ti |Οψ |Φγ |Tψ |Oγ |Zϑ |Ιk |Σw |Rf |Υi |Ωp |Vr |Υτ |Xl |Οβ |Πb |Δν |Οu |Jα |Ττ |Κl |Pf |Iκ |Gk |Πe |Σu |Δβ |Ωh |Nλ |Ξt |My |Πs |Βr |Mγ |Δω |Le |Zρ |Θv |Σs |Ηd |
               Bn |Κu |Δξ |Pτ |Ηα |Δu |Πμ |Ρh |Bω |Τλ |Gt |Αρ |Sh |Aο |Θδ |Δπ |Wq |Tφ |Γo |Γf |Λβ |Xυ |Mη |Δw |Qυ |Vν |Βτ |Γα |Μm |Μπ |Κζ |Θd |Fε |Ρτ |Οn |Αs |Wu |Ξh |Μz |Αν |Aε |Yq |Τε |Cz |Ωu |Ec |Ds |Wρ |Θϑ |Κp |Τδ |Mδ |Ηy |Go |Sb |Rξ |Σϑ |Yο |Jg |Vh |Kσ |Nδ |Ηψ |Γh |Rk |Eο |Μk |Ζk |Ψο |Ψμ |Zσ |Pβ |Ρd |Us |Hυ |Βi |Mχ |Σr |Βι |Sχ |Zγ |Δα |Sτ |Γp |Ns |Sn |Νn |Pξ |Νa |Sω |Σi |Τφ |Xο |Eδ |Ba |To |Vj |Sl |Κκ |Δh |Τχ |Gυ |Ρϑ |Bs |Dh |Μσ |Vd |Iϑ |Kg |Νμ |Dμ |Σγ |Πg |Γg |Εt |Fa |Ψn |Ρx |Αj |Mβ |Kλ |Ξψ |Fω |Qζ |Θj |Kπ |Gf |Oe |Yυ |Κk |Wω |Bδ |Lο |Cβ |Nf |Ol |Σo |Fn |Τβ |Βω |Dn |Ha |Πλ |Ss |Σy |Kϑ |Lp |Dδ |Dψ |Ωo |Xγ |Χk |Ωσ |Δa |Sκ |Jμ |Κt |Rc |Ηc |Lχ |Oε |Μλ |Cs |Il |Tι |Ra |Zα |Ωr |Ob |Wβ |Ον |Γν |St |Xλ |Kv |No |Rε |Kd |Mν |Np |Ωc |Δζ |Nβ |Zπ |Ok |Vι |Tδ |Vδ |Γz |Χα |Μs |Βυ |Xc |Xo |Vp |Γχ |Υf |Θπ |Πj |Pi |Γj |By |Φk |Υq |Ny |Rο |Γd |Ωj |Αy |Εo |Κy |Uc |Rm |Ph |Αδ |Ιl |Ιx |Δτ |Zt |Nq |Ct |Φi |Uv |Eπ
                |Κm |Rλ |Vu |Χσ |Τn |Μe |Φη |Ξβ |Εz |Σω |Bb |Ψε |Sε |Ρm |Δο |Vξ |Φo |Ωε |Zb |Σc |Dζ |Ξp |Rη |Ιψ |Δσ |Χη |Kj |Eμ |Qν |Ri |Ip |La |Νξ |Αγ |As |Nr |Δi |Oν |Ζx |Xκ |Pr |Ελ |Λb |Ψk |Ωβ |Pl |Ιy |Cμ |Ζc |Αg |Σρ |Dw |Ρq |Ιη |Pζ |Σa |Uq |Ρμ |Lω |Fh |Ζδ |Αd |Cψ |Κσ |It |Qκ |Fν |Αb |Ηg |Ιν |Ls |Jr |Ow |Je |Zx |Ld |Jl |Ζd |Μo |Χτ |Kα |Μβ |Mo |Σλ |Xρ |Μq |Ψb |Νd |Ρβ |Wδ |Μf |Κρ |Ηb |Ξτ |Qα |Λv |Zψ |Φt |Sδ |Εh |Rκ |Rμ |Χι |Κυ |Ηj |Pχ |Pη |Jσ |Ρσ |Ιχ |Kζ |Εδ |Nω |Iψ |Γμ |Vσ |Ψρ |Χυ |Αw |Kn |Al |Gj |Zj |Αc |Aζ |Ζi |Bz |Vπ |Πw |Αu |Qf |Bf |Ξo |Ρε |Λy |En |Ey |Wi |Σχ |Τc |Dχ |Fg |Ρo |Zm |Ψω |Fq |Μa |Ηt |Wc |Kε |Κτ |Χψ |Κβ |Λφ |Κq |Υm |Πx |Pj |Mi |Δy |Κχ |Lϑ |Wτ |Lη |Nd |Ωk |Iπ |Tα |Bο |Uε |Lc |Rp |Θx |Ρη |Lu |Μζ |Εd |Gρ |Χμ |Vγ |Ιζ |Πυ |El |Uk |Hc |Ξξ |Λx |Ιο |Μy |Ζm |Jw |Iε |Σφ |Αk |Σf |Ac |Ab |Αq |Δf |Θκ |Υa |Ζτ |Jc |Xμ |Sι |Κv |Ζj |Ει |Oω |Ηδ |Φv |Dα |Fτ |Ko |Et |Ψζ |Jx |Mk |Th |Βλ |Λχ |Οo |Υπ |
               Cζ |Θy |Λk |Γδ |Iυ |Σξ |Υϑ |Cι |Cχ |Εσ |Βψ |Iα |Τη |Eυ |Lφ |Lδ |Υw |Ξο |Uσ |Δb |Nϑ |Ζγ |Δz |Cο |Mb |Ξy |Γυ |Εk |Αζ |Vα |Τυ |Ιω |Wυ |Cτ |Ιγ |Yω |Ωy |Ηp |Ψψ |Ah |Dq |Βv |Ιw |Ox |Ξv |Οζ |Tχ |Πψ |Qb |Rδ |Aψ |Zμ |Ζg |Ψφ |Nφ |Δρ |Χe |Vχ |Ηυ |Ml |Σσ |Ζμ |Sz |Πκ |Sγ |Kq |Dη |Υk |Dt |Ξe |Sc |Νs |Μv |Ev |Ji |Rχ |Xπ |Αo |Lμ |Gδ |Fσ |Λϑ |Λe |Σb |Id |Hb |Γι |Βz |Sβ |Tg |Ζο |Δk |Dl |Λσ |Κϑ |Aw |Uγ |Lx |Uψ |Hs |Ωχ |Δφ |Wσ |Π  |Εe |Ro |Λο |Ud |Fχ |Δψ |Νh |Θμ |Zd |Kb |Οδ |Ex |Να |Φσ |Φω |Pm |Λυ |Xq |Si |Σδ |Gα |Bu |Βw |Eχ |Ρι |Gβ |Vο |Yh |Σε |Χq |Hι |Re |Zχ |Ζp |Eρ |Ωγ |Bξ |Hδ |Oξ |Γc |Μγ |Wφ |Πη |Wj |Ιq |Γs |Πο |Κj |Un |Rι |Dφ |Τl |Ωz |Pμ |Wr |Gω |Gi |Εu |Σq |Ρl |Iν |Zy |Rb |Νk |Ky |Uκ |Ησ |Hy |Ir |Tp |Εc |Bw |Εο |Cm |Εw |Ψf |Yχ |Ιρ |Hβ |Ιz |Vλ |Εj |Oδ |Qρ |Θν |Aρ |Ov |Zω |Gψ |Ij |Ξη |Ps |Φh |Οg |Dp |Ta |Ty |Οe |Uο |Rγ |Οr |Θp |Hλ |Νι |Vk |Νz |Tl |Ψi |Λs |Hη |Ζκ |Rz |Hx |Fξ |Ξn |Φe |Sπ |Ηw |Dκ |Ζω
                |Sr |Vψ |Ντ |Vω |Lv |Νg |Fκ |Jψ |Ζs |Oβ |Υζ |Δg |Fυ |Yκ |Χd |Zf |Φμ |Lt |Ξd |Oφ |Τp |Κh |Ψx |Vυ |Qπ |Θφ |Nψ |Ρχ |Rx |Υz |Ξκ |Ξχ |Qn |Pu |Υψ |Az |Xj |Σd |Φξ |Ws |Xα |Βm |Βf |Lh |Hv |Aω |Hν |Kχ |Ρψ |Aδ |Χx |Sη |Φx |Cκ |Jz |Dr |Xu |Ηζ |Ξζ |Gτ |Ca |Af |Aν |Bι |Mc |Ψg |Ωv |Ωs |Qω |Mψ |Lλ |Μα |Kμ |Vl |Yσ |Οι |Ve |Dν |Eg |Ιυ |Xι |Zν |Xϑ |Νζ |Ni |Sφ |Se |Ζa |Xδ |Νv |Wι |Jv |Jt |Ιh |Υv |Cη |Τd |Ψι |Τu |Ge |Πc |Bυ |Mϑ |Χλ |Δλ |Σψ |Μϑ |Απ |Vg |Κα |Sψ |Ζz |Λδ |Aκ |Λκ |Ga |Κb |Db |Jo |Τa |Fw |Τs |Βϑ |Eτ |Wk |Ξu |Ψl |Αι |Νψ |Δι |Qμ |Υn |Bτ |Ηs |Yw |Ye |Iο |Dο |Γe |Rβ |Qv |Xs |Ηη |Yo |Χj |Dω |Οπ |Uβ |Mλ |Qh |Fο |Βd |Ζr |Οv |Zφ |Αi |Dλ |Pb |Οx |Rv |Uz |Εν |Ψτ |Na |Aη |Βu |Ιd |Ηm |Υd |Wn |Qσ |Οp |Αr |Ηλ |Σι |Br |Cu |Ωζ |Θγ |Qo |Bρ |Bψ |Zβ |Πφ |Ρκ |Qϑ |Bj |Vε |Zz |Ζϑ |Za |Θt |Τψ |Ρο |Jq |Πf |Jφ |Τα |Xχ |Χn |Vo |Αt |Bg |Gs |Bi |Rϑ |Nι |Ρa |Υr |Υν |Λo |Γφ |Δo |Yρ |Χc |Ξα |Gq |Γm |Ωμ |Ζυ |Wζ |At |Mw |
               Cf |Επ |Fo |Οh |Tσ |Ηv |Sα |Ζq |Dk |Jπ |Ιm |Mj |Oi |Ψa |Qγ |Rn |Dξ |De |Γk |Ψm |Lα |Cl |Θο |Γq |Λc |Tx |Nm |Ki |Υο |Χr |Φs |Κi |Φλ |Vq |Αω |Ch |Tμ |Xb |Ζπ |Ym |Ζn |Eω |Ξj |Υκ |Τg |Uo |Ai |Sy |Τe |Ητ |Tτ |Λg |Bp |Δq |Χo |Pπ |Dγ |Δγ |Yπ |Ys |Ωδ |Ψσ |Sζ |Πξ |Rφ |Hj |Uf |Td |Ξk |Xψ |Οj |Cx |Φπ |Gλ |Φδ |Ej |Yψ |Ae |Φφ |Jγ |Qχ |Ξγ |Δp |Σg |Is |Eσ |Λπ |Cδ |Ιe |Cυ |Oh |Hm |Tb |Qi |Οl |Bε |Eψ |Hn |Ja |Σν |Γr |Ηu |Ζξ |Ζb |Nu |Θξ |Κd |Qο |Lq |Λw |Ηf |Kξ |Ευ |Rr |Τm |Εξ |Ψp |Χh |Ξi |Fπ |Μφ |Fu |Cξ |Aα |Pγ |Sk |Cω |Ηr |Αp |Ββ |Bx |Fp |Tζ |Pω |Λp |Lm |Jp |Bl |Φc |Vf |Τz |Εy |Λμ |Rd |Νf |Πρ |Ηx |Μψ |Γη |Bα |Συ |Iσ |Γt |Κξ |Io |Ζφ |Γl |Θf |Γλ |Υγ |Ψh |Xg |Tn |Iu |Bφ |Πχ |Λq |Χπ |Bϑ |Εm |Κφ |Λt |Ιu |Ρs |Ιβ |Ωg |Yν |Lσ |Ζι |Eι |Aτ |Φa |Pα |Θz |Ψκ |Θs |Θη |Ηl |Φζ |Bt |Ρυ |On |Ξε |Tf |Gp |Mα |Μi |Kβ |Σο |Ωξ |Νl |Iz |Fk |Dj |Bπ |Nz |Xr |Mp |Χω |Sϑ |Hu |Αμ |Js |Βn |If |Τw |Ηz |Σz |Po |Yj |Ημ |Yβ |Σm |Do
                |Ηχ |Κg |Θo |Ζh |Ψj |Ψu |Ωφ |Δμ |Γa |Bν |Ιε |Oz |Νq |Υp |Qλ |Υc |Υy |Kc |Kh |Ew |Wγ |Νβ |Ωλ |Οξ |Zι |Yr |Sυ |Γπ |Bm |Μj |Pa |Os |Χδ |Κδ |Εx |Iγ |Eη |Fλ |Tγ |Yλ |Hξ |Φq |Τξ |Ql |Δn |Zn |Ot |Sa |Φψ |Nμ |Ξr |Ξc |Φj |Gl |Oλ |Rπ |Am |Mο |Gx |Fd |Cg |Χu |Lι |Wv |Ζt |Jυ |Pσ |Σκ |Wκ |Pv |Ιg |Ωι |Δx |Φl |Eb |Δυ |Cr |Nχ |Ογ |Νφ |Gu |Ασ |Λi |Rτ |Eh |Xη |Md |Wm |Tt |Πα |Υe |Βk |Ju |Dρ |Χβ |Οs |Γi |Kι |Κe |Mm |Χf |Oκ |Vb |Γβ |Οy |Vv |Νϑ |Hl |Λα |Wξ |Om |Βφ |Ρp |Φβ |Βb |Αυ |Υδ |Χφ |Pλ |Νρ |Υλ |Ul |Kγ |Qc |Νm |Πz |Hφ |Es |Ψπ |Xm |Xξ |Tν |Eλ |Ao |Ak |Ka |Ζη |Xk |Γψ |Βπ |Fβ |Βρ |Xx |Βζ |Iτ |Pϑ |Εb |Ψγ |Τk |Gm |Yn |Xν |Νu |Hϑ |Εr |Τπ |Uw |Mh |Og |Μυ |Tj |Λν |Qm |Xn |Ην |Νi |Kη |Zv |Ιι |Ση |Yk |Dx |Aχ |Ou |Fy |Cα |Θl |Γκ |Ax |Vκ |Cn |Cλ |Ξϑ |Wε |Υl |Ψt |Ωa |Θe |Ξω |Ηo |Ll |Bζ |Kw |Αβ |Δc |Oυ |Βj |Jβ |Νε |Eϑ |Ξg |Tz |Cc |Ry |Sρ |Ψz |Yα |Pq |Υg |Jn |Vμ |Σk |Ck |Ωt |Zg |Pι |Hω |Λλ |Aμ |Wλ |Ιλ |Βc |Ξa |
               Jk |Πϑ |Ιt |Εψ |Hε |Ωϑ |Εη |Ie |Κω |Yc |Iβ |Ου |Hg |Θr |Nn |Uμ |Ζv |Ζχ |Jρ |Pο |Ng |Be |Δv |Fζ |Ρe |Qe |Cq |Κf |Θλ |Tϑ |Ξq |Me |Βq |Oα |Θc |Qr |Δt |Dm |Yu |Ru |Σh |Λr |Yy |Εε |Μχ |Mφ |Δδ |Kφ |Cγ |Ζσ |Iω |Au |Wb |Κc |Πq |Ωω |Pυ |Γn |Nγ |Cv |Βχ |Φg |Gο |Ug |Kο |Βκ |Wμ |Hτ |Hχ |Ue |Οw |Sμ |Sm |Υω |Yb |Χa |Ιi |Κν |Πu |Κψ |Uτ |Lβ |Fj |Pn |Εf |Τσ |Qε |Ψo |Λρ |Oϑ |Πν |Ts |Ηο |Μρ |Ff |Ψβ |Ne |Nκ |Bλ |Bσ |Mx |Πp |Υσ |Ιn |Αz |Fz |Ηa |Uν |Mζ |Δϑ |Yι |Ζe |Ψα |Tο |Βg |Lπ |Ζf |Αλ |Em |Θh |Gπ |Γω |Kω |Tξ |Σn |So |Im |Φυ |Ξb |Ii |Λι |Xz |Kδ |Μω |Uυ |Wf |Χb |Sλ |Lγ |Οη |Ιs |Xβ |Pκ |Bc |Ιp |Od |Αn |Va |Tω |Ζw |Ιτ |Θε |Ρi |Gι |Τh |Υx |Nτ |Δη |Εφ |Kx |Xa |Gν |Ft |Yt |Qd |Gσ |Ξυ |Εs |Nσ |Νc |Λj |Υu |Ρc |Ψξ |Δm |Qβ |Μu |Υb |Nk |Ωτ |Κr |Δd |Iλ |Πa |Ωρ |Χν |Μh |Jξ |Μμ |Fc |Iφ |Zr |Ux |Φb |Πo |Gd |Eζ |Αα |Νν |Λz |Vη |Pψ |Ωf |Lρ |Cb |Ν |Α |Χ |Ω |Zτ |Τκ |Αε |Bβ |Uι |Fi |Ui |Βx |Ωq |Βp |Λh |Uu |Ωw |Xp |Ζβ |Λτ
 | N2012 deriving(Enum); instance Show Counter where show = show . fromEnum
share|improve this answer
I'm afraid this compiles just fine modified, although an exception is thrown at runtime. –  Jeff Burdges Jan 3 '12 at 19:13
@JeffBurdges: sure, I take this to be included in "and will not cause it to crash". –  leftaroundabout Jan 3 '12 at 21:30
For the a=map(head.show.length)[[a,a],[],[a],[a,a]] solution, insert a between []. I really like this post, though! Very clever solutions. –  Dillon Cower Jan 4 '12 at 0:15
I've verified that all 5825 variations of your 29-character program (replacing or inserting ASCII characters 32-126) work as expected. Here's the test script I used. It can easily be tweaked to test other programs, including other languages. Warning: It took almost 1 hour to run on my laptop :) –  hammar Jan 4 '12 at 0:30
+1 Wow, 19 chars and bulletproof is impressive. –  M. Joanis Jan 4 '12 at 6:54


I believe this is runtime error proof, any single change should either result in a compile error or a single alert saying 2012.

Edit: Code would make a runtime error on something like if("alert(2012 "==r), I moved the try section to deal with it.

Edit: Nice one Vilx-, but fixable :-) Now there is a bracket mismatch for inserting that semicolon.

Edit: But then a comma could do the same thing as the semicolon, that is a host of options, I think I have fixed it, but there is an awful lot of code now.

Edit: Simplified a bit.

Edit: One more in an infinite series of bugfixes.

Edit: This kinda feels more long and complicated than bulletproof, but it should at least take care of ~eval and !eval.

var q="alert(2012 "
var p=1
    if("alert(2012 "==q){
share|improve this answer
Wow that's impressive. I spent a few minutes trying to break it but I couldn't, congratulations, but why the ||alert(2012)? –  user11 Jan 3 '12 at 4:07
Because for instance q-")" returns NaN, which eval convert to "NaN" before evaling it, which simply turns it back to NaN. Strange thing to do, but technically legit, so that doesn't invoke the catch. –  eBusiness Jan 3 '12 at 8:23
Same thing as the C solution - insert a ; between eval and (. –  Vilx- Jan 3 '12 at 11:00
For the comment readers, the semicolon vulnerability is fixed, I believe the code to be clean now. –  eBusiness Jan 3 '12 at 23:38
Not sure if this counts or not, but putting a ~ in front of the eval causes it to echo 2012 twice instead of once. Not sure if that disobeys the rules or not :P –  mellamokb Jan 11 '12 at 0:34


print(xx if xx=='2012' else

Alternative solution(with great help from D C):


Please try and break both.

I think the current code should also be comment-proof.

I will probably go to python hell for writing code like that...

share|improve this answer
Not if I add a - sign: print -x if ... –  JBernardo Jan 3 '12 at 0:59
Fixed that. How about now? –  stranac Jan 3 '12 at 1:13
Add a , somewhere in the last 2012, e.g. 20,12 will print 12 after 2012. Putting the last 2012 between ' seems to fix it. –  M. Joanis Jan 3 '12 at 1:55
At least in python 3, you can protect against a semicolon after print by passing a keyword argument (sep='' should work) to print. –  James Apr 25 '12 at 9:38
fails for prin=(... –  gnibbler Feb 4 '13 at 23:34

Perl, 49 chars

use strict;$_=2012;;2012==$_&&0-print||die}

Based on J B's answer, but this one actually satisfies the spec. An exhaustive check indicates that every one-character deletion, insertion or replacement either leaves the output unchanged or causes the program to crash when run (as indicated by a non-zero return value and output to stderr), at least as long as insertions and replacements are restricted to printable ASCII characters.

(Without the restriction, the task is impossible in Perl: a little-known feature of the Perl parser is that it stops when it encounters a Ctrl-D or a Ctrl-Z character, so inserting either of those in front of any file turns it into a valid Perl program that does nothing.)

Edit: Shaved off one more char by replacing 1==print with 0-print.

share|improve this answer
Breaks with Perl 5.28 where print starts returning 'true' instead of 1 :-P –  J B Jan 3 '12 at 21:39
@JB: Well, you can downvote it when that happens. :) (For the benefit of other readers, this is a joke. As far as I know, there are no plans to change the return value of print in any version of Perl 5, even if it isn't explicitly documented.) –  Ilmari Karonen Jan 3 '12 at 21:47


I am trying to convince myself that this is possible, and I am fairly certain I may have stretched it a bit too far. I have made a few assumptions about my environment:

  1. An infinite loop is considered a 'crash'. A similar condition could possibly be achieved by decrementing past zero or to the left of memory location zero in certain interpreters. Many interpreters are difficult to crash at runtime. I avoid the halting problem by using only the simplest, most obvious infinite loop.
  2. Unmatched square braces are considered a compile error.
  3. This will only work in an environment where the program's output is piped back to it's own input. I use that to verify that it did indeed output '2012'. This is the only way I could get around simply deleting one of the output characters.

Unfortunately, if you get any stricter I fear this will be impossible. Here is my solution:

,[]EOF = 0

Basically, you can change the output code, or the verification code, but not both. One of them is guaranteed to work. If one of them doesn't it will 'crash'.

share|improve this answer
Ugh, brainfuck! You just HAD to, didn't you? XD –  Vilx- Mar 20 '12 at 16:15
would you have preferred he used whitespace instead? –  NRGdallas Sep 28 '12 at 22:16

Spreadsheet formula

Tested in LibreOffice Calc 3.4. Please don't count the leading equals sign as part of the formula itself.

share|improve this answer
I just inserted - at the beginning. It gives me -2012 then. –  Howard Jan 3 '12 at 11:49
Use any formula, set custom format string to 2\012. Problem solved! :P –  mellamokb Jan 5 '12 at 14:25


import sys;xx='2012';(
1/(sys.stdout.write(xx=='2012' and xx or 2012)==None))

I had to change Ray's test script slightly to test this as the stdout redirect was breaking it. Passing empty dicts to exec avoids polluting the namespace

exec(prog, {}, {})
share|improve this answer
Great! You make it! –  Ray Feb 6 '13 at 6:49


A little verbose (now with a fix for that pesky semicolon between print and (!):

(lambda x:print(
share|improve this answer
@Jeff Burdges: Yeah, with this one I'm banking on runtime errors being disallowed as well. :) –  Dillon Cower Jan 3 '12 at 7:05
I'm afraid it's still syntactically correct if the intersection yields the empty set and pop throws a runtime error. Add more 2012s on both sides. –  Jeff Burdges Jan 3 '12 at 7:10
@DC: I would say that an exception is not the same as a runtime error, although it seems exceptions are called errors in Python. pop()ing the empty set isn't an error in and of itself, but it does raise an 'Error'. –  Williham Totland Jan 3 '12 at 9:37
The task specifies that the change will not cause the program to crash, which makes this solution valid - in my understanding, a runtime error that stops program execution is practically the definition of a crash. Therefore, +1 for the nice trick. –  cemper93 Jan 3 '12 at 22:14
An exception becomes an error when it's not caught. –  Ilmari Karonen Jan 7 '12 at 0:27

I've make a python script to judge all the python solutions. The script breaks the first and the third python solutions, with many different methods. And the second solution use lambda to guard itself, is unbreakable. The second python solution is in python 3. I modified it into python 2 format and then judge program broke it.

Here is the judge script.

from StringIO import StringIO
import sys

def run(prog, atexp=True):
    stdout = sys.stdout
    fakeOut = StringIO()
        sys.stdout = fakeOut
        # exec prog # running exec directly will break some solutions by mistake
        exec(prog, {}, {}) 
        return fakeOut.getvalue().rstrip() == '2012'
        return atexp
        sys.stdout = stdout
    return True

def judge(prog):
    RED = '\x1b[31m'
    WHITE = '\x1b[37m'
    ans = True
    chars = """abcdefghijklmnopqABCDEFGHIJKLMNOP`~1234567890!@#$%^&*()_+-=[]{};:'"<>,./?"""
    # attack by replace
    if not run(prog):
        print "Are you joking...This program don't print 2012 itself."
        return False
    p = list(prog)
    for i in xrange(len(prog)):
        for c in chars:
            p[i] = c
            r = run(''.join(p))
            if not r:
                print 'Attack by replace success'
                print 'origin:\n'+prog
                print 'modified:\n'+''.join(p[:i])+RED+c+WHITE+''.join(p[i+1:])
                ans = False
        p[i] = prog[i]
    # attack by delete
    for i in xrange(len(prog)):
        p = prog[:i]+prog[i+1:]
        r = run(''.join(p))
        if not r:
            print 'Attack by delete success'
            print 'origin:\n'+prog
            print 'modified:\n'+''.join(p[:i])+RED+'{|}'+WHITE+''.join(p[i:])
            ans = False
    # attack by insert
    for i in xrange(len(prog)+1):
        p = list(prog)
        p.insert(i, ' ')
        for c in chars:
            p[i] = c
            r = run(''.join(p))
            if not r:
                print 'Attack by insert success'
                print 'origin:\n'+prog
                print 'modified:\n'+''.join(p[:i])+RED+c+WHITE+''.join(p[i+1:])
                ans = False
    if ans: 
        print 'Amazing! judgement passed'
    return ans

print(xx if xx=='2012' else
p2="""import sys
(lambda x:sys.stdout.write(

p3="""print sorted(['2012',
p4="""print 2012
share|improve this answer
cool! my answer sucks and blows at the same time –  gnibbler Feb 4 '13 at 22:34
p2 always throws an exception for Python2. The output is never 2012. Your judge program won't run under Python3 as it uses print statements. –  gnibbler Feb 4 '13 at 22:51
@gnibbler I don't noticed that p2 is in python 3. –  Ray Feb 5 '13 at 15:10
I've worked out a new answer for Python2 that passes your script –  gnibbler Feb 5 '13 at 23:08

Javascript - 68, 77, 84, 80 chars

Here's a solution that should work this year :)

a="eval(alert(new Date().getFullYear()))" 

Here's the test fiddle.

Update 1: Fixed issue where eval(+a) broke it (thanks eBusiness).

Update 2: Fixed for the '|' case (thanks again eBusiness).

Update 3: Fixed for the '>' case (thanks again eBusiness). And broke for the '1' case :(

share|improve this answer
You didn't guard your eval. eval(+a) and a lot of other modifications run perfectly fine but doesn't do a whole lot. –  eBusiness Jan 3 '12 at 23:33
@eBusiness: Thanks for pointing out the eval(+a) case, that should now be fixed. Also, I've been unable to find one of the modification cases where it runs fine but doesn't output 2012, so will you please give me an example? –  Briguy37 Jan 4 '12 at 15:06
eval(0) and eval(-a) for instance does the same thing. –  eBusiness Jan 4 '12 at 15:40
Post edit it can at least be broken by replacing || with |. –  eBusiness Jan 4 '12 at 15:45
@eBusiness: Thanks, that should be fixed now. The flexibility of JavaScript definitely does not help here, as I'm sure you know. Nice going with your solution, and please let me know if you see anything else :) –  Briguy37 Jan 4 '12 at 16:09

Mathematica 23 chars


Note> "/." means "replace"

share|improve this answer
This might be kind of a weak answer/defeat, but change /. to // (postfix form). –  Dillon Cower Jan 8 '12 at 19:31
@DillonCower Good catch! –  belisarius Mar 8 '13 at 12:53

T-SQL 2012, 55

DECLARE @n CHAR(4)='2012'PRINT IIF(@n='2012',@n,'2012')
share|improve this answer
What SQL dialect is this? Looks like Transact-SQL (aka SQL Server), but it has invalid syntax for that. –  Vilx- May 3 '12 at 10:22
@Vilx-: I tested it in SQL Server 2008 myself when I was trying to break it, and it worked just fine. –  mellamokb May 4 '12 at 14:23
@mellamokb - That's odd. It's exactly what I did, and it complained that you cannot assign a default value to variable (you need a separate SET statement), and there is no IIF (only CASE). –  Vilx- May 4 '12 at 18:15
@Vilx-: Ah, you are correct. I realize now I was actually testing on SQL Azure. With SQL Server 2008 I get those same errors as you. However, it seems to work fine in SQL Server 2012/Azure. Here's a demo with SQL 2012: sqlfiddle.com/#!6/d41d8/27 –  mellamokb May 7 '12 at 14:10
OK, congratulations, I can't find any obvious ways of breaking this! :) That's not to say there aren't any. ;) –  Vilx- May 7 '12 at 15:12

Ruby 1.9

puts (

I build this short but simple program which you are invited to break according to above rules. I couldn't even find a position where the output is changed (without breaking the code) if a # is inserted in order to comment out the rest of the line.

share|improve this answer
puts (r = 2012) == 2012 ? -r : 2012.send(:abs) prints "-2012" –  M. Joanis Jan 2 '12 at 20:31
@M.Joanis But you need two additional characters: a space character and a minus. A minus alone will not work. –  Howard Jan 2 '12 at 20:40
Ah, you're right! Compilation error. I know nothing about Ruby, I should be more careful. Sorry! –  M. Joanis Jan 2 '12 at 20:47
According to irb, adding a minus before the rx results in a valid program that outputs -2012 –  Konrad Rudolph Jan 4 '12 at 14:14
Changing puts to putc causes this to output a ? in Ruby 1.9. –  histocrat Dec 12 '12 at 18:39

Scala, 95

(or 54 if skip non-meaningful parts)

object Main{def main(ar:Array[String]){print(((s:String)=>if(s=="2012")s else"2012")("2012"))}}
share|improve this answer
I'm afraid I don't know enough about Scala to find any flaws. :( Can other people, please, take a look? –  Vilx- Sep 26 '12 at 9:07
It's not hard at this level. Most of Scala hardness is due to complexity of its type system (which I still cannot understand fully :D ) –  Sarge Borsch Sep 26 '12 at 13:44

Ruby 1.9 - 43 chars

b if qq!=[:p,2012]

Not tested, so break away.

share|improve this answer

Haskell, 65

import Data.List

Perl, 84

use strict;use English;$ARG=
2032;s/.*/2012/unless$ARG eq 2012;$SUBSEP=2012;print;

Failed approach :

use strict;use English;"2012 2012"=~
share|improve this answer
You Perl solution can be broken by replacing the first $& with something like $0. –  Howard Jan 3 '12 at 8:29
And the Haskell one breaks if you replace the comma with a plus sign. Valiant attempt though. –  Jeff Burka Jan 3 '12 at 9:33
I think nub$filter(\x->x==2012||x==2012)(2012:[2012]) might be safe for the Haskell solution. –  Jeff Burka Jan 3 '12 at 9:35
I forgot the use English in perl, that'll fix it. I think several fixes work for Haskell, including switching to strings. –  Jeff Burdges Jan 3 '12 at 13:12
Replacing the first $MATCH with *MATCH gives the output *main::&. –  Ilmari Karonen Jan 3 '12 at 13:45

PHP, 43 48

share|improve this answer
Inserting a - between the ? and the $a results in -2012 being printed. –  Gareth Jan 9 '12 at 15:05
Cute attempt with the date(), but the program has to work beyond 2012 as well. ;) –  Vilx- Jan 10 '12 at 8:51
@Gareth - hmm :) –  The Coder Jan 11 '12 at 20:24
@Vilx-"The task is to write a program in your favorite language that outputs 2012" where does it say it has to work beyond 2012? :) –  The Coder Jan 11 '12 at 20:24
@TheCoder Ok, now I'm going to insert my - between the ? and the abs. ;-) –  Gareth Jan 11 '12 at 20:46

VBA: I gave up...

Sub z()  
MsgBox IIf(a=2012,a,2012)  
End Sub

A variation on the same theme of other answers already supplied.

The problem with the above code is that one can change the second a in the IIf() statement to anything else, and the result will be NULL.

Option Explicit
Sub z()
Dim a
Call MsgBox(IIf(a=2012,a,2012))
Call MsgBox(IIf(a=2012,a,2012)) 
'Does this count as acceptable if the function returns 2012x2?
End Sub

Adding Option Explicit enforces the Dim'ing of a, thereby preventing the variable from being changed, as was the issue in the original code.

I don't believe this is possible in VBA. (Someone please prove me wrong.) Any conditional checks can be bypassed by adding - just after a MsgBox, Debug.Print or return assignment. i.e.

Call MsgBox(-(WhateverCheckYouHaveToEnsure2012IsPositive))
MsgBox -(WhateverCheckYouHaveToEnsure2012IsPositive)
Debug.Print -(WhateverCheckYouHaveToEnsure2012IsPositive)
share|improve this answer
No, it's not, but people somehow mistook it for such. XD –  Vilx- Mar 20 '12 at 14:51
Namely, me! ;-) –  Gaffi Mar 20 '12 at 15:54
You, and almost everybody else who looked at this question. Beats me why, but it's more fun that way anyway, so who am I to complain? :D Anyway - MsgBox IIf(a=2012,-a,2012) - this outputs '-2012'. Try looking at other answers, this one's been covered before, as well as a few others that might be relevant to VBA. Oh, and also, since comments in VBA are also a single character, that opens up a whole new world of possibilities! ;) –  Vilx- Mar 20 '12 at 16:12
@Vilx- Good point on the - - I was stuck on replacing a char, not adding. Thinking of comments, that would be a nast trick to comment out everything after MsgBox. I will fix that with Call MsgBox(...), however. –  Gaffi Mar 20 '12 at 16:17
Why not just comment the whole line, Call and all? –  Vilx- Mar 20 '12 at 16:20


a = b = 2012;
c = d = alert(
    (a === 2012) ? a : (
        (b === 2012) ? b : 2012
if (c || d) {
share|improve this answer
I add one character: (a === 2012) ? -a : ( –  Vilx- Apr 25 '12 at 10:36

Ruby (57 36)

EDIT And another one in 36 chars.


I guess using strings is pretty failsafe because that minus thing doesn't work any more.

EDIT next try (36 chars) [never mind, adding a - after p results in -2012]

p [2012,2012].find(2012).first||2012

This one will only work this year, but also for similar contests in the future :) (15.chars)

p Time.now.year

Note that this substitution is also working:

p Time.new.year

57 chars. If you count the newlines, too it is 76 chars, though.


share|improve this answer
First two solutions - add a # at the start of the line. Last solution - enter a newline before p. (Note - I don't know Ruby myself, so perhaps I'm wrong). –  Vilx- Apr 25 '12 at 13:02
damn :) you're right –  padde Apr 25 '12 at 13:30
Prints "2012" for me. The quotes aren't conform - are they? –  user unknown May 10 '12 at 3:37
Yeah you are right. You could use $><< or puts instead. Whatever, i'm not gonna try this any more, i gave up :) –  padde May 10 '12 at 7:02

Q, 23





share|improve this answer
And adding a negative (-)? -- {$[-2012~m:2012;m;2012]} -- {$[2012~m:-2012;m;2012]} -- {$[2012~m:2012;m;-2012]} –  Gaffi May 22 '12 at 21:07
it still outputs 2012 q){$[-2012~m:2012;m;2012]}` 2012-- q){$[2012~m:-2012;m;2012]}` 2012-- q){$[2012~m:2012;m;-2012]}` 2012 –  tmartin May 23 '12 at 9:18

Hmm.. let me try:

class a {
  int i=2012, j=2012;
  public static void main(String[] args){if (i==j)

128 chars without the whitespace.

class a{int i=2012, j=2012;public static void main(String[] args){if(i==j){System.out.println(i);}else{System.out.println(i);}}}
share|improve this answer


I hope it's unbreakable :)

$a="2012";ob_start();function c(){ob_clean();return"2012";}function ee($s){return crc32($s)+printf($s);}
share|improve this answer
I add one character to the end of this line: echo(printf("%s",$a)==4)?die(3 and I get 20123. –  Vilx- Sep 27 '12 at 10:59
Hmm… PHP 5.4.7 works correctly with die(3. –  Stanislav Yaglo Sep 27 '12 at 11:00
You're right. My bad. Continuing the search... –  Vilx- Sep 27 '12 at 11:06
PHP 5.3.3 — correct as well. die() outputs only strings, it doesn't output numbers. –  Stanislav Yaglo Sep 27 '12 at 11:06
Wait, DUH, found it! Just change ."2012" to ."FAIL". :) –  Vilx- Sep 27 '12 at 11:08

Groovy: 26

x=2012;print x^2012?2012:x
share|improve this answer
I don't know Groovy much, but would this work? x=2012;print x^2012?2012:-x –  Vilx- Sep 27 '12 at 14:48
what's the - for? –  Alison Sep 27 '12 at 15:39
@Alison The - is to try and modify your code with one character so that it no longer works. –  Gareth Oct 30 '12 at 9:11
x=2012;print x^=2012?2012:x (changing ^ to ^=) changes the output to 0. –  histocrat Dec 12 '12 at 19:23

Excel, 14 characters (cheating slightly):

{=2012} (in a 2x1 array with one cell hidden)

Any valid change to the array will affect the contents of both cells, and attempting to change just one cell triggers an error message.

Of course, this breaks down if you take the view that it's really only one formula, as opposed to 2 formulas that are constrained to be identical.

share|improve this answer


Set X(2012)=2012 Write X(X(X))
share|improve this answer


print(- -(function(ab,ba)assert(ab==ba)return- -ab end)(2012,2012))
share|improve this answer
What if you delete one of those - signs? –  Vilx- Jan 15 '13 at 15:30
Oh, and if you change one of those 2012 to something else, the assert will raise an error. Hmm... well, I guess you deserve creativity points for abusing the rules. But seriously, that's not how it was meant. –  Vilx- Jan 15 '13 at 15:35

Ruby, 40

share|improve this answer
Deleting the p causes this to run successfully but output nothing, or inserting a p after the first two characters causes it to output [2012, 2012, 2012] first. –  histocrat Feb 4 '13 at 21:02

Python - does not work

print sorted(['2012',

I think it's basically impossible to prevent all the possible attacks against the print statement. eg.

prin=...        # changed t to =
print;...       # inserted ;
print(...,)     # inserted ,

So I tried a new approach using sys.stdout

share|improve this answer
I think you might have forgotten some parentheses.. so, assuming they're present, add ; after sorted. I like where this one is going, though! –  Dillon Cower Jan 12 '12 at 4:24
@DC also can put a : after the 1 :( maybe i need to use __getitem__ –  gnibbler Jan 12 '12 at 4:47
What's wrong with just print sorted([2012,2012,2012])[1]? –  jsvk Feb 4 '13 at 21:23
@jsvk, print sorted([2012,2012,2012])[1:] –  gnibbler Feb 4 '13 at 22:31
Ah sorry, I should've read the question more closely. I thought it was just replacement, I didn't know it could be insertion or deletion too –  jsvk Feb 5 '13 at 3:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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