Printing "Hello world!" using curve fitting techniques (or: The "Hello world!" function)

Well, I have a computer architecture exam in six hours and can't be bothered, so I figured I would realize a lifelong dream of mine, and make a program that prints "Hello world!" using curve fitting techniques. Enlisting the help of a good friend with numerous mathematical papers under his belt (ostensibly because he could not afford a tighter belt), MATLAB and a longing for procrastination, we embarked on this perilous journey. After many, many hours of fitting and discarding data, I can finally present to you my masterpiece.

This function returns the ascii ordinal for each of the letters of "Hello, world!" at each integer position (0, 1, 2, 3 etc). I call it... The "Hello world!" function! A simple Python script shows it in all its glory:

from math import *

def f(x):
    return int(round(96.75 + -21.98*cos(x*1.118) + 13.29*sin(x*1.118) + -8.387*cos(2*x*1.118)\
               + 17.94*sin(2*x*1.118) + 1.265*cos(3*x*1.118) + 16.58*sin(3*x*1.118)\
               + 3.988*cos(4*x*1.118) + 8.463*sin(4*x*1.118) + 0.3583*cos(5*x*1.118)\
               + 5.878*sin(5*x*1.118)))

print "".join([chr(f(x)) for x in range(12)])

and that's it! Just save this as hello.py and run it, and the phrase "Hello world!" will be prominently etched upon your screen for future generations to enjoy. I, along with my friend and colleague, reserve all rights to this code, which will be coming soon to a scientific conference near you. I will also be waiting for my Nobel prize nomination.

In case you are wondering, here are the plot points and the fitted function:

Thank you all for your support. T-shirts of the function are available at http://www.cafepress.com/poromenos, right now there's only the classic MATLAB design but I soon hope to be making better ones. Oh, also, if you are a bigshot employer, you can hire me to fit other functions for you, or perhaps do some Python/Django/whatever development. Email's under "About me".

Brilliant

Thanks for this. It made my day.

Let me know when you have the plot for sale in t-shirt format.

Submitted by Jason Striegel (not verified) on Thu, 03/04/2008 - 05:00.
DSP Hello World

Kind of Fourier series applied to Hello World? Very nice. It can be a very useful example to show to someone that any periodic function can be a sum of sines and cosines. Make my d... morning (I hope I will find something for the afternoon). Thanks.

Submitted by Emmanuel Rio (not verified) on Thu, 03/04/2008 - 08:11.
Re: DSP

Indeed, that's exactly it. There were some series that were fluctuating wildly and hit the spots pretty much by accident, but this one fits beautifully with a 0.01 margin of error or something (which obviously goes away when rounding).
---
Vidi, Vici, Veni.

Submitted by Poromenos on Thu, 03/04/2008 - 10:25.
The genius of it makes my

The genius of it makes my eyes bleed.
I'll be forwarding the bill for my optometrist fees shortly.

Well done sir.

Submitted by Mr L (not verified) on Thu, 03/04/2008 - 11:13.
Fees

Pay nothing!

Submitted by Moriarty (not verified) on Fri, 16/05/2008 - 21:38.
Better equation

Good idea...but I've seen it elsewhere before :|

A method that will give you a better-looking polynomial (equation-wise) can be obtained via Lagrange Interpolation:

http://mathworld.wolfram.com/LagrangeInterpolatingPolynomial.html

Of course, the resulting graph may look nasty just like almost all other high order polynomials (probably will look like a bunch of vertical lines) but the equation itself will consist solely of integers! :)

Submitted by wolfier (not verified) on Thu, 03/04/2008 - 20:04.
Re: Equation

I tried that, it did look like a bunch of vertical lines (which might introduce unacceptable floating-point errors, since it varies so wildly), but I am rather partial to this one... It's so pretty!
---
Vidi, Vici, Veni.

Submitted by Poromenos on Fri, 04/04/2008 - 10:53.
Spam-analysis

Have you already tried to use this algorythm for spam-visualisation?
Could be smth like hier: http://www.wired.com/special_multimedia/2008/ff_dataart_1603

Submitted by sohin@drupal.org on Wed, 09/04/2008 - 17:31.
Ruddy Awesome

Amazing. I'm wondering how many hours (out of the six you had) it took you.

Submitted by Scatman Dave (not verified) on Fri, 11/04/2008 - 20:29.
Re: Awesome

About twenty minutes or so (but don't tell anyone)!
---
Vidi, Vici, Veni.

Submitted by Poromenos on Fri, 11/04/2008 - 21:07.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Google ads

(You can disable these if you log in)