Programming and Scripting :: C question
if (($max ge 3) && ($result =~ /$c{3}$/)) {
should have been (I think)
if (($max >= 3) && ($result =~ /$c{3,}$/)) {
[EDIT: classic mistake confusing string and numeric comparisons ]
If that didn't work would have applied a regex somewhere like:
=~ /(.)\1\1/
which would match any string containing 3 or more identical adjacent chars.
You might notice the similarity to sed syntax. Perl regex's are much easier and more intuitive and you do a lot less escaping of backslashes and brackets and other hassles.
Is the new algorithm guaranteed to try every combination?
AKAIK - it's taken from the Algorithm::Permute man page, basically just put in a loop to do all string lengths between 1 and the number of elements in @set.
There's also benchmarks on the man page comparing speeds to other implementations.
There may possibly be a faster way of using the module via the callback interface but I'll have to think and maybe post somewhere about that. [ EDIT I doubt it . The callback thing won't take a perm length argument, and the man page warns against trying to change the array mid execution. ]
EDIT: I've updated the above to allow for setting desired string length ranges.
Yesterday I had a crack at a version using threads, but there were segfaults - I think Algorithm::Permute is probably not thread-safe. Googling reveals this is likely since (a) any module that does not explicitly state it is thread-safe should be assumed not to be, and (b) it's written in XS code and XS code modules are less likely to be thread-safe.
Anyway I have some other improvements in mind for speed increases.
The smaller ones have run through - aka all under 7 chars. That proved my pass isn't 7 chars or less. Oh well.
Then I did a quick reschedule - new dial is:
8-9, 10-11, 12-13, 14-15, 16-17, 18-19, 20-21, 22-23; that is, one process goes through two lengths, instead of one going from 8 to 23. These are all running on the main lappy - load averages have floated above 15 for some time now
I haven't yet applied the fix for adjacent chars, maybe I should have? Haven't had time.
Next Page...
original here.