1: # file name (temp): default_homework
2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
3: #
4: #
5: $RANDOMINIT=0;
6:
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='';
15: my $unit_str='';
16: my $calc='';
17: my ($response,$expr)=@_;
18:
19: ($answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,
20: $unit_str,$calc) = eval $expr.'return $answer,$type,$tol_type,$tolerance,$sig_lbound,$sig_ubound,$ans_fmt,$unit_str,$calc';
21: my $result = &caparesponse_capa_check_answer($response,$answer,$type,
22: $tol_type,$tolerance,
23: $sig_lbound,$sig_ubound,
24: $ans_fmt, $unit_str,$calc);
25: return ":$result:$response:$answer:";
26: }
27:
28: sub tex {
29: if ( $external::target eq "tex" ) {
30: #$SCRIPT_RESULT.=@_[0];
31: return @_[0];
32: } else {
33: #$SCRIPT_RESULT.=@_[1];
34: return @_[1];
35: }
36: }
37:
38: sub web {
39: if ( $external::target eq "tex" ) {
40: #$SCRIPT_RESULT.=@_[1];
41: return @_[1];
42: } else {
43: if ( $external::target eq "web") {
44: #$SCRIPT_RESULT.=@_[0];
45: return @_[0];
46: } else {
47: #$SCRIPT_RESULT.=@_[2];
48: return @_[2];
49: }
50: }
51: }
52:
53: sub problem {
54: $SCRIPT_RESULT.='1';
55: return '';
56: }
57:
58: sub hinton {
59: return 0;
60: }
61:
62: sub random {
63: my ($start,$end,$step)=@_;
64: if ( ! $RANDOMINIT ) { srand($external::randomseed); $RANDOMINIT=1; }
65: my $num=1+int(($end-$start)/$step);
66: my $result=$start + int(rand() * $num)*$step;
67: return $result;
68: }
69:
70: sub tan { sin($_[0]) / cos($_[0]) }
71: sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
72: sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
73:
74: sub html {
75: if ( $external::target eq "web" ) {
76: #$SCRIPT_RESULT.=@_[0];
77: return @_[0];
78: }
79: }
80:
81:
82: sub pow {return $_[0] ** $_[1]; }
83: sub ceil {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }
84: sub floor {return int($_[0]); }
85:
86: sub format {
87: my ($value,$fmt)=@_;
88: $SCRIPT_RESULT.=sprintf('%.'.$fmt,$value);
89: }
90:
91: sub map {
92: my $num = $#_/2;
93: my $i;
94: my @used;
95: my @permutation;
96: for ($i=0; $i < $num;) {
97: $rand = &random(1,$num,1);
98: if ( $used[$rand] == '0' ) {
99: $i++;
100: $used[$rand]='1';
101: $permutation[$i]=$rand;
102: }
103: }
104: for ( $i=1 ; $i<$num+1 ; $i++ ) {
105: ${$_[$permutation[$i]]}=$_[$i+$num]
106: }
107: }
108:
109: sub choose {
110: my $num = $_[0];
111: return $_[$num];
112: }
113: #$external::randomseed=time;
114: #$a=2;
115: #$b=2;
116: #$c=2;
117: #&map(1,\$a,\$b,\$c,3,4,5);
118: #print $a."\n".$b."\n";
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>