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

version 1.26, 2001/06/12 21:07:32 version 1.27, 2001/06/13 20:00:07
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 $num = scalar(@$source);
   for ($i=0; $i < $num;) {      my $destct = scalar(@$dest);
     $rand = &random(1,$num,1);  #    print "Warning - Number of source elements and destination elements does not match.\n" if $destct != $num;
     if ( $used[$rand] == '0' ) {      my @idx = &math_random_permuted_index($num);
       $i++;      my $ctr = 0;
       $used[$rand]='1';      my $tot = $num;
       $permutation[$i]=$rand;      $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 $num = scalar(@$source);
       my $destct = scalar(@$dest);
   #    print "Warning - Number of source elements and destination elements does not match.\n" if $destct != $num;
       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 }

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


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