Inefficient "Hello World" Program for Octave

Here's a really hideous program for Octave that prints out "Hello, World!"...


# -*- octave -*-
# This is just about the most hideous and complicated way of printing
# "Hello World" I can think of for the moment...
# Feel free to abuse the idea.
# By Weyfour WWWWolf (Urpo Lankinen), 2001-02-04
1;

letters = toascii("Hello world");
[p, evald] = polyfit([1:11],letters,13);

if (exist("want_plotted"))
  plotx = (0:0.1:25)';
  polydata = [plotx, polyval(p,plotx)];

  chardata = [(1:11)',letters'];

  gset grid xtics ytics;
  gplot [0:13] [0:255] \
      chardata with points title "desired values", \
      polydata with lines title "fitted curve"
endif

disp(setstr(evald))

If you want to see the "heart" of the program, it's here:


letters = toascii("Hello world");
[p, evald] = polyfit([1:11],letters,13);

disp(setstr(evald))

The rest is just plotting code. =)

It takes the ASCII values of the string, interprets that as a series of number (y coordinate for each x coordinate 1, 2, 3...), finds a polynomial of 13th degree that fits the data, evaluates the polynomial for each x, converts results back to ASCII, and displays the string.

(Evaluation is done automatically by polyfit, stored to evald... Handy, that.)

I'm not a mathematician, but I know a doomed-to-fail programming approach when I see one. =)

Here's the plot that the program program produces:

[Plot]

The coefficients are:

# Created by Octave 2.0.16.92, Wed Feb 21 15:53:56 2001 <wwwwolf@nighthowl>
# name: p
# type: matrix
# rows: 14
# columns: 1
 1.99079381095492e-05
 -0.00115437249297999
 0.0287925989153794
 -0.403199605046038
 3.46465373237423
 -18.6812013367602
 61.4275957129813
 -109.846789475099
 64.1870784258645
 69.9070799001331
 -43.5100385152995
 -77.6672165963919
 -1.37969637341796
 124.474075996299

[Index] [Up] [Main] [Weyfour WWWWolf]

Last modified: Sun Jul 29 22:19:50 EEST 2001