Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Analysing a (binary) string.

by hdb (Prior)
on Jun 28, 2013 at 12:23 UTC ( #1041239=note: print w/replies, xml ) Need Help??


in reply to Re: Analysing a (binary) string.
in thread Analysing a (binary) string. (Solved)

I cannot see where you get N factorial from. To me it seems what you describe is N^2. This is also what I get from the brute force method below:

use strict; use warnings; use Time::HiRes qw/time/; sub find_best_offset { my $strref = shift; my $n = length $$strref; my $mindiff = $n; my $best_offset = -1; for( my $i=1; $i<=$n/2; $i++ ) { # shift/rotate string and compare to original my $diff = $$strref ^ substr( $$strref, -$i ).substr( $$strref +, 0, -$i ); # number of differing characters between shifted string and or +iginal my $ndiff = $diff =~ tr/\0//c; # test for and keep optimal solution if( $ndiff < $mindiff ) { return $i unless $ndiff; # best case! $mindiff = $ndiff; $best_offset = $i; } } return $best_offset; } for ( 9, 99, 999, 9999, 99999 ) { my $t = time; my $str1 = "01234567890123456789".("01234567890123456x89" x $_); print find_best_offset( \$str1 ); print "\t$_\t",time-$t,"\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041239]
help
Chatterbox?
[Discipulus]: italian doc says to modify somehow the initial SVG before using it with D3.js
[Discipulus]: LanX the fact is that my js ability is even poorer than my Perl one..
[LanX]: oh its negative? ;P
[Discipulus]: my warmest comprehension karlgoethebier ;=(
[Discipulus]: yes LanX.. is so good to be appreciated (I fortunately have a big self estimation that compensate)
[LanX]: you can manipulate a html tree by addressing and replacing so called document objects (DOM) and from my experience the same methods can be used with any XML, though I didn't test all browsers yet
LanX just joking, playing "ego judo"
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2017-03-23 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.