74
20
The 9 Billion Names of God is a short story by Arthur C. Clarke. It's about a group of Tibetan monks whose order is devoted to writing down all the possible names of God, written in their own alphabet. Essentially, they are devoted to writing every possible permutation of their alphabet, restricted by a few rules. In the story, the monastery hires some engineers to write a program to do all the work for them. Your goal is to write that program.
Rules:
The monk's alphabet uses 13 characters (according to my estimations). You may use
ABCDEFGHIJKLM
or some other set of 13 characters.The minimum length of a possible name is 1 character. The maximum length is 9 characters.
No character may repeat more than 3 times in succession.
AAABA
is a valid name, butAAAAB
is not.Your program should print out (to a file) every possible name in sequence from
A
toMMMLMMMLM
, separated by any character not in the alphabet (newlines, semi-colons, whatever).This is code-golf, and you can use any language. The shortest solution by June 1st 2014 wins.
Edit: The names should start with A
and end with MMMLMMMLM
, progressing through all the billions of names sequentially. But the particular sequence is up to you. You can print out all the 1-letter names first, then all the 2-letter names, etc. Or you can print all the names starting with A
, then all the ones starting with B
, or some other pattern. But a human should be able to read through the file and confirm they are all there and in whatever logical order you choose, assuming they have the time.
1
This verifies that the number of names in the present problem is indeed 11,459,252,883 (as found in edc65's C program). Implementing Ross Millikan's solution at MathSE generates the following polynomial formula for the number of names with length <= 9, for variable alphabet size k:
– r.e.s. – 2014-06-06T04:01:37.243f(k) = k^9 + k^8 + k^7 - 5*k^6 + k^5 + k^4 + 4*k^3 - 2*k^2 + k
. Sage implementation: https://goo.gl/0srwhq29Are you trying to end the universe, sir? – Boluc Papuccuoglu – 2014-06-02T11:21:47.783
8Link to the story, for anyone interested. – ThatOneGuy – 2014-06-02T19:40:00.960
"The 11,459,252,883 Names of God"? It would be cool if the number of names were independently verified. It's 11,459,252,883 according to @edc65 's C answer, but the other answers appear too slow for this. (Except by actually enumerating the names, I don't know how to obtain the number.) – r.e.s. – 2014-06-03T13:00:23.197
There's definitely a way to calculate it. Of course, in the story, the monks had more rules, lowering the number of possibilities. – CSturgess – 2014-06-03T19:57:10.007
@CSturgess: no, in the story the monks had the limit of 3 letters repeated and no more. Where Clarke wrote the story, maybe 40 years ago, he could just estimate the number of possibilities (short of calling IBM and renting some months of machine power) – edc65 – 2014-06-04T09:15:11.867
1953 if fact ... – edc65 – 2014-06-04T09:22:18.077
@edc65 No, they had more rules than that. They just said that one as an example. They never elaborated on the others. – CSturgess – 2014-06-04T14:34:37.237
@CSturgess - Certainly there's a combinatorial-style proof of the correct number of names defined by your rule-set, but we don't have such a proof at hand. (It might be a good question for Math SE.) The next best thing would be independent brute-force computations to verify that it's 11,459,252,883.
– r.e.s. – 2014-06-04T21:17:18.693@CSturgess - sorry, going by memory, and I read that story 30 years ago. I can't believe that in the last 60 years nobody tried to verify the number. – edc65 – 2014-06-05T18:22:06.653
1
Here it is! http://math.stackexchange.com/a/34292
– edc65 – 2014-06-05T18:34:59.923Wait a minute, a british billion is different from an American billion? That changes everything. That would mean a 28 character alphabet instead of 13. I wonder if that would change the scope of the problem at all? – CSturgess – 2014-06-05T19:20:53.490
@edc65 - See my "answer" below, which uses a Sage implementation to generate the polynomial formula for the number of names as a function of variable alphabet size.
– r.e.s. – 2014-06-06T04:06:25.653@edc65 - A better answer from that question is this one, I think. It points out:
– Bobson – 2014-06-27T15:54:05.937Everyone here seems to think that (in the story) the two hired engineers printed out a 9 billion word list. People here are trying to calculate which n-letter alphabet system gives 9 billion words. The list that the engineers printed was much longer than 9 billion.
The 11,459,252,883 possibilities just included the 9 billion names.I'd recommend against generating the list. According to my calculations the table is around
107GB
(ignoring the 3 character repetition rule, including a newline characters after each name). – recursion.ninja – 2014-06-27T16:33:15.460@awashburn 113,637,155,697 including the 3 characters repetion rule, newlines and no padding. I actually built the file. [http://codegolf.stackexchange.com/a/28876/21348] – edc65 – 2014-06-27T16:37:03.867
3@edc65 So
105.8GB
all said and done! I'm glad the stars didn't go out... or maybe you have to print the list for that to happen...? – recursion.ninja – 2014-06-27T16:53:30.827