Quine

Inkqubo yeQuine okanye iQuin yinkqubo evelisa ikhowudi yemvelaphi yayo xa isenziwa. IQuine ayinako "kuphuma ngaphandle kwayo" ngokuthi, umzekelo, iprinte imixholo yefayile equletheyo okanye isebenzise ubuchule bokuzibonela ukuprinta umelo lwayo. Endaweni yoko, kufuneka ibale ikhowudi yomthombo wayo.


Indlela yakudala yokwenza inkqubo enjalo ithatha amanyathelo amabini:

  1. Qalisa umtya oguquguqukayo onesibambi-ndawo sofakelo.
  2. Shicilela umtya kwaye udibanise kuwo ngokwawo .

Iqhinga kukufumana umtya ngokufanelekileyo. Indlela yokwenza oku iyahluka ukusuka kulwimi ukuya kulwimi kwaye kuxhomekeke kwindlela ekubhengezwa ngayo ukuguquguquka, imfuno yeesemikholoni kunye nemigca emitsha, amanqaku okucaphula afunekayo, njl. Ukusetyenziswa kwamanqaku okucaphula kunomdla; Ubani kufuneka akhangele indlela yokubonisa ukuba uphawu lokucaphula lufanele lushicilelwe ngaphandle kokusebenzisa uphawu lokucaphula.

Bash

Njengezinto ezininzi eBash, le nkqubo isebenzisa i-quirk enomdla. Nangona iingcaphuno ezingatshatanga zizicaphulo ezinamandla kwaye zingandisi nantoni na, zitolikwe printf octal ukubaleka abalinganiswa njengoonobumba abanenqaku lekhowudi elikhankanyiweyo:

s='s=%s;printf "$s" "$s"';printf "$s" "$s"

Inhlwathi

KwiPython, isicacisi sefomathi siyabuya %r ngokuzenzekelayo ucaphulo olulodwa. Kulula kakhulu ukuba ikhowudi iphela ngombhalo omtsha womgca:

s='s=%r;print(s%%s)';print(s%s)

Ukuba ufuna ikhowudi ngaphandle kokuqhawula umgca, kufuneka ubhale oku kulandelayo:

s='s=%r;print(s%%s,sep="")';print(s%s,sep="")

IJavaScript

Le migca ilandelayo yeJavaScript iyasebenza phantsi kwe node.js. usebenzisa console.log, esoloko ifakela umgca omtsha, ngoko ke umgca omtsha uyafuneka ekupheleni kweskripthi ngasinye:

s="s=%j;console.log(s,s)";console.log(s,s)

Le nkqubo ilandelayo ikwanika umdla: ayishicileli umboniso wayo wonke, kodwa ixhomekeke kwinto yokuba imisebenzi inophawu oluthile.:

(function a(){console.log('('+a+')()')})()

Umzekelo olandelayo ukufutshane ukukopela kuba eval esetyenzisiweyo:

code='var q=unescape("%27");console.log("code="+q+code+q+";eval(code)")';eval(code)

Umhlwa

Umhlwa ubonelela ngendlela yokuvala ingxabano kwiingcaphuno kushicilelo olufomathiweyo olukhulu. Nangona kunjalo, le macro ifuna ingxabano yokuqala ye-macro yoshicilelo ukuba ibe ngumtya ongokoqobo! Ngoko ke kungcono kakhulu ukusebenzisa isichongi sengxoxo yesikhundla:

fn main(){print!("fn main(){{print!({0:?},{0:?})}}","fn main(){{print!({0:?},{0:?})}}")}

I-PHP

Le nkqubo ye-PHP isebenza ngokugcina ikhowudi yemvelaphi kumtya kwaye ke usebenzisa loo mtya printf iziphumo. I 39 imele uphawu lwe ASCII ', ukuphatha ngokuchanekileyo izicaphulo kumtya:

<?php
$code = '<?php
$code = %c%s%c;
printf($code, 39, $code, 39);
';
printf($code, 39, $code, 39);

HQ9+

Okokugqibela kodwa okungancinci yi-HQ9+, ephuhliswe nguCliff Biffle:

Q
Emva