This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort#Perl | |
sub merge_sort { | |
my @x = @_; | |
return @x if @x < 2; | |
my $m = int @x / 2; | |
my @a = merge_sort(@x[0 .. $m - 1]); | |
my @b = merge_sort(@x[$m .. $#x]); | |
for (@x) { | |
$_ = | |
!@a ? shift @b : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
our $invTimes =0; | |
sub mergeSortInversions{ | |
my @x =@_; | |
return @x if (@x < 2); | |
my $mid = int (@x/2); | |
my @a = mergeSortInversions(@x[0 .. $mid - 1]); | |
my @b = mergeSortInversions(@x[$mid .. $#x]); | |
for (my $i = 0; $i < @x; $i++) { | |
if (!@a){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subroutine to implement insertion_sorting | |
#!/usr/bin/perl -w | |
sub insertion_sort { | |
my (@list) = @_; | |
foreach my $i (1 .. $#list){ | |
my $j = $i; | |
my $tmp = $list[$i]; | |
while ($j >0 && $tmp < $list[$j-1]){ | |
$list[$j] = $list[$j-1]; | |
$j --; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(1026) | |
Cond1<-rpois(n=1000,lambda=5) #虽然用泊松分布模拟数据已经被吐槽了 | |
Cond2<-rpois(n=1000,lambda=10) | |
df<-as.data.frame(cbind(cond1=Cond1,cond2=Cond2)) | |
row.names(df)=paste("g",1:1000,sep="") | |
cond1Sum<-sum(df$cond1) | |
cond2Sum<-sum(df$cond2) | |
df$cond1Other<--df$cond1+cond1Sum | |
df$cond2Other<--df$cond2+cond2Sum | |
head (df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# string of number | |
# sum number larger than 0 | |
# report start and end site | |
my $line = shift; | |
my @numbers = (split //,$line); | |
my $tag = 0; | |
my $sum = 0; |
NewerOlder