-9
\$\begingroup\$

The challenge is to write the string hello world to your processes standard output, using as few characters of code as possible.

The following restrictions apply:

  • The following words may not appear anywhere in the code in any casing (this includes as part of another word)

    1. Console
    2. Debug
    3. Write
    4. Print
    5. Line
    6. Put
  • Your code must compile as C# 4/4.5

  • No external libraries are permitted.

  • Your process may not spawn any new processes.

A working (but not necessarily the shortest) solution will be provided after a number of answers have been provided.

The winner is the author of the shortest code by character count that satisfies the above criteria.

\$\endgroup\$
5
  • \$\begingroup\$ There is at least one solution to this in the answers to codegolf.stackexchange.com/questions/5550/… \$\endgroup\$ Commented May 14, 2013 at 15:50
  • \$\begingroup\$ @PeterTaylor - none of the C# answers posted for that challenge satisfy the word usage restriction. \$\endgroup\$
    – PhonicUK
    Commented May 14, 2013 at 16:29
  • \$\begingroup\$ w0lf's one does. There are also some answers in codegolf.stackexchange.com/questions/307/obfuscated-hello-world which demonstrate a technique which could be applied to the trivial hello world program (and which I see Johannes Kuhn has used in his answer). \$\endgroup\$ Commented May 14, 2013 at 17:57
  • \$\begingroup\$ @JohannesKuhn how is it a duplicate? The restrictions are completely different. \$\endgroup\$
    – PhonicUK
    Commented May 14, 2013 at 19:19
  • \$\begingroup\$ Not exactly. You may violate 1 rule of the other question, and for C# it have to be rule 1 (class is needed). All of the words you list here except put violate rule 2. That means the difference is that on the other question put and other languages are allowed and here the characters eor0127 are allowed. Not very big. \$\endgroup\$ Commented May 14, 2013 at 19:48

4 Answers 4

3
\$\begingroup\$

75 chars

New answer, new approach.

class M{static void Main(){System.\u0043onsole.\u0057rite("hello world");}}

It looks like you can hide every character with a \uXXXX sequence. Which makes this thing...
Easy.

\$\endgroup\$
1
\$\begingroup\$

Here's my current best that runs anywhere:

158 Characters

using System;class M{static void Main(){Type.GetType("System.\x43onsole").GetMethod("\x57rite\x4cine",new[]{typeof(string)}).Invoke(0,new[]{"hello world"});}}

.Invoke ignores the first param entirely if its a static method, so you can use 0 instead of null to save 3 characters.

Additionally, a variation that bans the use of the \ character:

234 Characters

using System;using System.Linq;class M{static void Main(){Func<string,string>f=(i)=>new string(i.Reverse().ToArray());Type.GetType(f("elosnoC.metsyS")).GetMethod(f("eniLetirW"),new[]{typeof(string)}).Invoke(0,new[]{"hello world"});}}
\$\endgroup\$
1
\$\begingroup\$

183 chars

Without reflection "cheats"! (but using the deprecated overload of FileStream to avoid using SafeFilePointer)

using System;using System.IO;public class M{static void Main(){new MemoryStream(Convert.FromBase64String("SGVsbG8gV29ybGQ=")).CopyTo(new FileStream(new IntPtr(-11),(FileAccess)2));}}
\$\endgroup\$
0
\$\begingroup\$

Ok, I try my luck:

118 chars

class M{static void Main(){System.Type.GetType("System.\x43onsole").GetMethods()[78].Invoke(0,new[]{"hello world"});}}

Based on this solution.

Idone

As noted in the original answer, the index of the Write method might be different on your system.

\$\endgroup\$
2
  • \$\begingroup\$ 'Object of type 'System.String' cannot be converted to type 'System.Int32'' You were right about the index not being the same. Since it doesn't run for me I can't accept this particular answer. \$\endgroup\$
    – PhonicUK
    Commented May 14, 2013 at 18:21
  • \$\begingroup\$ It runs on Idone. You have to change the index. Try 78. \$\endgroup\$ Commented May 14, 2013 at 18:50

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