Annotation of loncom/homework/default_homework.lcpm, revision 1.9
1.1 harris41 1: # file name (temp): default_homework
2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
3: #
4: #
1.3 albertel 5: $RANDOMINIT=0;
6:
1.7 albertel 7: sub caparesponse_check {
8: my $answer='';
9: my $type='';
10: my $tol_type='';
11: my $tolerance='';
12: my $sig_lbound='';
13: my $sig_ubound='';
14: my $ans_fmt='';
1.9 ! albertel 15: my $units='';
1.7 albertel 16: my $calc='';
17: my ($response,$expr)=@_;
18:
19: ($answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,
1.9 ! albertel 20: $units,$calc) = eval $expr.'return $answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,$units,$calc';
1.8 albertel 21:
22: #type's definitons come from capaParser.h
23: if ($type eq '' ) {
24: if ( $answer eq ($answer *1.0)) { $type = 2;
25: } else { $type = 3; }
26: } else {
27: if ($type eq 'cs') { $type = 4;
28: } elsif ($type eq 'ci') { $type = 3;
29: } elsif ($type eq 'mc') { $type = 5;
30: } elsif ($type eq 'fml') { $type = 8;
1.9 ! albertel 31: } elsif ($type eq 'subj') { $type = 7;
! 32: } else { return "ERROR: Unknown type of answer: $type" }
1.8 albertel 33: }
34:
35:
1.7 albertel 36: my $result = &caparesponse_capa_check_answer($response,$answer,$type,
37: $tol_type,$tolerance,
38: $sig_lbound,$sig_ubound,
1.9 ! albertel 39: $ans_fmt, $units,$calc);
! 40:
! 41: if ($result == '1') { $result='EXACT_ANS'; }
! 42: elsif ($result == '2') { $result='APPROX_ANS'; }
! 43: elsif ($result == '3') { $result='SIG_FAIL'; }
! 44: elsif ($result == '4') { $result='UNIT_FAIL'; }
! 45: elsif ($result == '5') { $result='NO_UNIT'; }
! 46: elsif ($result == '6') { $result='UNIT_OK'; }
! 47: elsif ($result == '7') { $result='INCORRECT'; }
! 48: elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
! 49: elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
! 50: elsif ($result =='10') { $result='SUB_RECORDED'; }
! 51: elsif ($result =='11') { $result='BAD_FORMULA'; }
! 52: elsif ($result =='12') { $result='WANTED_NUMERIC'; }
! 53: else {$result = "ERROR: Unknown Result: $result";}
! 54:
1.7 albertel 55: return ":$result:$response:$answer:";
56: }
57:
1.4 albertel 58: sub tex {
59: if ( $external::target eq "tex" ) {
60: #$SCRIPT_RESULT.=@_[0];
61: return @_[0];
62: } else {
63: #$SCRIPT_RESULT.=@_[1];
64: return @_[1];
65: }
66: }
67:
68: sub web {
69: if ( $external::target eq "tex" ) {
70: #$SCRIPT_RESULT.=@_[1];
71: return @_[1];
72: } else {
73: if ( $external::target eq "web") {
74: #$SCRIPT_RESULT.=@_[0];
75: return @_[0];
76: } else {
77: #$SCRIPT_RESULT.=@_[2];
78: return @_[2];
79: }
80: }
81: }
82:
83: sub problem {
84: $SCRIPT_RESULT.='1';
85: return '';
86: }
87:
1.1 harris41 88: sub hinton {
89: return 0;
90: }
91:
92: sub random {
93: my ($start,$end,$step)=@_;
1.3 albertel 94: if ( ! $RANDOMINIT ) { srand($external::randomseed); $RANDOMINIT=1; }
1.1 harris41 95: my $num=1+int(($end-$start)/$step);
96: my $result=$start + int(rand() * $num)*$step;
97: return $result;
98: }
99:
100: sub tan { sin($_[0]) / cos($_[0]) }
101: sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
102: sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
103:
104: sub html {
1.4 albertel 105: if ( $external::target eq "web" ) {
106: #$SCRIPT_RESULT.=@_[0];
107: return @_[0];
1.1 harris41 108: }
109: }
110:
111:
112: sub pow {return $_[0] ** $_[1]; }
113: sub ceil {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }
114: sub floor {return int($_[0]); }
115:
1.2 albertel 116: sub format {
117: my ($value,$fmt)=@_;
118: $SCRIPT_RESULT.=sprintf('%.'.$fmt,$value);
119: }
1.5 albertel 120:
121: sub map {
122: my $num = $#_/2;
123: my $i;
1.6 albertel 124: my @used;
125: my @permutation;
126: for ($i=0; $i < $num;) {
127: $rand = &random(1,$num,1);
128: if ( $used[$rand] == '0' ) {
129: $i++;
130: $used[$rand]='1';
131: $permutation[$i]=$rand;
132: }
133: }
1.5 albertel 134: for ( $i=1 ; $i<$num+1 ; $i++ ) {
1.6 albertel 135: ${$_[$permutation[$i]]}=$_[$i+$num]
1.5 albertel 136: }
137: }
138:
139: sub choose {
140: my $num = $_[0];
141: return $_[$num];
142: }
1.6 albertel 143: #$external::randomseed=time;
1.5 albertel 144: #$a=2;
145: #$b=2;
1.6 albertel 146: #$c=2;
147: #&map(1,\$a,\$b,\$c,3,4,5);
1.5 albertel 148: #print $a."\n".$b."\n";
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>