Create a gist now

Instantly share code, notes, and snippets.

@qrohlf /helloworld
Last active Jul 26, 2016

What would you like to do?
Ruby Hello World
  = 1
   =  + 
    =   *  + 
     =    *  
      =
[     *(   +  )+  ,
        =     *    + ,
         =     *    +    -  ,
        ,
        =        +    ,
    *  +    +  ,
    *    -  *    +   +  ,
       ,
       + +  ,
        ,
    *    ,     + +  ,
    ]
puts      .map(&:chr).join
@pboling
pboling commented Dec 28, 2015

That is not valid Ruby, failure on first line.

∴ irb
>>       = 1
SyntaxError: (irb):1: syntax error, unexpected '='
      = 1
       ^

I am sure it is based on something that did work for someone somehow, anyone know how to fix it?

@BatmanAoD

@pboling Yes, you need to ensure that you're actually feeding the invisible unicode characters to the interpreter; you may be inadvertently stripping them during the copy-and-paste. (It appears that some or all online interpreters do this.) See this StackOverflow question.

@BatmanAoD

It would be interesting to know if there are particular versions of Ruby that don't treat special whitespace unicode points as valid identifier characters. I think a Ruby feature-request to make future versions of Ruby treat all unicode whitespace as real whitespace (i.e. assume it indicates a separation between two tokens but otherwise ignore it) would probably be helpful.

@mvidner
mvidner commented Jan 29, 2016

Nice! Here's a readability trick:

ruby -p -e '$_.gsub!(/ +/," ").gsub!(/\u00a0+/){|m| "v#{m.size}"}' < helloworld 

prints

v1 = 1
v2 = v1+v1
v3 = v2*v2+v1
v4 = v3*v2
v5 = 
 [v4 *(v3+v2)+v2, 
 v7 = v4*v4+v1, 
 v8 = v4*v4+v4-v2, 
 v8, 
 v7 = v7+v4,
 v4*v2+v4+v2, 
 v4*v4-v2*v4+v3+v2, 
 v7, 
 v7+v1+v2, 
 v8, 
 v4*v4, v4+v1+v2, 
 v4]
puts v5.map(&:chr).join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment