... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2009-05-30

"Hello World" Using Long Integers

I enjoyed the Python program exhibited on Poromenos's blog that prints out "Hello World" using curve-fitting. I wanted to play copycat in Java, but wanted to use an exact solution to the equation instead of rounding off. The result is exhibited below.

public class HelloWorld {

    public static void main(String arguments[]) {
        for (int i = 0; i < 13; ++i) {
            System.out.print(f(i));
        }
        System.out.println();
    }
    
    private static char f(int x) {
        return (char)(
                ( 49816166400L
                + 1114492383360L * x
                - 3487560668352L * x * x
                + 4521056833128L * x * x * x
                - 3246967654612L * x * x * x * x
                + 1447974643830L * x * x * x * x * x
                - 423730694651L * x * x * x * x * x * x
                + 83502380214L * x * x * x * x * x * x * x
                - 11141107791L * x * x * x * x * x * x * x * x
                + 991358610L * x * x * x * x * x * x * x * x * x
                - 56296097L * x * x * x * x * x * x * x * x * x * x
                + 1844058L * x * x * x * x * x * x * x * x * x * x * x
                - 26497L * x * x * x * x * x * x * x * x * x * x * x * x
                ) / 479001600L
            );
    }
}

In case you are wondering, I captured a transcript of the Mathematica session where I generated that program (PDF).

Blog Archive