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

version 1.26, 2001/06/12 21:07:32 version 1.33, 2001/07/27 18:15:04
Line 21  sub caparesponse_check { Line 21  sub caparesponse_check {
   my $sig_lbound=''; #done    my $sig_lbound=''; #done
   my $sig_ubound=''; #done    my $sig_ubound=''; #done
   my $ans_fmt='';    my $ans_fmt='';
   my $units='';     #done    my $unit='';     #done
   my $calc='';    my $calc='';
   my ($response,$expr)=@_;    my ($response,$expr)=@_;
     
   
   ($answer,$type,$tol,$sig,$ans_fmt,    ($answer,$type,$tol,$sig,$ans_fmt,
    $units,$calc) = eval $expr.';return $answer,$type,$tol,$sig,$ans_fmt,$units,$calc';     $unit,$calc) = eval $expr.';return ($answer,$type,$tol,$sig,$ans_fmt,$unit,$calc);';
   #type's definitons come from capaParser.h    #type's definitons come from capaParser.h
     my $message='';
     #remove leading and trailing whitespace
     if ($response=~ /^\s|\s$/) {
       $response=~ s:^\s+|\s+$::g;
       $message .="Removed ws now :$response:<br />";
     } else {
       $message .="no ws in :$response:<br />";
     }
   
   if ($type eq '' ) {    if ($type eq '' ) {
       $message .= "Didn't find a type :$type:$expr: defaulting<br />";
     if ( $answer eq ($answer *1.0)) { $type = 2;      if ( $answer eq ($answer *1.0)) { $type = 2;
     } else { $type = 3; }      } else { $type = 3; }
   } else {    } else {
Line 61  sub caparesponse_check { Line 72  sub caparesponse_check {
   my $result = &caparesponse_capa_check_answer($response,$answer,$type,    my $result = &caparesponse_capa_check_answer($response,$answer,$type,
        $tol_type,$tol,         $tol_type,$tol,
        $sig_lbound,$sig_ubound,         $sig_lbound,$sig_ubound,
        $ans_fmt,$units,$calc);         $ans_fmt,$unit,$calc);
   
   if    ($result == '1') { $result='EXACT_ANS'; }     if    ($result == '1') { $result='EXACT_ANS'; } 
   elsif ($result == '2') { $result='APPROX_ANS'; }    elsif ($result == '2') { $result='APPROX_ANS'; }
Line 77  sub caparesponse_check { Line 88  sub caparesponse_check {
   elsif ($result =='12') { $result='WANTED_NUMERIC'; }    elsif ($result =='12') { $result='WANTED_NUMERIC'; }
   else  {$result = "ERROR: Unknown Result:$result:$@:";}    else  {$result = "ERROR: Unknown Result:$result:$@:";}
   
   return "$result:<br />Error $error:<br />Answer $answer:<br />Response $response:<br />$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$units<br />";    return "$result:<br />Error $error:<br />Answer $answer:<br />Response $response:<br /> type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$units<br />$message$expr";
 }  }
   
 sub caparesponse_check_list {  sub caparesponse_check_list {
   my ($response,$expr)=@_;    my ($response,$expr)=@_;
     # do these first, because who knows what varname the instructor might have used
     # but it probably isn't $CAPARESPONSE_CHECK_LIST_answer
     my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $answer';
     my (@list) = eval $CAPARESPONSE_CHECK_LIST_answer;
   my $result='';    my $result='';
     $result.="error:$@:<br />";
     # if the eval fails just use what is in the answer exactly
     if (!defined(@list) || !defined($list[0])) {
       $result.="list zero is undefined<br />";
       $list[0]=$CAPARESPONSE_CHECK_LIST_answer;
     }
   my $aresult='';    my $aresult='';
   my $current_answer;    my $current_answer;
   my $answer = eval $expr.';return $answer';    $result.="Got response :$CAPARESPONSE_CHECK_LIST_answer:$list[0]:<br />";
   my (@list) = eval $answer;    my @responselist;
   my (@responselist)=split /,/,$response;    my $type =eval $expr.';return $answer;';
     if ($type ne '' && $#list > 0) {
       (@responselist)=split /,/,$response;
     } else {
       (@responselist)=($response);
     }
   my $unit='';    my $unit='';
   $result.="Final response :$responselist['-1']:<br />";    $result.="Initial final response :$responselist['-1']:<br />";
   if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {    if ($type eq '') {
     $responselist['-1']=$1;      #for numerical problems split off the unit
     $unit=$2;      if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
         $responselist['-1']=$1;
         $unit=$2;
       }
   }    }
   $result.="Final response :$responselist['-1']:<br />";    $result.="Final final response :$responselist['-1']:<br />";
     $result.=":$#list: answers<br />";
   $unit=~s/\s//;    $unit=~s/\s//;
   my $i=0;    my $i=0;
   my $awards='';    my $awards='';
   for ($i=0; $i<@list;$i++) {    for ($i=0; $i<@list;$i++) {
       $result.="trying answer :$list[$i]:<br />";
     if ($unit eq '') {      if ($unit eq '') {
       $aresult=&caparesponse_check($responselist[$i],        $aresult=&caparesponse_check($responselist[$i],
      $expr.';my $answer='.$list[$i].';');       $expr.';my $answer=\''.$list[$i].'\';');
     } else {      } else {
       $aresult=&caparesponse_check($responselist[$i]." $unit",        $aresult=&caparesponse_check($responselist[$i]." $unit",
    $expr.';my $answer='.$list[$i].';');     $expr.';my $answer=\''.$list[$i].'\';');
     }      }
     my ($temp)=split /:/, $aresult;      my ($temp)=split /:/, $aresult;
     $awards.="$temp,";      $awards.="$temp,";
Line 237  sub random_noncentral_f { Line 268  sub random_noncentral_f {
 }  }
   
 sub random_multivariate_normal {  sub random_multivariate_normal {
   my ($item_cnt,$seed,@mean) = @_;    my ($item_cnt,$seed,$mean,$covar) = @_;
   return "Number of deviates must be greater than 0" if $item_cnt <= 0;  
   my (@covar,@retArray);  
   my $ind = 0;  
   while ($ind<$item_cnt) {  
      push @covar, pop (@mean);  
      $ind++;  
   }  
   &random_set_seed_from_phrase($seed);    &random_set_seed_from_phrase($seed);
   @retArray=&math_random_multivariate_normal($item_cnt,@mean,@covar);    @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
   return @retArray;    return @retArray;
 }  }
   
Line 358  sub sub_string { Line 382  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 392  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 545  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.33


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