#! perl -slw use strict; sub fact{ my $n = shift; my $f = $n; $f *= $n while --$n; return $f; } sub nCr{ my( $n, $r ) = @_; return fact( $n ) / ( fact( $r ) * fact( $n - $r ) ); } sub NwithM { my $f = 4-1; my( $L, $M ) = @_; my $T = 1; for my $m ( 1 .. $M ) { $T += nCr( $L, $m ) * $f**$m; } return $T; } print "8 with $_ mismatch(es): ", NwithM( 8, $_ ) for 1 .. 4; print "9 with $_ mismatch(es): ", NwithM( 9, $_ ) for 1 .. 4; #### C:\test\humanGenome>fuzzyDNAcalc.pl 8 with 1 mismatch(es): 25 8 with 2 mismatch(es): 277 8 with 3 mismatch(es): 1789 8 with 4 mismatch(es): 7459 9 with 1 mismatch(es): 28 9 with 2 mismatch(es): 352 9 with 3 mismatch(es): 2620 9 with 4 mismatch(es): 12826