Diff for /loncom/homework/default_homework.lcpm between versions 1.26 and 1.28

version 1.26, 2001/06/12 21:07:32 version 1.28, 2001/06/14 21:29:14
Line 358  sub sub_string { Line 358  sub sub_string {
 }  }
   
 sub pow   {return $_[0] ** $_[1]; }  sub pow   {return $_[0] ** $_[1]; }
 sub ceil  {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }  sub ceil  {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? (int($_[0])+ 1) : int($_[0])); }
 sub floor {return int($_[0]);  }  sub floor  {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? int($_[0]) : (int($_[0])-1)); }
   #sub floor {return int($_[0]); }
   
 sub format {  sub format {
   my ($value,$fmt)=@_;    my ($value,$fmt)=@_;
Line 367  sub format { Line 368  sub format {
 }  }
   
 sub map {  sub map {
   my $num = $#_/2;      my ($phrase,$dest,$source)=@_;
   my $i;      my @seed = &random_seed_from_phrase($phrase);
   my @used;      &random_set_seed(@seed);
   my @permutation;      my $destct = scalar(@$dest);
   for ($i=0; $i < $num;) {      if (!$source) {
     $rand = &random(1,$num,1);   my @output;
     if ( $used[$rand] == '0' ) {   my @idx = &math_random_permuted_index($destct);
       $i++;   my $ctr = 0;
       $used[$rand]='1';   while ($ctr < $destct) {
       $permutation[$i]=$rand;      $output[$ctr] = $$dest[$idx[$ctr]];
       $ctr++;
    }
    return @output;
       } else {
    my $num = scalar(@$source);
    my @idx = &math_random_permuted_index($num);
    my $ctr = 0;
    my $tot = $num;
    $tot = $destct if $destct < $num;
    if (ref($$dest[0])) {
       while ($ctr < $tot) {
    ${$$dest[$ctr]} = $$source[$idx[$ctr]];
           $ctr++;
               }
           } else {
       while ($ctr < $tot) {
    $$dest[$ctr] = $$source[$idx[$ctr]];
    $ctr++;
       }
    }
       }
   }
   
   sub rmap {
       my ($phrase,$dest,$source)=@_;
       my @seed = &random_seed_from_phrase($phrase);
       &random_set_seed(@seed);
       my $destct = scalar(@$dest);
       if (!$source) {
    my @idx = &math_random_permuted_index($destct);
    my $ctr = 0;
    my @r_idx;
    while ($ctr < $destct) {
       $r_idx[$idx[$ctr]] = $ctr;
       $ctr++;
    }
    my @output;
    $ctr = 0;
    while ($ctr < $destct) {
       $output[$ctr] = $$dest[$r_idx[$ctr]];
       $ctr++;
    }
    return @output;
       } else {
    my $num = scalar(@$source);
    my @idx = &math_random_permuted_index($num);
    my $ctr = 0;
    my $tot = $num;
    $tot = $destct if $destct < $num;
    my @r_idx;
    while ($ctr < $tot) {
       $r_idx[$idx[$ctr]] = $ctr;
       $ctr++;
    }
    $ctr = 0;
    if (ref($$dest[0])) {
       while ($ctr < $tot) {
    ${$$dest[$ctr]} = $$source[$r_idx[$ctr]];
           $ctr++;
               }
           } else {
       while ($ctr < $tot) {
    $$dest[$ctr] = $$source[$r_idx[$ctr]];
    $ctr++;
       }
    }
     }      }
   }  
   for ( $i=1 ; $i<$num+1 ; $i++ ) {  
     ${$_[$permutation[$i]]}=$_[$i+$num]  
   }  
 }  }
   
 sub capa_id { return }  sub capa_id { return }
Line 458  sub array_moments { Line 521  sub array_moments {
   $output[0]=$N;    $output[0]=$N;
   if ($N <= 1) {    if ($N <= 1) {
     $output[1]=$input[0];      $output[1]=$input[0];
     $output[1] = "Input array not defined" if ($N == 0);      $output[1]="Input array not defined" if ($N == 0);
     $output[2]="variance undefined for N<=1";      $output[2]="variance undefined for N<=1";
     $output[3]="skewness undefined for N<=1";      $output[3]="skewness undefined for N<=1";
     $output[4]="kurtosis undefined for N<=1";      $output[4]="kurtosis undefined for N<=1";

Removed from v.1.26  
changed lines
  Added in v.1.28


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>