Self-Writer: Coding Challenge

Ed Sullivan's coding challenge

In his new book, Under Pressure and On Time, Ed Sullivan reports that NuMega had a standard coding test for applicants:

For years, we gave the same programming test to every developer. It was a straightforward test that required no setup or external knowledge from manuals. The candidates were asked to write a program that could print its source to the screen exactly, without performing any file input.

Well, I've done this before, but it was a long time ago, so why don't we give this a whirl?

[Hugh Brown's Website, Hugh's C Solution]

Here is the best solution I could come up with in C#:

using System; 
public class Class1
{   
   static void Main(string[] args)   
   {     
      Console.Write(code + '\u0022' + code + '\u0022' + ';' + '\n' + '}');   
   }   
   public static string code =   
@"using System;
public class Class1
{   
   static void Main(string[] args)   
   {    
      Console.Write(code + '\u0022' + code + '\u0022' + ';' + '\n' + '}');   
   }   
   public static string code =   
@"
;
}
[Incase anyone is interested I colorized this code using CodeHtmler, written by Shawn Van Ness and Wes Haggard]
 
Update: I saw something that wanted me to see what the shortest possible "quine" I could come up with in C#. I came up with one that is 188 chars (including spaces)

class c{static void Main(){System.Console.Write(d+'\x22'+d+'\x22'+';'+'}');}static string d="class c{static void Main(){System.Console.Write(d+'\x22'+d+'\x22'+';'+'}');}static string d=";}

 
 

3 Comments

  • I got one too....
    a simple one to learn quine programming...

  • So it's years on but we just did this exercise for a lark...

    class e{static void Main(){System.Console.Write((d+='\x22')+d+';'+'}');}static string d=@"class e{static void Main(){System.Console.Write((d+='\x22')+d+';'+'}');}static string d=@";}


    (If that HTML'd correctly then it's 182 bytes)

  • OK, so HTML is not allowed I guess... here it is as plain text...

    class E{static void Main(){System.Console.Write((d+='\x22')+d+';'+'}');}static string d=@"class E{static void Main(){System.Console.Write((d+='\x22')+d+';'+'}');}static string d=@";}

Comments have been disabled for this content.