Diff for /loncom/homework/default_homework.lcpm between versions 1.97 and 1.104

version 1.97, 2005/03/31 14:43:13 version 1.104, 2005/11/16 22:18:22
Line 89  sub caparesponse_check { Line 89  sub caparesponse_check {
     } else {      } else {
  $message .="no ws in :$response:\n";   $message .="no ws in :$response:\n";
     }      }
     if ($type eq 'cs' || $type eq 'ci' || $type eq 'mc') {      &LONCAPA_INTERNAL_DEBUG(" type is $type ");
       if ($type eq 'cs' || $type eq 'ci') {
  #for string answers make surec all places spaces occur, there is    #for string answers make surec all places spaces occur, there is 
         #really only 1 space, in both the answer and the response          #really only 1 space, in both the answer and the response
  $answer=~s/ +/ /g;   $answer=~s/ +/ /g;
  $response=~s/ +/ /g;   $response=~s/ +/ /g;
       } elsif ($type eq 'mc') {
    $answer=~s/[\s,]//g;
    $response=~s/[\s,]//g;
     }      }
     if ($type eq 'float' && $unit=~/\$/) {      if ($type eq 'float' && $unit=~/\$/) {
  if ($response!~/^\$/)  { return "NO_UNIT: Missing \$ "; }   if ($response!~/^\$/)  { return "NO_UNIT: Missing \$ "; }
Line 189  sub caparesponse_check_list { Line 193  sub caparesponse_check_list {
     my $type = $LONCAPA::CAPAresponse_args{'type'};      my $type = $LONCAPA::CAPAresponse_args{'type'};
     $result.="Got type :$type:\n";      $result.="Got type :$type:\n";
     if ($type ne '' && $#list > 0) {      if ($type ne '' && $#list > 0) {
  (@responselist)=split /,/,$response;   (@responselist)=split(/,/,$response);
     } else {      } else {
  (@responselist)=($response);   (@responselist)=($response);
     }      }
Line 213  sub caparesponse_check_list { Line 217  sub caparesponse_check_list {
  $result.="trying answer :$list[$i]:\n";   $result.="trying answer :$list[$i]:\n";
  my $thisanswer=$list[$i];   my $thisanswer=$list[$i];
  $result.="trying answer :$thisanswer:\n";   $result.="trying answer :$thisanswer:\n";
  if ($unit eq '') {   if (defined($list[$i])) { 
     ($aresult,$msg)=&caparesponse_check($thisanswer,$responselist[$i]);      if ($unit eq '') {
    ($aresult,$msg)=&caparesponse_check($thisanswer,
       $responselist[$i]);
       } else {
    ($aresult,$msg)=&caparesponse_check($thisanswer,
       $responselist[$i]." $unit");
       }
  } else {   } else {
     ($aresult,$msg)=&caparesponse_check($thisanswer,      $aresult='ERROR';
  $responselist[$i]." $unit");  
  }   }
  my ($temp)=split /:/, $aresult;   my ($temp)=split(/:/, $aresult);
  $awards.="$temp,";   $awards.="$temp,";
  $result.=$aresult;   $result.=$aresult;
  push(@msgs,$msg);   push(@msgs,$msg);
     }      }
     chop $awards;      chop($awards);
     return ("$awards:\n$result",@msgs);      return ("$awards:\n$result",@msgs);
 }  }
   
Line 447  sub random_negative_binomial { Line 456  sub random_negative_binomial {
     return @retArray;      return @retArray;
 }  }
   
 sub abs { abs(shift) }  sub abs { CORE::abs(shift) }
 sub sin { sin(shift) }  sub sin { CORE::sin(shift) }
 sub cos { cos(shift) }  sub cos { CORE::cos(shift) }
 sub exp { exp(shift) }  sub exp { CORE::exp(shift) }
 sub int { int(shift) }  sub int { CORE::int(shift) }
 sub log { log(shift) }  sub log { CORE::log(shift) }
 sub atan2 { atan2($_[0],$_[1]) }  sub atan2 { CORE::atan2($_[0],$_[1]) }
 sub sqrt { sqrt(shift) }  sub sqrt { CORE::sqrt(shift) }
   
 sub tan  { CORE::sin($_[0]) / CORE::cos($_[0]) }  sub tan  { CORE::sin($_[0]) / CORE::cos($_[0]) }
 #sub atan { atan2($_[0], 1); }  #sub atan { atan2($_[0], 1); }
Line 518  sub format { Line 527  sub format {
     #if ($options =~ /\$/) { $dollamode=1; }      #if ($options =~ /\$/) { $dollamode=1; }
     #if ($options =~ /,/)  { $commamode=1; }      #if ($options =~ /,/)  { $commamode=1; }
     if ($options =~ /\./) { $alwaysperiod=1; }      if ($options =~ /\./) { $alwaysperiod=1; }
       my $result;
     if ($fmt=~/s$/i) {      if ($fmt=~/s$/i) {
  $result=&format_significant_figures($value,$fmt);   $result=&format_significant_figures($value,$fmt);
     } else {      } else {
  $fmt=~s/e/E/g;   $fmt=~s/e/E/g;
  my $result=sprintf('%.'.$fmt,$value);   $result=sprintf('%.'.$fmt,$value);
  if ($alwaysperiod && $fmt eq '0f') { $result .='.'; }   if ($alwaysperiod && $fmt eq '0f') { $result .='.'; }
  $result=~s/(E[+-]*)0/$1/;   $result=~s/(E[+-]*)0/$1/;
     }      }
Line 632  sub prettyprint { Line 642  sub prettyprint {
 sub commaformat {  sub commaformat {
     my ($number,$target) = @_;      my ($number,$target) = @_;
     if ($number =~ /\./) {      if ($number =~ /\./) {
  while ($number =~ /([^\.,]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) {   while ($number =~ /([^0-9]*)([0-9]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) {
     $number = $1.','.$2.$3;      $number = $1.$2.','.$3.$4;
  }   }
     } else {      } else {
  while ($number =~ /([^,]+)([^,][^,][^,])([,0-9]*)$/) {   while ($number =~ /^([^0-9]*)([0-9]+)([^,][^,][^,])([,0-9]*)$/) {
     $number = $1.','.$2.$3;      $number = $1.$2.','.$3.$4;
  }   }
     }      }
     return $number;      return $number;
Line 680  sub format_significant_figures { Line 690  sub format_significant_figures {
     my $numSig = $xint*10**($x10-$sig+$power);      my $numSig = $xint*10**($x10-$sig+$power);
     # insert trailing zero's if have decimal point      # insert trailing zero's if have decimal point
     $numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/;      $numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/;
       # put a decimal pt for number ending with 0 and length = # of sig fig
       $numSig.='.' if (length($numSig) == $sig && $numSig =~ /0$/);
       if (length($numSig) < $sig) {
    $numSig.='.'.substr($zeros,0,($sig-length($numSig)));
       }
     # return number with sign      # return number with sign
     return $sign.$numSig;      return $sign.$numSig;
   
Line 880  sub choose { Line 895  sub choose {
     return $_[$num];      return $_[$num];
 }  }
   
   #&sum1(1,$x,sub { &sum1($_[0],2*$_[0], sub { fact($_[0])**2 })});
   #sub sum1 {
   #    my ($start,$end,$sub)=@_;
   #    my $sum=0;
   #    for (my $i=$start;$i<=$end;$i++) {
   #        $sum+=&$sub($i);
   #    }
   #    return $sum
   #}
   
   #&sum2('a',1,$x,'&sum2(\'b\',$a,2*$a, \'&factorial($b)**2\')');
   #sub sum2 {
   #    my ($varname,$start,$end,$line)=@_;
   #    my $sum=0;
   #    for (my $i=$start;$i<=$end;$i++) {
   # my $func=sub {
   #    eval("\$".$varname."=$i");
   #    eval($line);
   # };
   #        $sum+=&$func($i);
   #    }
   #    return $sum
   #}
   
 # expiremental idea  # expiremental idea
 sub proper_path {  sub proper_path {
     my ($path)=@_;      my ($path)=@_;

Removed from v.1.97  
changed lines
  Added in v.1.104


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