Come up with the most inefficient, poorly written, and complex way to print out "Hello World!".

29    16 Jul 2015 20:01 by u/jped

I got bored today sitting at home and thought about doing this.

edit: its always fun to take things to extreme

39 comments

29

https://veuwer.com/i/2v3m.gif

Not really poorly written, but definitely inefficient and complex.

2

I'm not 100% sure what is going on, but I love it.

4

When writing files on a computer, it's written with bits. The file extensions or what program you open them with is how you expect the bits to interpreted. In a .bmp, the bits are meant to be interpreted as colours but if you open it in notepad then it interprets those bits as text.

0

So you wrote C code in Paint?

1

Not quite, I wasn't the one who wrote the one in the gif, I found it here on stack overflow. However I have reproduced it by writing the c++ code first and then opening it up in paint. Then you add some bogus values to make it a rectangle without changing the rest of the bits that actually contain the code. Go backwards from there and voila!

In theory this could work with any program you want, just depends on the kind of determination you have.

0

I will never be this good at any sort of programming.

I have no words for how impressed I am by the dedication it must take to write C++ in MSPaint.

1
  1. Write it in C++
  2. Rename the extension to .bmp
  3. Open it in paint
  4. Record the values and make some tweaks to make it an 8x4 block or otherwise
  5. Do it in reverse.
0

Files do start off with "Magic Numbers" that tell the computer what type they are, but a whole lot of programs are content to ignore them.

1

You did not do this, this has been on the internet for years

1

I never claimed to have made this .gif.

0

I'm impressed.

17
2

you win, here have 1 internet

9

Concepts:

 

Get random character from Unicode-32 one-by-one until they combine to "Hello World!" and then print it.


Generate random string, calculate hash (md5/SHA-1/whatever) until it will get "Hello World"


Download random image from igmur/tumblr/veuwer whatever calculate hash until you get "Hello world"


Calculate number Pi until its substring is "Hello world!" (ASCII encoded)


Find (m, n) for Ackermann_function when the value is equal to ASCII representation of "Hello World"

 

Feel free to implement and share when you are done.

9

Hello world you say? How about a sort of genetic algorithm to try to intelligently come up with Hello World! knowing and using nothing except a customizable suitability method?

The following code is written for a C# forms window. Simply add a textbox named outputTextBox and a button named goButton with a click event goButton_Click. Alternatively it'd be trivial to port to a console app, but I'm lazy(?). Variables that might be fun to play with are consted and all caps. This program probably has bugs and is undoubtedly poorly written. Enjoy!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HelloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int GetClosenessMeasure(string output)
        {
            const int missValue = 50;
            const string target = "Hello World!";
            int result = 0;
            int length = Math.Min(output.Length, target.Length);
            for (int i = 0; i < length; i++)
                result += Math.Abs(target[i] - output[i]);
            result += Math.Abs(target.Length - output.Length) * missValue;
            return result;
        }
        void SeekTheGoldenChild()
        {
            const int MAX_SURVIVORS_PER_GEN = 50;
            const int CHILDREN_PER_GEN = 10;
            const int OUTPUT_INTERVAL = 1000;
            int generations = 0;
            bool done = false;
            List<Entity> generation = new List<Entity>();
            for (int i = 0; i < 100; i++)
                generation.Add(new Entity(GetClosenessMeasure));
            while (!done)
            {
                generation.Sort((a, b) => a.MySuitability - b.MySuitability);
                if (generation[0].MySuitability == 0)
                {
                    WriteLine("We have a winner from generation " + generations + "!!" + Environment.NewLine + Environment.NewLine + Environment.NewLine + generation[0].MyDNA);
                    done = true;
                }
                else
                {
                    generation.RemoveRange(MAX_SURVIVORS_PER_GEN, generation.Count - MAX_SURVIVORS_PER_GEN);
                    if (generations % OUTPUT_INTERVAL == 0)
                        WriteLine("Generation " + generations + " most eligible bachelor with a suitability of " + generation[0].MySuitability + " is: " + generation[0].MyDNA);
                    List<Entity> tempGen = new List<Entity>();
                    for (int i = 0; i < generation.Count - 1; i++)
                        for (int j = 0; j < CHILDREN_PER_GEN; j++)
                            tempGen.Add(generation[i].MakeBaby(generation[i + 1]));
                    generation = tempGen;
                }
                ++generations;
            }
        }
        void WriteLine(string s)
        {
            Action a = ( () => outputTextBox.AppendText(s + Environment.NewLine));
            if (outputTextBox.InvokeRequired)
                outputTextBox.BeginInvoke(a);
            else
                a();
        }
        private void goButton_Click(object sender, EventArgs e)
        {
            Task.Run(() => SeekTheGoldenChild());
        }
    }
    public class Entity
    {
        const int MAX_LENGTH = 50;
        const string LANGUAGE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*() ";
        static Random rng = new Random();
        public string MyDNA { get; private set; }
        public int MySuitability { get; private set; }
        private Func<string, int> mySuitabilityMethod;
        public Entity(Func<string,int> SuitabilityMethod)
        {
            int length = rng.Next(MAX_LENGTH);
            MyDNA = new string(Enumerable.Repeat(LANGUAGE, length).Select(s => s[rng.Next(s.Length)]).ToArray());
            MySuitability = SuitabilityMethod(MyDNA);
            mySuitabilityMethod = SuitabilityMethod;
        }
        private Entity(string dna, Func<string, int> SuitabilityMethod)
        {
            MyDNA = dna;
            MySuitability = SuitabilityMethod(dna);
            mySuitabilityMethod = SuitabilityMethod;
        }
        enum GeneticLotteryWinner {Me, Partner, Milkman};
        private GeneticLotteryWinner GetGeneticLotteryWinner(int percentForMe, int percentForPartner, int percentForMilkman)
        {
            int roll = rng.Next(100);
            if (roll < percentForMe)
                return GeneticLotteryWinner.Me;
            else if (roll < percentForMe + percentForPartner)
                return GeneticLotteryWinner.Partner;
            else
                return GeneticLotteryWinner.Milkman;
        }
        public Entity MakeBaby(Entity partner)
        {
            const int DOM_LENGTH_ODDS = 60;
            const int SUB_LENGTH_ODDS = 20;
            const int MILK_LENGTH_ODDS = 20;
            const int DOM_DNA_ODDS = 60;
            const int SUB_DNA_ODDS = 20;
            const int MILK_DNA_ODDS = 20;
            Entity dom = MySuitability >= partner.MySuitability ? this : partner;
            Entity sub = dom == this ? partner : this;
            // we'll use a 60 : 20 : 20 ratio for breeding. The dom gets a 60% preference, followed by a 20% for the sub and a 20% for randomness
            GeneticLotteryWinner lengthWinner = GetGeneticLotteryWinner(DOM_LENGTH_ODDS, SUB_LENGTH_ODDS, MILK_LENGTH_ODDS);
            int length;
            switch (lengthWinner)
            {
                case GeneticLotteryWinner.Me:
                    length = MyDNA.Length;
                    break;
                case GeneticLotteryWinner.Partner:
                    length = partner.MyDNA.Length;
                    break;
                default:
                    length = rng.Next(MAX_LENGTH);
                    break;
            }
            char[] dnaTemp = new char[length];
            for (int i = 0; i < dnaTemp.Length; i++)
            {
                int domOdds = DOM_DNA_ODDS, subOdds = SUB_DNA_ODDS, milkOdds = MILK_DNA_ODDS;
                if (i >= dom.MyDNA.Length && i >= sub.MyDNA.Length) { domOdds = 0; subOdds = 0; milkOdds = 100; }
                else if (i >= dom.MyDNA.Length) { subOdds += domOdds; domOdds = 0; }
                else if (i >= sub.MyDNA.Length) { domOdds += subOdds; subOdds = 0; }
                GeneticLotteryWinner dnaSpotWinner = GetGeneticLotteryWinner(domOdds, subOdds, milkOdds);
                switch (dnaSpotWinner)
                {
                    case GeneticLotteryWinner.Me:
                        dnaTemp[i] = dom.MyDNA[i];
                        break;
                    case GeneticLotteryWinner.Partner:
                        dnaTemp[i] = sub.MyDNA[i];
                        break;
                    default:
                        dnaTemp[i] = LANGUAGE[rng.Next(LANGUAGE.Length)];                       
                        break;
                }
            }
            return new Entity(new string(dnaTemp), mySuitabilityMethod);
        }
    }
}
1

Sample output where it just couldn't get it:

Hello World!
Generation 0 most eligible bachelor with a suitability of 302 is: 60cse9EbTY
Generation 1000 most eligible bachelor with a suitability of 10 is: Hbmln Xnslb!
Generation 2000 most eligible bachelor with a suitability of 7 is: Hcllo Wnnld!
Generation 3000 most eligible bachelor with a suitability of 11 is: Iejlo Wnskh 
Generation 4000 most eligible bachelor with a suitability of 6 is: Felpo World!
Generation 5000 most eligible bachelor with a suitability of 8 is: Gello Voplh!
Generation 6000 most eligible bachelor with a suitability of 6 is: Hfllp Woqmd#
Generation 7000 most eligible bachelor with a suitability of 12 is: Fejlm Unrod!
Generation 8000 most eligible bachelor with a suitability of 11 is: Fcnmo Wnrnd 
Generation 9000 most eligible bachelor with a suitability of 5 is: Idllo Wqrkd!
Generation 10000 most eligible bachelor with a suitability of 12 is: Efjlo Xproc!
Generation 11000 most eligible bachelor with a suitability of 11 is: Hejlo Xqslh 
Generation 12000 most eligible bachelor with a suitability of 7 is: Helio!Would!
Generation 13000 most eligible bachelor with a suitability of 9 is: Hemjo#Uorld 
Generation 14000 most eligible bachelor with a suitability of 4 is: Hemmo Vorle!
Generation 15000 most eligible bachelor with a suitability of 12 is: Ijklo Wprie!
Generation 16000 most eligible bachelor with a suitability of 9 is: Gdklp!Uoqle!
Generation 17000 most eligible bachelor with a suitability of 7 is: Hfono Wosld!
Generation 18000 most eligible bachelor with a suitability of 7 is: Hemlo Wopme#
Generation 19000 most eligible bachelor with a suitability of 5 is: Hemmo Uorle!
Generation 20000 most eligible bachelor with a suitability of 8 is: Ielhp Wprlc!
Generation 21000 most eligible bachelor with a suitability of 12 is: Ldlkp!Woqmf!
Generation 22000 most eligible bachelor with a suitability of 10 is: Gfmlm Xmrlb!
Generation 23000 most eligible bachelor with a suitability of 3 is: Helmo Xormd!
Generation 24000 most eligible bachelor with a suitability of 12 is: Fgmlo!Vntnd!
Generation 25000 most eligible bachelor with a suitability of 10 is: Gdnlo Wosoe 
Generation 26000 most eligible bachelor with a suitability of 12 is: Hemnn Wnuie!
Generation 27000 most eligible bachelor with a suitability of 7 is: Hekln#Wnsld!
Generation 28000 most eligible bachelor with a suitability of 8 is: Heplp Worod!
Generation 29000 most eligible bachelor with a suitability of 13 is: Jgkoo Xosmf!
Generation 30000 most eligible bachelor with a suitability of 9 is: Hejlo Wmskb 
Generation 31000 most eligible bachelor with a suitability of 9 is: Hfkjp Xpsld 
Generation 32000 most eligible bachelor with a suitability of 9 is: Helkm Xlrjd!
Generation 33000 most eligible bachelor with a suitability of 5 is: Hello Vorka!
Generation 34000 most eligible bachelor with a suitability of 11 is: Helko Wqkmd!
Generation 35000 most eligible bachelor with a suitability of 15 is: Hehnm Xptmb!
Generation 36000 most eligible bachelor with a suitability of 8 is: Helko Rorme!
Generation 37000 most eligible bachelor with a suitability of 11 is: Egmko Xmrlc!
Generation 38000 most eligible bachelor with a suitability of 10 is: Hejlp Vmrjb!
Generation 39000 most eligible bachelor with a suitability of 11 is: Hclmp Xmtlf!
Generation 40000 most eligible bachelor with a suitability of 9 is: Femmo!Vnrlf!
Generation 41000 most eligible bachelor with a suitability of 12 is: Heilq Wprjd%
Generation 42000 most eligible bachelor with a suitability of 6 is: Hemlo Vosla!
Generation 43000 most eligible bachelor with a suitability of 10 is: Efmlp Vnqkd!
Generation 44000 most eligible bachelor with a suitability of 9 is: Kdjlo Xoslc!
Generation 45000 most eligible bachelor with a suitability of 9 is: Hgllo$Wrrld!
Generation 46000 most eligible bachelor with a suitability of 12 is: Galno Wptlb!
We have a winner from generation 46417!!
Hello World!
2

Love the "GeneticLotteryWinner"!

5

I have thought of a horrible way to do it, but it would take so long to test that I can't really write it. Basically, continually calculate Pi, converting each digit into binary, then look for the binary representation of 'hello' and then do it all again for 'world'. Then take those indexes, and generate pi again to get to that index, and print the ascii representation of that part. Stupid and inefficient? Most definitely!

They'll be in there somewhere (and here's the locations: hello and world). If you remove the space and punctuation, you'd be looking a LOT longer (exponentially longer, I imagine ;) ). It's not in the first 4 billion digits.

Capitalisation and punctuation while looking for the exact string would probably turn this into something that takes longer than your lifetime.. I don't know.

2

Love the idea sort of a digital rube goldberg machine...

2

Generate white image of a random size and flip a random number of pixels to black. If the number matches the ascii code of the correct letter, print the letter to the screen. Repeat until entire string is printed.

Entirely coded in assembly, of course.

2

http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function.html Here is a great article, on a hello world program.

2

I've read that before and it takes the cake here. I'd be willing to bet there's an old precedent for it somewhere in the history of the obfuscated coding contest.

The only thing I can think of that matches that is a huge mess of nested and/or recursive function calls and callbacks that somehow puts together the correct string in the end. I don't have the tools an old C programmer has.

1

That reminded me of this thing. The Evolution of a Programmer.

1

Use particles: Hello world

0

How about examining PI to find the machine instructions in sequence to print it

0

Create a hash table for ascii values to voltage read from a photodiode sensor, re-arrange the table based on east/west gps coordinates and select an entry based on n/s coordinates. travel to a location that has the proper light conditions and gps coordinates to print 'H' repeat until "Hello world!" is printed. Assuming this is all on a microcontroller you need to write the program itself as well as drivers for photodiode, lcd display and GPS.

I come from robotics, what is this 'UI' everyone keeps jabbering about?

0

In theory (I tried and can't get it to totally work) you should be able to generate a huffman tree in which The encodings of "Hello World!" results in the output of "Hello World!".

0

Something, Something, InterCal.

0

Wow everyone else's is so good, but I just finished my first year of CSCI at uni so this is the best I could do other than making a class for each letter.

#include <iostream> 
using namespace std; 
char H ()
{
    return 'H';
}
char e ()
{
    return 'e'; 
}
char l ()
{
    return 'l'; 
}
char o ()
{
    return 'o'; 
}
char W ()
{
    return 'W'; 
}
char r ()
{
    return 'r'; 
}
char d ()
{
    return 'd'; 
}
char ExclamationMark ()
{
    return '!'; 
}
char Space ()
{
    return ' '; 
}
int main ()
{
    cout << H(); 
    cout << e(); 
    for (int i = 0; i < 2; i++)
    {
        cout << l(); 
    }
    cout << o(); 
    cout << Space(); 
    cout << W(); 
    cout << o(); 
    cout << r(); 
    cout << l(); 
    cout << d(); 
    cout << ExclamationMark() << endl; 
    return 0; 
}
0

Run a loop with a Sleep(3000) in it. Have your computer generate a random number, sum down the digits until you reach a number under 26, and if it corresponds to the letter of the alphabet you want, reboot the computer, zero out your free disk space, calculate pi to 30303030303030 places... etc......

0

Write a JavaScript parser for a Python parser for a BF parser for a Lisp parser for a program that has a basic structure like this:

int i = 0, j = 0;
String helloWorld = "Hello, World!";
char c = helloWorld.substring(0,1);
char[13] arr;
while(1 && j < helloWorld.length()) {
  if (toChar(++i) == c)) {
    arr[j] = toCharacter(i);
    i = 0;
    j++;
  }
}
for (i = 0; i < j; i += 1000000) {
  int k = i / 1000000;
  print(arr[i]);
}
0
0

bogosort is a great place to start with stuff like this try this pseudocode alloc all unassigned disk fill it with binary garbage one bit at a time by randomly picking a bit location and then running an iterative checksum on the TB image where your iterator is 0 to free mem of the system choose a random number between 0 free mem size fill up the buffer by picking random offsets into you disk image. toss the disk image and write the mem pool to disk. compare your new disk image to hello world by asking a human if this is what they're looking for. if not recurse.

You can also take the human step out with intentionally super-slow comparisons.

0

Not the best/silliest answer, but definitely inefficient. First thing that came to mind.

list = [" ", "H", "e", "l", "o", "W", "r", "d"]
print list[1] + list[2] + list[3] + list[3] + list[4] + list[0] + list[5] + list[4] + list[6] + list[3] + list [7] 
0
grep -o "Hello world!" /dev/urandom
0
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
0
void main(){
    while(true){
        if(pigs.can_fly()){
            print("Hello World");
        }
    }
}
0

Another difficult way to do it is to use the language Malbolge.