Jump to content

Trian Gular Ramblings

  • entries
    47
  • comments
    213
  • views
    26,882

6 billion names


le717

1,231 views

 Share

That is how many alternate JimbobJeffers mathematically exist. :P

The evening of 13 November, Yajmo was joking how should have some code randomize the spelling of his name, with a new spelling appearing upon every page load. Since such a task would be best accomplished client-side using JavaScript, I wrote up some code that did just that, available at gist.github.com/le717/4c2188ca814f56575a26.

The above code loops through each character of the entered name, randomly picks a letter and concatenates it to the existing string. It also ensures it does not use the same letter twice unless it already exists. I have checked each output for my name, "le717", and every single one only has two sevens in it, never three. The trick is not checking for the character used, but the index chosen. If the index has been used before, then it will choose a different one. Since the sevens have two different indexes (3 and 5), they are both included and a third is never added. Cyrem liked the idea, so he and I worked together to get it implemented.

The next morning, most everybody here had already seen the name scrambling and either loved it or hated it For fun, I decided to run it on a few names on my end and see the results. JimbobJeffers' name in particular produced some really scrambled names. He wondered if it were possible for the code to generate a name containing "Bobjim". Since I knew it would be a trivial bit of code to write, I said I would try it.

I started by calculating the possible permutations of his name using factorials. His name is 13 characters long, producing a possible 6,227,020,800 (six billion, two hundred twenty-seven million, twenty thousand, eight hundred) combinations. :0 I then found some JavaScript to calculate that number for me (I did not want to type it in manually) (although I should know how to write code to calculate the factorial already xD ). Because he wanted to see if any of them contained "Bobjim", I made it store any names that matched in an object along with its index. Finally, once it had generated and checked all 6 billion names, it would either display the object or report such a combination does not exist, depending on the outcome. After some small-scale tests to ensure the code worked, making his name and check all lowercase to remove possible misses because of case differences, and a false start in order to implement a 100-increment progress counter, around 10:22 AM I let the code loose, powered by none other than the awesome Node.js.

The progress of this code was amazing. While I failed to check the processing speed after I started it, I later started calculating the speed (names processed at the 10 second, 1 minute, and 1 hour levels), current number of names processed, and projected time until completion. A mere 10 minutes after starting, an amazing 64 million names had already been processed. That is a rate of 6.4 million a minute, roughly 106 thousand a second! 40 minutes after starting, when I formally starting performing logs, I clocked it at 6 million names a minute, or 36 million names an hour. Within an hour after running, 419 million names had been run, with a projected time until all 6 billion were processed looking at 15 hours, or 2 AM the next morning. Yikes. I knew it would take a long time, but not that long. :P

After that, it slowed down drastically. Two hours after starting, it ran at only 54,000 names a minute, or 3,240,000 names an hour, an 11-fold decrease. Within that time, a staggering 419,159,500 names had been generated.

Finally, nearly 4 and a half hours and a CPU priority increase to High (in an attempt to make it run faster), it chugged along at 13,000 names an hour, with a projected 49 years remaining for it to calculate the remaining 5,807,484,800 names. Yea, that is totally happening. :P

Finally, I killed the code, having processed 419,750,000 names in a few minutes shy of 5 hours running.

419750000-names.png

So, what did I learn from this experiment?

  1. JavaScript, like any other language, slows down the longer it runs.
  2. 6 billion is a lot larger than you might think. :P
  3. I brushed up on my factorial and permutation knowledge.
  4. I had fun doing it.
  5. Does there exist an alternate JimbobJeffers that goes under the name "Bobjim"? The world may never know.

http://www.youtube.com/watch?v=O6rHeD5x2tI

In case you wanted to try this experiment yourself, I have posted the exact code I used in a GitHub Gist. This was not the most scientific experiment ever, so there may be some issues with it, but that's not the point. :P

Well that was fun. Perhaps I should try to calculate the meaning of life next, as Ayliffe suggested. After all, if I can get it to retain the speed it starts out with constantly, it should only take a month. :P

 Share

5 Comments


Recommended Comments

ProfessorBrickkeeper

Posted

"Perhaps I should try to calculate the meaning of life next, as Ayliffe suggested."

42

24

Your work's done here. :)

  • Like 3
Link to comment

Looking at that code... you're scrambling the name x amount of times, but where is the duplicate check?

Link to comment

Looking at that code... you're scrambling the name x amount of times, but where is the duplicate check?

 

I thought about a duplicate check. After all, my name is 5 characters for a factorial of 120, but there are only 51 unique combinations. I wasn't sure how to go about figuring out why there is such a large difference (when calculating the factorial is supposed to give the number of permutations (combinations) of the word or how to account for that in code (the difference, not a duplicate check), so I left it out and just used the mathematical value. I'm having it calculate the unique names right now.

Link to comment

It would seem the JavaScript embedded at the end of pages served here was probably was run through a minifier...

The variables are renamed to single letters.

Link to comment

It would seem the JavaScript embedded at the end of pages served here was probably was run through a minifier...

The variables are renamed to single letters.

 

It was, but I have checked it and it is my code that I linked. ;)

Link to comment

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.