Thanksgiving code

November 28th, 2008 in Coding, Rants - 1 Comment

I needed a script to loop through the letters of the alphabet and put this in an array: a-z, aa-zz, aaa-zzz, aaaa-zzzz, etc. Through a very rough approach, I’ve satisfied conditions 1-3, but not anything after (source code below).

[syntax,alg.phps,php]

So, all my problems are from the function get_items(). Basically, I don’t want to loop through the $used array to find out what values have a particular length. So based on my analysis, we have a theoretical function f(x, y) which gives the following when run:

f(1, 26) = 0	
f(2, 26) = 26	
f(3, 26) = 702
f(4, 26) = 18278

ie, the set {0, 26, 702, 18278, …}

f(2, 26) - f(1, 26) = 26      = 26 ^ 1
f(3, 26) - f(2, 26) = 676     = 26 ^ 2
f(4, 26) - f(3, 26) = 17576   = 26 ^ 3

Okay, now I see it clearly. Here goes:

[syntax,alg2.phps,php]

So, why do I need this? I have to do a test on an PHP-Ajax newsletter WordPress plugin. On a site I’m working on, we need to send emails to 70000 subscribers, and the current plugin loops through all the records in the database in one go. Of course the max execution time passes before then. I needed to generate a test database of 70000 emails @localhost.com to help me test while I rewrite the plugin.

Well, onto the actual rewrite.

1 Comment so far

  • April 22, 2009 at 6:09 am

    Great work.