📜 ⬆️ ⬇️

Happy programmer !! Atsimmargorp Mend S (Quine Palindrome)

I also join the congratulations in honor of the day of the programmer! And I do it with the help of a quine-palindrome.

Reading the post about multiquay generators and other posts about quains recently, I also wanted to do something interesting and non-standard in the field of quine. It did not take long to think, because the idea of ​​quain- palindromes lies on the surface.

Quine

So, in order to understand what I need, I immediately decided to take a ready quine on wikipedia and try to modify it.

Palindrome

Immediately write quine palindrome for me was hard. So I decided to start with the usual palindrome program. But how to write a program so that it is correctly executed when the source is reversed, because you get a non-compiled character set? It immediately comes to mind that you can comment on all this garbage. Since in C # two types of comments (single-line and multi-line), the corresponding programs were written:
')
Single line comments
//}}{)(niaM diov citats{P ssalc class P{static void Main(){}}// 


Multiline comments
 /**/class P{static void Main(){}};/*/;}}{)(niaM diov citats{P ssalc/**/ 

The second option is better because it does not depend on whether there is a line break or not. Before him, I did not immediately guess. However, later we managed to google palindromes in different languages on stackoverflow .

Utilities for checking programs

Since reversing the code for comments is a rather tedious process and can be accompanied by errors, before writing a quine palindrome, methods were written to check strings for palindrome and, more interestingly, methods to check if the input string could be compiled. If so, is the compiled program a quine? It looks like this:
Compiling a program from a line at runtime
 public static CheckingResult CompileAndGetOutput(string program) { CompilerResults compilerResults = null; using (CSharpCodeProvider provider = new CSharpCodeProvider()) { compilerResults = provider.CompileAssemblyFromSource(new CompilerParameters(new string[] { "System.dll" }) { GenerateExecutable = true }, new string[] { program }); } CheckingResult result; if (compilerResults.Errors.HasErrors) { result.FirstErrorLine = compilerResults.Errors[0].Line; result.FirstErrorColumn = compilerResults.Errors[0].Column; result.Output = null; } else { try { Process process = Process.Start(new ProcessStartInfo(compilerResults.PathToAssembly) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardInput = true, RedirectStandardOutput = true }); process.StandardInput.WriteLine(Environment.NewLine); process.WaitForExit(); string output = process.StandardOutput.ReadToEnd(); try { File.Delete(compilerResults.PathToAssembly); } catch { } result.FirstErrorLine = -1; result.FirstErrorColumn = -1; result.Output = output; } catch { result.FirstErrorLine = 0; result.FirstErrorColumn = 0; result.Output = null; } } return result; } 



Quine Palindrome

The result after several attempts at minification was the following. (Programs were written in halves and formatted for easy writing. After that, spaces were removed and the missing part was added in the form of comments at the beginning or end.)

Quine-palindrome using single-line comments:
 //}};)s+"r\n\r\"+)c(gnirts wen(etirW.elosnoC;)c(esreveR.yarrA;)(yarrArahCoT.s=c rav;)'\\','"',s,s(tamroF.gnirts=s;"//}}}};)s+}1{r}2{n}2{r}2{}1{+)c(gnirts wen(etirW.elosnoC;)c(esreveR.yarrA;)(yarrArahCoT.s=c rav;)'}2{}2{','}1{',s,s(tamroF.gnirts=s;}1{}0{}1{=s rav{{)(niaM diov citats{{P ssalc;metsyS gnisu"=s rav{)(niaM diov citats{P ssalc;metsyS gnisu using System;class P{static void Main(){var s="using System;class P{{static void Main(){{var s={1}{0}{1};s=string.Format(s,s,'{1}','{2}{2}');var c=s.ToCharArray();Array.Reverse(c);Console.Write(new string(c)+{1}{2}r{2}n{2}r{1}+s);}}}}//";s=string.Format(s,s,'"','\\');var c=s.ToCharArray();Array.Reverse(c);Console.Write(new string(c)+"\r\n\r"+s);}}// 


Quine-palindrome using multi-line comments:
 /*  !*/using System;class P{static void Main(){var s="{2}*  !*/using System;class P{{static void Main(){{var s={1}{0}{1};s=string.Format(s,s,'{1}','{2}');var c=s.ToCharArray();Array.Reverse(c);Console.Write(s+'*'+new string(c));}}}}/";s=string.Format(s,s,'"','/');var c=s.ToCharArray();Array.Reverse(c);Console.Write(s+'*'+new string(c));}}/*/}};))c(gnirts wen+'*'+s(etirW.elosnoC;)c(esreveR.yarrA;)(yarrArahCoT.s=c rav;)'/','"',s,s(tamroF.gnirts=s;"/}}}};))c(gnirts wen+'*'+s(etirW.elosnoC;)c(esreveR.yarrA;)(yarrArahCoT.s=c rav;)'}2{','}1{',s,s(tamroF.gnirts=s;}1{}0{}1{=s rav{{)(niaM diov citats{{P ssalc;metsyS gnisu/*!  *}2{"=s rav{)(niaM diov citats{P ssalc;metsyS gnisu/*!  */ 


On this topic, we managed to find only one efficient link to quine-palindromes. However, there was no solution in C #.

Link to the project on github: (in the future the collection will be replenished): Freaky-Sources

Throw quays-palindromes in other languages, as well as simply palindromes in honor of atsimmargorp or 31 whacks or all together :)

I wish fewer bugs, more interesting ideas and just a good Friday on this wonderful day!

Hidden text
! day of day tote to visit your good morning just and yedi skyline more often than ever before

): This is either Friday or Friday 13, or a programmer who is on a computer in a computer, but a computer is written in a computer in a computer.

secruoS-ykaerF :) yastyanlopop toedub of mechkyllok meschudud in (:: buhtig en tkorp en aklysS

. # C en unhesher solazako en mat okandO.imordilip-nyavk an uklyss uunled undo ushil ityang ékadu etkitameonnad op

/ * Happy programmer day! * / Using System; class P {static void Main () {var s = "{2} * Happy programmer day! * / Using System; class P {{static void Main () {{var s = {1} {0} {1}; s = string.Format (s, s, '{1}', '{2}'); var c = s.ToCharArray (); Array.Reverse ©; Console. Write (s + '*' + new string ©);}}}} / "; s = string.Format (s, s, '"', '/'); var c = s.ToCharArray (); Array.Reverse ©; Console.Write (s + '*' + new string ©);}} / * /}};)) c (gnirts wen + '*' + s (etirW.elosnoC;) c (esreveR.yarrA;) (yarrArahCoT .s = c rav;) '/', '"', s, s (tamroF.gnirts = s;" /}}}};)) c (gnirts wen + '*' + s (etirW.elosnoC;) c (esreveR.yarrA;) (yarrArahCoT.s = c rav;) '} 2 {', '} 1 {', s, s (tamroF.gnirts = s;} 1 {} 0 {} 1 {= s rav { {) (niaM diov citats {{P ssalc; metsyS gnisu / *! Atsimmargorp Mend With *} 2 {"= s rav {) (niaM diov citats {Pssalc; MetsyS gnisu / *! Atsimmargorp Mend C * /

: Viraemtemmok Hynchortsogonm Meinvozpozpsi with Mordnilap-NyavK

//}};) s + “r \ n \ r \” +) c (gnirts wen (etirW.elosnoC;) c (esreveR.yarrA;) (yarrArahCoT.s = c rav;) '\\', '" ', s, s (tamroF.gnirts = s; "//}}}};) s +} 1 {r} 2 {n} 2 {r} 2 {} 1 {+) c (gnirts wen (etirW.elosnoC ;) c (esreveR.yarrA;) (yarrArahCoT.s = c rav;) '} 2 {} 2 {', '} 1 {', s, s (tamroF.gnirts = s;} 1 {} 0 {} 1 {= s rav {{) (niaM diov citats {{P ssalc; metsyS gnisu "= s rav {) (niaM diov citats {P ssalc; metsyS gnisu

using System; class P {static void Main () {var s = "using System; class P {{static void Main () {{var s = {1} {0} {1}; s = string.Format (s , s, '{1}', '{2} {2}'); var c = s.ToCharArray (); Array.Reverse ©; Console.Write (new string © + {1} {2} r {2 } n {2} r {1} + s);}}}} // "; s = string.Format (s, s, '"', '\\'); var c = s.ToCharArray (); Array.Reverse ©; Console.Write (new string © + "\ r \ n \ r" + s);}} //

: Viraemtemmok Hynchortsondo Meinavozlopsi with Mordnilap-NyavK

markups

Mordnil-NyavK

Cruise season exercise campgrounds

: cat onremirp ote tidalgyyV? monyavk ammargorp yaannavorilipmoks yl yasteyalvya from hell ilsE.yastavorilipmok enil si yaandohv yl tezhom, ogot ikrevorp yald ydotem, onseretni eelob TSS and tsonmordnilap en Corts ikrevorp yald ydotem ynasipan ilyb amordnilap-anyavk meinasipan derep from, imakbisho yastadzhovorpos tezhom and yyndun onlovod ssetsorp veiratnemmok yald dock repair server

mmargorp ikrevorp professional

.wolfrevokcats en hakızı hınzar an ımordilin-rymargorp ıtilgugan іsoladu motop okandO.yaslamudod uzars i og ogan ot.ten or rykorts vyzar iltstse, ogot tisyvaz i ny byslokop rytokop, i ryklotoc ny og talivan, i korts otsand otsand motoc okandOn.O.

/ ** / class P {static void Main () {}}; / * /;}} {) (niaM diov citats {P ssalc / ** /

Awesome Money Trains

//}} {) (niaM diov citats {P ssalc

class P {static void Main () {}} //

Hot Springs

: Eischyuuvtstevtoos ynasipan ilyb ymmargorp and on,) and eynchortsogonm eynchortsondo (veiratnemmok adiv AED #C in both kaT.rosum SOFC sev tavoritnemmok onzhom otch, uvolog in tidohirp uzarS volovmis Roban yymeurilipmoken yastichulop dev, vokindohsi esrever PRI and salyanlopsi onlivarp ano ybotch ybotch,? Cat Ummargorp Ataspana as ON.Mordnilap-ymarmarpor Yonchibo from the plotter pischer I utotooP.zhelezhat solazako yald mordnilap-nyavktasipan uzarS

Portland

.Topicate, copyright, and monitor, and run away from the skin, cut it off, leave it alone, need to answer it, see

NyavK

titsonhave

.Amordnilap-anyavk yoshchomop with ote yuled i! Atsimmargorp ydsech in meinelvardzop to ksyuyanaidosirz ezhoz I

Source: https://habr.com/ru/post/189192/


All Articles