91
\$\begingroup\$

Dilbert is awesome
source: Dilbert, September 8, 1992

I'm hoping to add a new twist on the classic "Hello World!" program.

Code a program that outputs Hello World! without:

  • String/Character literals
  • Numbers (any base)
  • Pre-built functions that return "Hello World!"
  • RegEx literals

With the exceptions of "O" and 0.

†"O" is capitalized, "o" is not acceptable.

\$\endgroup\$
24
  • 1
    \$\begingroup\$ I hope by "numbers" you mean "numeric constants", because there probably wouldn't be much programming left without. \$\endgroup\$
    – J B
    Mar 11, 2011 at 21:42
  • 5
    \$\begingroup\$ One of [code-golf] and [code-challenge] please, not both. The point of these tags to to help people find questions with the rules they want to use. Essentially every question on this site should be a game of some kind or another. \$\endgroup\$ Mar 11, 2011 at 22:29
  • 4
    \$\begingroup\$ -1 We've already had Obfuscated Hello World, and I think this challenge is too similar. I'd have cast a "close as duplicate" vote, if I weren't a mod. \$\endgroup\$ Mar 11, 2011 at 22:35
  • 2
    \$\begingroup\$ @zzzzBov: I don't think it's different enough to warrant another question in the "hello world" theme; a different theme would have been better. But, that's just my opinion. \$\endgroup\$ Mar 11, 2011 at 23:39
  • 2
    \$\begingroup\$ Some people seem to assume that "O"* means they can have a string literal with any number of O’s, including zero. I don’t think that was the intention. Please clarify. \$\endgroup\$
    – Timwi
    Mar 12, 2011 at 21:12

108 Answers 108

3
\$\begingroup\$

JavaScript 662 chars

O=[[,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[],[,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,],[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]];for(O_O=[].length;O.length>O_O;O_O++)document.write(String.fromCharCode((O[O_O].length||-Math.pow([,,].length,[,,,,,].length)-[,,,,,,,].length)+Math.pow([,,].length,[,,,,,,].length)+Math.pow(++[,].length,[,,,].length)-[,].length));document.write(String.fromCharCode(Math.pow([,,].length,[,,,,,].length)+[,].length))

What about abusing array literals just to have unary base. This program has advantage of not using 0.

\$\endgroup\$
5
  • \$\begingroup\$ While this may be valid, this particular puzzle is a code golf, which means you should be aiming for the shortest code possible. At 600+ chars, you're nowhere near the <100 chars that the existing JS solutions already have. \$\endgroup\$
    – zzzzBov
    Nov 20, 2012 at 15:01
  • 2
    \$\begingroup\$ @zzzzBov: I'm actually not trying to win. \$\endgroup\$
    – 0..
    Nov 20, 2012 at 15:02
  • 1
    \$\begingroup\$ This program has advantage of not using 0. What about O_O=0;? \$\endgroup\$ Sep 15, 2016 at 15:12
  • \$\begingroup\$ @EriktheGolfer: Fixed, thanks. I failed to notice that one. \$\endgroup\$
    – 0..
    Sep 17, 2016 at 11:15
  • \$\begingroup\$ O_O=[].length can be written as O_O=false which decreases it by 4. \$\endgroup\$ Oct 26, 2016 at 14:54
3
\$\begingroup\$

Commodore 64 O.0! interpreter

O0 Hello World interpreter

The best I could come up with was to write an interpreter that would accept O and 0 - O starts the counter from 65 (A) and 0 adds 1 to the counter, so you have to enter the following to produce HELLOWORLD**

O0000000O0000O00000000000O00000000000O00000000000000O0000000000000000000000O00000000000000O00000000000000000O00000000000O000

Which I work out at 124 characters. To use, run the program and start typing with O, enter 0 to increase the character count and begin a new character with O again.

** The current version of the interpreter does not support the space or new line character, and you have to break [RUN/STOP] to stop it

\$\endgroup\$
3
\$\begingroup\$

APL (Dyalog Unicode), 35 bytesSBCS

{⍞←⍺,⍵,⍨⊃⍕⍬⋄⍞←!}/⎕NL≡Hello World←⍬0

Try it online!

⍬0 the list [[];0]

Hello World← store those two values in these two variables

the depth of that array; ¯2 (max-depth is 2, negative means ragged)

⎕NL Name List of defined variables (class 2 — negative means return as list of strings)

{}/ apply the following anonymous lambda infix between the two names:

 empty list; []

 stringify; ""

 coerce the first character; " "

⍵,⍨ append the right argument; " World"

⍺, prepend the left argument; "Hello World"

⍞← print that to stdout with no trailing line break

 then:

⍞←! print the factorial function to stdout

\$\endgroup\$
3
\$\begingroup\$

Julia 1.0, 45 bytes

print(string(:([Hello World!]))[-~-~0:~-end])

Try it online!

This is not cheating (I think)

  • :(...) is an Expr, which represents Julia code (AST or something)
  • [Hello World!] is a 2 by 1 Matrix containing two variables Hello and World!. They don't need to be defined since they are in an Expr (internally stored as Symbols)
  • string turns the Expr into a string: "[Hello World!]"
  • we remove the brackets: -~-~0 is 2 and ~-end is end-1
\$\endgroup\$
2
\$\begingroup\$

PHP, 220 202 201 characters

<?$b=++$a+$a;$y=$b+$a;$c=$y+$b;$z=$c*$b;$s=$y*$z+$b;$h=$s*$b+$z-$b;$e=$z*$z+$a;$o=$e+$z;$l=chr($o-$y);echo chr($h).chr($e).$l.$l.chr($o).chr($s).chr($h+$z+$c).chr($o).chr($o+$y).$l.chr(--$e).chr(++$s);

Uses no numbers, string literals, RegEx literals, or pre-built functions that display "Hello World!".

It works: http://codepad.viper-7.com/OhXBkA

\$\endgroup\$
2
\$\begingroup\$

Python (169) -- FIXED

Quite a bit longer than the other solutions. But more insane.

from turtle import setworldcoordinates as w
o=0**0
t=o+o+o
b=cmp.__ne__.__doc__
print(hex.__name__[0]+str(Ellipsis)[:t]+"O"+b[-t*t-o]+w.func_name[t:t*t-o]+b[-t]).title()
\$\endgroup\$
3
  • \$\begingroup\$ Sorry, typo on my behalf. I've corrected that error now. \$\endgroup\$
    – Jagu
    Mar 19, 2011 at 0:35
  • \$\begingroup\$ Nice. I would retract my downvote, but this stupid website doesn’t let me, so don’t blame me... \$\endgroup\$
    – Timwi
    Mar 19, 2011 at 17:00
  • \$\begingroup\$ @Timwi: I think if a question/answer is edited, you can undo your vote, can't you? \$\endgroup\$
    – Luna
    Apr 27, 2011 at 5:18
2
\$\begingroup\$

C - 125 128 chars

I didn't see a proper C entry so I wrote this one:

main(){char u='O'/'O',t=u+u+u,h=u<<t,s=h<<u+u,d='O'*'O'+t,l=d+h,o='O'|s,
g['O']={'O'-h+u,d+u,l,l,o,s,o+h,o,o+t,l,d,s+u};puts(g);}

(As noted below, redefining u via main(u) can save another 9 bytes.)

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Your array isn't NULL-terminated, so it prints junk. Pay 2 chars. Earn them back, and more, by main(u) instead of 'O'/'O'. \$\endgroup\$
    – ugoren
    May 8, 2012 at 6:58
2
\$\begingroup\$

C, 190 189 204

a,b,c,h,e,l,o;i[4],*j=i;main(_){o=*"O";a=_+_+_;b=_<<a;c=b*a+b;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h-c|e<<b|l<<b+b|l<<c-b;*j++=o|c<<b|o+b-c<<b+b|o<<c-b;*j=o+a|l<<b|e-_<<b+b|c+_<<c-b;puts(i);}
  • Must be run with exactly zero command line arguments since it depends on argc being equal to 1.
  • no preprocessor macros
  • Might be system endian dependant (involves cast from integer array to char array)
  • Not memory safe
a,b,c,h,e,l,o;   // variables
i[],m,*j=i;      // array and pointer

main(_)          // if no arguments are given _ will be 1
{
    o=*"O";      // our one legal string constant
    a=_+_+_;     // a = 3
    b=_<<a;      // b = 8
    c=b*a+b;     // c = 32
    h=(o>>_)^o;  // h = 'h'
    o^=c;        // o = 'o'
    e=h-a;       // e = 'e'
    l=o-h+e;     // l = 'l'
    *j++=h-c|e<<b|l<<b+b|l<<c-b;     // j[0] = 'H' | 'e' << 8 | 'l' << 16 | 'l' << 24
    *j++=o|c<<b|o+b-c<<b+b|o<<c-b;   // j[1] = 'o' | ' ' << 8 | 'W' << 16 | 'o' << 24
    *j=o+a|l<<b|e-_<<b+b|c+_<<c-b;   // j[2] = 'r' | 'l' << 8 | 'd' << 16 | '!' << 24
    
    puts(i);     // puts("Hello World!\0\0\0\0")
}

Revisions:

a,b,c,h,e,l,o;i[9],*j=i;main(_){o=*"O";a=_<<_|_;b=_<<a;c=_<<b-a;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h^c|e<<b|l<<b<<b|l<<(c-b);*j++=o|c<<b|(o+b^c)<<b<<b|o<<(c-b);*j=o+a|l<<b|e-_<<b<<b|c+_<<(c-b);printf(i);} /* original */
a,b,c,h,e,l,o;i[4],*j=i;main(_){o=*"O";a=_+_+_;b=_<<a;c=b*a+b;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h-c|e<<b|l<<b+b|l<<c-b;*j++=o|c<<b|o+b-c<<b+b|o<<c-b;*j=o+a|l<<b|e-_<<b+b|c+_<<c-b;puts(i);} /* golfed better */
a,b,c,h,e,l,o;i[],m,*j=i;main(_){o=*"O";a=_+_+_;b=_<<a;c=b*a+b;h=(o>>_)^o;o^=c;e=h-a;l=o-h+e;*j++=h-c|e<<b|l<<b+b|l<<c-b;*j++=o|c<<b|o+b-c<<b+b|o<<c-b;*j=o+a|l<<b|e-_<<b+b|c+_<<c-b;puts(i);} /* removed illegal numeric literal in array size */
\$\endgroup\$
4
  • \$\begingroup\$ i[9] violates the rules. \$\endgroup\$
    – ugoren
    Nov 9, 2012 at 18:15
  • \$\begingroup\$ shoot, it does doesn't it. \$\endgroup\$
    – Wug
    Nov 9, 2012 at 18:26
  • \$\begingroup\$ i['O'] should be fine. Or i[-~-~-~-~0]. \$\endgroup\$
    – ugoren
    Nov 9, 2012 at 21:05
  • \$\begingroup\$ The way that's there works (with the caveat that it starts scribbling over other global variables, but they're not read from again later so I don't care). I could probably reorder them to specifically take advantage of this behavior and make them only overwrite variables that are from-then-on unused. Anyway, at this point it contains no numeric literals and I rather like it that way. \$\endgroup\$
    – Wug
    Nov 9, 2012 at 21:57
2
\$\begingroup\$

JavaScript 100 chars (when all in one line)

Borrowing subtly from zzzzBov -- with regard to the -~ trick, not seen that before :) -- this is another way to source those pesky space and exclamation characters.

Relies on the Function.toString() ability:

c=!0<<-~-~!0;a=[];
for(i in{Hello:0,world:"O"}){a+=i+([]+function(){!0}).charAt(c);c+=c>>!0}
alert(a)

JavaScript 89 chars (when all in one line)

Also zzzzBov could slightly improve the first example by using the fact that arrays in JS collapse down to strings when used in a calculation; oh, and not creating needless vars ;)

t=!0<<-~-~-~-~!0;r=[];for(i in{Hello:"O",World:0})r+=i+String.fromCharCode(t++);alert(r)
\$\endgroup\$
2
\$\begingroup\$

Java - 147, no literals

class HelloCWorlds{static{char[]a=HelloCWorlds.class.getName().toCharArray();int
x=a.length,y=a[--x]%x;a[y]/=x/y;a[x]=a[y]--;System.out.print(a);}}

Run it like this (after compiling):

java HelloCWorlds 2>/dev/null

If you don't want to ignore stderr, then add System.exit(0); after the last semicolon. It brings the file size to 162 and makes use of the 0 literal.

\$\endgroup\$
3
  • \$\begingroup\$ Nice trick! Just one thing to mention: not works with OpenJDK. pastebin.com/gxE7PrjX \$\endgroup\$
    – manatwork
    Mar 19, 2013 at 8:42
  • \$\begingroup\$ @manatwork Hmm I think it's not about OpenJDK, but about java 6 vs 7 \$\endgroup\$ Mar 19, 2013 at 8:55
  • \$\begingroup\$ Possible. BTW, I dug out an old “java version "1.4.2_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)” to test this – also works fine. \$\endgroup\$
    – manatwork
    Mar 19, 2013 at 9:04
2
\$\begingroup\$

Python3, 16 bytes

import __hello__

Note the rule:

pre-built functions that return "Hello World!"

Does not apply since:

  1. That's an import and not a function
  2. It doesn't return anything
  3. It doesn't return the string but simply prints it.
\$\endgroup\$
2
\$\begingroup\$

Python 3 – 99 chars

from re import*
c=X+U+L;_=c+M
print(bytes([X+M,-~c,_,_,_-~I,U,X+U+~M,_-~I,c+S-I,_,c,-~U]).decode())

Taking advantage of the fact that the re module uses integers as flags, e.g. re.X is 64.

\$\endgroup\$
2
\$\begingroup\$

JavaScript, 661 characters (without "O" or 0)

That's not the shortest, but that was funny to make. I tried to make it without 0 or "O".

I'm not really happy with H and W because it's the only ones which uses non-symbols characters, but that works. If anyone has an idea to do it ...

This is javascript code, tested in firefox 27 scratchpad, and running with Ctrl+I (should I add an alert or console.log ?).

(document+[])[(++[[]+[]][+[]])<<(++[[]+[]][+[]])<<(++[[]+[]][+[]])<<(++[[]+[]][+[]])] // H
+((!!{})+[])[((++[[]+[]][+[]])<<(++[[]+[]][+[]]))+(++[[]+[]][+[]])]                   // e
+([]+(![]))[(++[[]+[]][+[]])<<(++[[]+[]][+[]])]                                       // l
+([]+(![]))[(++[[]+[]][+[]])<<(++[[]+[]][+[]])]                                       // l
+([]+{})[++[[]+[]][+[]]]                                                              // o
+([]+{})[((++[[]+[]][+[]]<<(~!+[]))+[])[(++[[]+[]][+[]])<<(++[[]+[]][+[]])]]          //  
+(self+[])[(++[[]+[]][+[]])<<(++[[]+[]][+[]])<<(++[[]+[]][+[]])<<(++[[]+[]][+[]])]    // W
+([]+{})[++[[]+[]][+[]]]                                                              // o
+([]+(!!{}))[++[[]+[]][+[]]]                                                          // r
+([]+(![]))[(++[[]+[]][+[]])<<(++[[]+[]][+[]])]                                       // l
+([][+[]]+[])[(++[[]+[]][+[]])<<(++[[]+[]][+[]])<<(++[[]+[]][+[]])<<(++[[]+[]][+[]])] // d
+((/!/)+[])[++[[]+[]][+[]]]                                                           // !

(the count of 661 of course doesn't include the comments)

\$\endgroup\$
1
  • \$\begingroup\$ I have one in the Obfuscated Hello world task that makes use of assignment. The idea is to use the Function constructor (which is reachable as ""["constructor"]["constructor"]) to allow arbitrary code. You could do something similar perhaps. \$\endgroup\$
    – FireFly
    Feb 5, 2014 at 13:49
2
\$\begingroup\$

Heres my Perl entry.

It uses the length of an array to store the ordinal of the character.

use strict;
use warnings;
use 5.010;
my @hello_world = (
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  [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_;"} qw"strict warnings 5.010";
  say "my \@hello_world = (";
  say "  [",join(",",@$_),"]," for map{[(0) x ord]} split //, "Hello World";
  say ");";
  say q"say map{ chr @$_ } @hello_world;"
'
\$\endgroup\$
2
\$\begingroup\$

bash, 66 characters

66 characters, no new lines

Hello(){ H=$FUNCNAME;};World! (){ echo $H $FUNCNAME;};Hello;World!

Previous version (81 characters), left here because I like the $IFS trick :-)

81 characters, no new lines

Hello(){ H=$FUNCNAME;};World! (){ echo $H${IFS:0:$[0**0]}$FUNCNAME;};Hello;World!

81 as well but with (including) new lines and easier to read

Hello(){ H=$FUNCNAME;}
World! (){ echo $H${IFS:0:$[0**0]}$FUNCNAME;}
Hello;World!

Commented version

Hello(){ H=$FUNCNAME;}                        # set $H to function name ("Hello")
World! (){ echo $H${IFS:0:$[0**0]}$FUNCNAME;} # print $H, first char of $IFS (" ") & "World!"
Hello;World!                                  # run the stuff

(strictly speaking the calculation 0**0 should be indeterminate but it evaluates to 1 :-D)

\$\endgroup\$
2
\$\begingroup\$

Python 2, 116

def Hello(n,m,j):print n.func_name,m.func_name+chr(j)
def World():pass
o=-~0;O=o+o;P=O<<O*O;Hello(Hello,World,P+o)

This is the best I can do so far. Hooray, func_name! (I may or may not try this in Befunge as well.)

(Oops, someone already did this better. Upvote that one instead.)

\$\endgroup\$
2
\$\begingroup\$

Python, 139 bytes

class World():
 pass
class Hello(World):
 def __init__(self):
  print(self.__class__.__name__, self.__class__.__base__.__name__)
O=Hello()
\$\endgroup\$
1
2
\$\begingroup\$

SmileBASIC, 98 bytes (non-competing)

I admit, this answer is cheating. Labels transparently behave as strings when in an expression, but technically they aren't string or character literals, right? If anyone wants to weigh in feel free but I'm convinced a SmileBASIC answer would just amount to abusing PI() or EXP() to compute every character code.

S=VAL(RIGHT$(@32,2))?RIGHT$(@Hello,5)+CHR$(S+LEN(@O0O0O0O0O0O))+CHR$(S)+RIGHT$(@world,5)+CHR$(S+1)

You could easily golf this more, I'm sure.

\$\endgroup\$
2
\$\begingroup\$

Unlambda, 37 bytes

Note that Unlambda doesn't have string or integer literals; .a is a function with a two-character name that writes a to standard output; it's not a function . that takes a as argument.

`.!`.d`.l`.r`.o`.W`. `.o`.l`.l`.e`.Hi

Try it online

\$\endgroup\$
2
\$\begingroup\$

Forth (gforth), 38 bytes

: f name type ; f Hello space f World!

Try it online!

OR

name World! name Hello type space type

Try it online!

Explanation

Uses the Forth built-in for processing code to convert the next character entered to a string, and then prints it

Code Explanation

: f             \ start a new word definition
  name          \ grabs the next word (space-delimited) from the input/code
  type          \ output the string on top of the stack
;               \ end word definition
f Hello         \ converts and outputs Hello, as name will grab Hello from the input before continuing
space           \ outputs a single space
f World!        \ converts World! to a string and outputs it
\$\endgroup\$
2
\$\begingroup\$

Swift, 193 174 172 126 116 102 bytes

enum h{case Hello,World};print(h.Hello,"\(h.World)\(UnicodeScalar("OOOOOOOOOOO".count*"OOO".count)!)")

Ungolfed:

enum HelloWorld {
    case Hello
    case World
}

let exclamationPoint = String(UnicodeScalar(
    String(repeating: "O", count: 11).count
    * String(repeating: "O", count: 3).count
)!)

print(
    HelloWorld.Hello,
    String(describing: HelloWorld.World) + exclamationPoint
)

Let's go through this step by step:

enum HelloWorld {
    case Hello
    case World
}

When converting these cases to Strings (for example, by printing them or using them in a string interpolation), they will evaluate to "Hello" and "World", respectively.

let exclamationPoint = String(UnicodeScalar(
    String(repeating: "O", count: 11).count
    * String(repeating: "O", count: 3).count
)!)

Since we can't use exclamation points in identifiers, we'll have to do something else. The ASCII value of "!" is 33, so creating an 11-character String and a 3-character String and multiplying their count properties will do the job.

print(
    HelloWorld.Hello,
    String(describing: HelloWorld.World) + exclamationPoint
)

The print call here has 2 arguments: HelloWorld.Hello and String(describing: HelloWorld.World) + exclamationPoint, equivalent to "Hello" and "World" + "!".

By default, print separates its arguments with a space. This gives us our final result of "Hello World!". (There's actually a newline at the end because print's default terminator is a newline.)

Extra Notes

  • I considered using the -~-~-~0 trick I've seen in some other answers, but Swift doesn't let you use multiple unary operators without parentheses (due to its support for custom operators), meaning it's more like -(~(-(~(-(~0))))), which is horribly inefficient.
\$\endgroup\$
1
\$\begingroup\$

Python 272 chars

s=ord('O')
a=len('0')
b=a+a
c=b+a
d=c+a
e=d+a
f=e+a
g=f+a
h=g+a
print chr(s-g)+chr(s+g*c+a)+chr(s+g*d+a)+chr(s+g*d+a)+chr(s+h*d)+chr(s-h*f+a)+chr(s+h)+chr(s+h*d)+chr(s+g*e)+chr(s+g*d+a)+chr(s+g*c)+chr(s-h*f+b)

Though I'm surprised no one tried this method

Python 31 chars

f=open(r'/0.O',)
print f.read()
\$\endgroup\$
1
  • \$\begingroup\$ I don't think '0' is valid. I think only 0 and '0' are valid. \$\endgroup\$ Oct 26, 2016 at 17:27
1
\$\begingroup\$

Scala 159

val o='O'/'O'
val t=o+o
val d=t+o
val f=t*t
val e=f*t
val l=' '-d
println (List(-e+o,d*e-t,l,l,' ',-'/',e,' ',' '+d,l,(e-1)*d).map(x=>(x+'O').toChar).mkString)

ungolfed:

val one='O'/'O'
val two=one+one
val drei=two+one // tri, three
val four=two*two
val eight=four<<one

val l=' ' - drei
val h=List(-eight+one, four*eight-two, l, l, ' ', -'/'+one, eight, ' ', ' ' + drei, l, (eight-1)*drei)
println (h.map (x=> (x + 'O').toChar).mkString)
\$\endgroup\$
1
\$\begingroup\$

Common Lisp, 35

I think nobody tried Common Lisp. Strictly speaking, a symbol is not a string literal, so this is valid:

(print(symbol-name'|Hello World!|))

Second-short if you count the Mathematica one.

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

Perl, 96 chars

sub AUTOLOAD{my$x++;$y=$x<<$x++;print substr($AUTOLOAD,$x+$y).chr(($x<<$y)+$a++)}
&Hello;&World

It passes the rules!

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

Groovy, 117

def propertyMissing(p){p}
b="OOOOOOOO"
c={(char)it.size()}
a=b+b+b+b
println(Hello+c(a+b+"OOOO")+c(a)+World+c(a+"O"))

prints

Hello, World!
\$\endgroup\$
1
\$\begingroup\$

Lua, 36

print(next{Hello=0},(next{world=0}))
\$\endgroup\$
1
\$\begingroup\$

Tcl

In Tcl, everything is a string.

puts Hello\ World!

If you disallow this, then this is the only valid Tcl program that can be written:

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

Fish - 270

>"O":l(?!v~~~~~~~lo 00000v |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !<lo0000000000000000000v  |0000000 !<lo000lo~~~~~~lo~~~~~~~~lo~~~~~~~~~v;
^        <|000000000000 !<lo0000000l:oo000lo~~~~~~~~~~~~~~~~~^|000000000000000000 !<lo0000000000^  |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !<lo;

Using |0000000000 !< to double the number of 0's put onto the stack. It will bounce off the mirror, and then jump past the <.

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

PowerShell: 596 382

Started with Joey's idea (Excel counts 1155 characters!) and cut it by about half with some math, then down to a third with some more math and optimization of my own script.

Original: 596 characters:

My first version was fairly similar to the current one in general theory, but a bit simpler in implementation. I just took each character's ASCII code and broke it into two factors, then converted those into strings of zeroes that were as long as the factors, and made PowerShell put them back together. Some numbers were problematic since the smallest factor pairs I could come up with were pretty high - especially 'e', since 101 is prime.

$O=('000000000','00000000'),('00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000','0'),('0000','000000000000000000000000000'),('0000','000000000000000000000000000'),('000','0000000000000000000000000000000000000'),('00000000','0000'),('000','00000000000000000000000000000'),('000','0000000000000000000000000000000000000'),('000000','0000000000000000000'),('0000','000000000000000000000000000'),('0000000000','0000000000'),('000','00000000000');for($0=0;$0-lt$O.Length;$0++){$O[$0]=($O[$0][0].length,$O[$0][1].length)-join'*'|iex}[char[]]$O-join''

Current: 382 characters

The current version includes a few optimizations, and a change to more comfortably suit the spirit of the challenge.

  • All factor pairs now end up 23 short of their actual target. This makes every element equate to a composite number, greatly reducing the characters required to build all of them. This alone saved about 156 characters.
  • Used a ForEach-Object loop, via the % alias, instead of for.
  • Replaced the 1 (though it was defining array indexes, and so not strictly a number or string literal) with '0'.length. This may cost me some characters, but it's relatively small in comparison to the overall length of the script and helps to fit in with the theme a bit better.
  • Optimized the multiplication routine by using a % loop instead of individually calling out array elements.
  • Restructured the script so that no defined variables are needed.
-join[char[]](('0000000','0000000'),('000000','0000000000000'),('00000','00000000000000000'),('00000','00000000000000000'),('00000000','00000000000'),('000','000'),('00000000','00000000'),('00000000','00000000000'),('0000000','0000000000000'),('00000','00000000000000000'),('0000000','00000000000'),('00','00000')|%{(($_|%{$_.length})-join'*'|iex)+'00000000000000000000000'.length})

Step-by-step:

-join[char[]](...) will take an array of integers (generated by the script within), convert them to ASCII characters, and put it all together in one string output.

('0000000','0000000'),('000000','0000000000000'),... are pairs of strings of zeroes. Within a pair, the product of each string's length comes 23 short of an ASCII code needed to represent a character in 'Hello World!'.

|%{...} pipes the factor pairs into a ForEach-Object loop.

(($_|%{$_.length})-join'*'|iex) takes the length of each factor in a pair and multiplies them together.

+'00000000000000000000000'.length effectively adds 23 to the product, resulting in our target ASCII code.

Hello World!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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