Noel Constant did it without genius and without spies.

His system was so idiotically simple that some people can't understand it, no matter how often is is explained. The people who can't understand it are people who have to believe, for their own peace of mind, that tremendous wealth can be produced only by thremendous cleverness.

This was Noel Constant's system:

He took the Gideon Bible that was in his room, and he started with the first sentence in Genesis.

The first sentence in Genesis, as some people may know, is: "In the beginning God created the heaven and the earth." Noel Constant wrote the sentence in capital letters, put periods between the letters, divided the letters into pairs, rendering the sentence as follows: "I.N., T.H., E.B., E.G., I.N. N.I., N.G., G.O., D.C., R.E., A.T., E.D., T.H., E.H., E.A., V.E., N.A., N.D., T.H., E.E., A.R., T.H."

And then he looked for corporations with those initials, and bought shares in them. His rule at the beginning was that he would own shares in only one corporation at a time, would invest his whole nest-egg in it, and would sell the instant the value of his shares had doubled.

–Kurt Vonnegut, Sirens of Titan

The investor Noel Constant is getting tired of using his system manually. He needs the power of computers to pick the companies to invest in.

Noel Constant is willing to learn how to execute a command line script or a function in the language of your choice. He will provide a single string of input. He won't bother removing any whitespace, punctuation, or change case for the input string. He doesn't like that kind of work.

In return he expects to see a list of companies he can invest in, produced according to his idiotically simple system. He wants to see each company on its own line with the initials in brackets. If there isn't a company with the initials needed he wants to see three dots (...).

International Nitrate (IN)
Throwbridge Helicopter (TH)
Electra Bakeries (EB)
Eternity Granite (EG)
... (IN)

His company, Magnum Opus, provided a list of company names and their initials for you: https://gist.github.com/britishtea/2f57710a114cfd79616d.

As you may have guessed, Noel Constant doesn't like reading, so he'll want the shortest program or function possible.


To clarify, the input to the function or program is string (with punctuation and whitespace, case unaltered). An example of such a string is "In the beginning God created the heaven and the earth." The list of company names and initials is not an input source, it should be read some other way (from disk for example).

The output is a list in the above format. I forgot to mention in the original challenge that the order the company names appear in shouldn't be altered, i.e. if you read the initials in the output from top to bottom it renders the original input (stripped of punctuation and whitespace).

This is no longer a requirement, but if your function or program satisfies this condition, there is a 0.9 bonus (# characters * 0.9) in it for you.

  • \$\begingroup\$ Do we have to consider only the first sentence of the Gideon Bible ? \$\endgroup\$
    – Optimizer
    Commented Feb 22, 2015 at 14:25
  • 1
    \$\begingroup\$ Do we have to hardcode the companies' names? If not you should specify that the program has to either 1(Download the names from your github page. 2(Assume the names are in a nearby file with such and such name. \$\endgroup\$ Commented Feb 22, 2015 at 14:58
  • \$\begingroup\$ @Optimizer In the book, Noel Constant gets a lot further than the first sentence, therefore the program or function should be able to give output company names for (at least) the full bible. I think this invalidates your current solution, I'm sorry about that. \$\endgroup\$
    – britishtea
    Commented Feb 22, 2015 at 17:27
  • \$\begingroup\$ Then you should make your question self sufficient and proper. Right now its not clear at all. \$\endgroup\$
    – Optimizer
    Commented Feb 22, 2015 at 17:29
  • \$\begingroup\$ And do you just assume that we put all of the bible in our code ? Is this even kolmogorov-complexity ? \$\endgroup\$
    – Optimizer
    Commented Feb 22, 2015 at 17:30

3 Answers 3


Unix tools, 111 * 0.9

(Not counting downloading and parsing the Bible)

$ curl -s https://www.gutenberg.org/cache/epub/10/pg10.txt|grep '^[0-9]:'|cut -d' ' -f2-|sed 's/[^a-z]//gi'|tr -d \\n|fold -w2|xargs -n1 sh -c 'grep -i ^$0 symbols.txt'|sed -r 's/(..) (.*)/\2 \(\1\)/'
Zylog Systems Ltd (IN)
Zynga Inc - Cl A (TH)
Zwahlen & Mayr Sa-br (EB)
Surpapelcorp Sa (EG)
Zylog Systems Ltd (IN)
Nisource Inc. (NI)
Novagold Resources Inc. (NG)
Zealand Pharma A/s (DC)
Everest Re Group, Ltd. (RE)
Atlantic Power Corporation (AT)

I am not a professional investor but I think that the more times a company is mentioned in the Bible the more successful it will be, so I would invest in these:

  10027 th - Zynga Inc - Cl A
   9026 he - Hawaiian Electric Industries, Inc.
   4748 nd - *
   3681 an - Autonation, Inc.
   3150 ha - Hawaiian Holdings, Inc.
   3109 er - *
   2925 re - Everest Re Group, Ltd.
   2829 in - Zylog Systems Ltd
   2665 nt - *
   2519 es - *

(Future founders, consider creating a company with stock symbols I marked with *, they are not yet taken)


Mathematica, 186


The output looks like this:output

This actually doesn't quite work, but I think it's pretty neat that Mathematica can do this. For some reason, though, it has trouble finding its own stocks. For example, it finds "NYSE:IN" but then says it's not a known entity:

weird bug?

Still, that's about as far as I think I'll go with it, unless someone knows why it's confused about the NYSE stocks. Feel free to expand or golf.


Python 3, 174 * 0.9 = 156.6 bytes

Rereading the rules, the company names can be in a file. This works with a file named w (No file extension) in the same format as the github.gist in the question. Takes input via stdin and outputs in the format company name (SC) or ... (SC) where SC is the stock code.

a={l[:2]:l[3:-1]for l in open("w").readlines()}
s="".join(c.upper()for c in input()if c.isalpha())
for i in(s[c:c+2]for c in range(0,len(s),2)):print(a.get(i,"..."),"(%s)"%i)

Old version, 248 241 238 * 0.9 = 214.2 bytes

This is the same as above, except it gets the stock codes from the internet.

from urllib.request import*
a={l[:2]:l[3:]for l in urlopen("http://goo.gl/lZVoIE").read().decode().split("\n")}
s="".join(c.upper()for c in input()if c.isalpha())
for i in(s[c:c+2]for c in range(0,len(s),2)):print(a.get(i,"..."),"(%s)"%i)

The goo.gl link is the link to the gist shortened.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.