Gravity ‘Hello World’ Program

The following code is a Gravity ‘Hello World’ program. It outputs ASCII values corresponding to the phrase ‘Hello world’, and then halts (assuming no input was provided).

(0,0) : 2

(1,1,1,1, 2) ->  3 :  72
(1,1,1,1, 3) ->  4 : 101
(1,1,1,1, 4) ->  5 : 108
(1,1,1,1, 5) ->  6 : 108
(1,1,1,1, 6) ->  7 : 111
(1,1,1,1, 7) ->  8 :  32
(1,1,1,1, 8) ->  9 : 119
(1,1,1,1, 9) -> 10 : 111
(1,1,1,1,10) -> 11 : 114
(1,1,1,1,11) -> 12 : 108
(1,1,1,1,12) ->  # : 100

Proof of function

By having a heavier particle at the origin, all particles start moving inwards. Every collision consists of four or more particles hitting the origin. In an unbounded number of collisions, exactly four particles will hit the particle at the origin, which will output the next character of the phrase ‘Hello World’ and increment the mass of the particle at the origin (or read from the input if the phrase is complete, halting the program). In the other collisions, the particle at the origin has the greatest mass and is therefore replaced after the collision.

This article was last edited on 14th April 2007. The author can be contacted using the form below.
Back to home page
Bookmark with: