9 billion names of God the integer

From Rosetta Code
Revision as of 13:35, 27 April 2013 by Nigel Galloway (talk | contribs) (Created page with "{{task}} This task is a variation of the short story by Arthur C. Clark. Solvers should be aware of the consequences of completing this task, see: [http://en.wikipedia.org/wik...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
9 billion names of God the integer
You are encouraged to solve this task according to the task description, using any language you may know.

This task is a variation of the short story by Arthur C. Clark. Solvers should be aware of the consequences of completing this task, see: Plot summary of The Nine Billion Names of God.

The integer 1 has 1 name 1.
The integer 2 has 2 names 1+1, and 2.
The integer 3 has 3 names 1+1+1, 2+1, and 3.
The integer 4 has 5 names 1+1+1+1, 2+1+1, 2+2, 3+1, 4.
The integer 5 has 7 names 1+1+1+1+1, 2+1+1+1, 2+2+1, 3+1+1, 3+2, 4+1, 5.

The task is to display the first 25 rows of a number triangle which begins:

                                      1
                                    1   1
                                  1   1   1 
                                1   2   1   1
                              1   2   2   1   1
                            1   3   3   2   1   1

Where row n corresponds to integer n, and each column C in row n from left to right corresponds to the number of names begining with C.

A function G(n) should return the sum of the names for that row. Demonstrate this function by displaying: G(23), G(123), G(1234), and G(12345).

Extra credit.

If your environment is able, plot G(n) against n for n=1 to n=999.