Make a quine. Simple enough, except it has to be a palindrome and accept input.

Now, any side of a palindromic quine is one half of it. For example, one side of the hypothetical quine AAAA is AA. One side of AAAAA is AA (the center symbol is ignored).

Your job is to make a quine like this that accepts input. If the input is the whole quine, then the quine prints the left side of itself. If the input is either side of the quine then the quine prints itself. Of course, with quines with an odd number of symbols the center symbol is ignored. If the input is anything other than the cases specified, the program must do nothing.

This is code golf, so the shortest submission wins.

  • It can be the right side, the left side or the quine itself. If anything else is inputted the program must do nothing. – Andrew Nov 25 at 9:31
  • @l4m2 From the spec it would need to print ; if the input is empty, so if ; is a nop it wouldn't be valid as far as I see. – Laikoni Nov 25 at 14:46
  • yee. the program must print nothing. – Andrew Nov 25 at 15:24
up vote 0 down vote accepted

Javascript, 224 200 bytes

Prompts for input. I shaved off some bytes by using ES6 features. Still can probably be golfed a lot more.

(f=_=>{a=prompt();s=`(f=${f})()/`;r=[...s].reverse().join('');return a==s||a==r?s+r:a==s+r?s:""})()//)()}"":s?r+s==a:r+s?r==a||s==a nruter;)''(nioj.)(esrever.]s...[=r;`/)()}f{$=f(`=s;)(tpmorp=a{>=_=f(

Haskell, 350 346 bytes

main=interact f;f s|s==l++r=l|s/=l,s/=r=[]|1<3=l++r;r=reverse l;l=q++show q++['-'];q="main=interact f;f s|s==l++r=l|s/=l,s/=r=[]|1<3=l++r;r=reverse l;l=q++show q++['-'];q="--"=q;]'-'[++q wohs++q=l;l esrever=r;r++l=3<1|][=r=/s,l=/s|l=r++l==s|s f;f tcaretni=niam"=q;]'-'[++q wohs++q=l;l esrever=r;r++l=3<1|][=r=/s,l=/s|l=r++l==s|s f;f tcaretni=niam

Edit: -4 bytes thanks to Ørjan Johansen! Also changed to a version which does not need (<>).

  • 1
    Save 4 bytes by rearranging guards to turn || into ,. (I also tried several ways to turn (++['-']) into something simpler like ('-':), including switching l and r, but it hasn't worked.) – Ørjan Johansen Nov 26 at 4:00
  • @ØrjanJohansen Thanks! – Laikoni Nov 26 at 17:47
  • the legend orjan johansen has appeared to help this man in his quest. – Andrew Nov 26 at 18:15
  • With your new version, you can save 4 more with shows. – Ørjan Johansen Nov 27 at 1:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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