Annotation of loncom/homework/default_homework.lcpm, revision 1.6
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.4 albertel 7: sub tex {
8: if ( $external::target eq "tex" ) {
9: #$SCRIPT_RESULT.=@_[0];
10: return @_[0];
11: } else {
12: #$SCRIPT_RESULT.=@_[1];
13: return @_[1];
14: }
15: }
16:
17: sub web {
18: if ( $external::target eq "tex" ) {
19: #$SCRIPT_RESULT.=@_[1];
20: return @_[1];
21: } else {
22: if ( $external::target eq "web") {
23: #$SCRIPT_RESULT.=@_[0];
24: return @_[0];
25: } else {
26: #$SCRIPT_RESULT.=@_[2];
27: return @_[2];
28: }
29: }
30: }
31:
32: sub problem {
33: $SCRIPT_RESULT.='1';
34: return '';
35: }
36:
1.1 harris41 37: sub hinton {
38: return 0;
39: }
40:
41: sub random {
42: my ($start,$end,$step)=@_;
1.3 albertel 43: if ( ! $RANDOMINIT ) { srand($external::randomseed); $RANDOMINIT=1; }
1.1 harris41 44: my $num=1+int(($end-$start)/$step);
45: my $result=$start + int(rand() * $num)*$step;
46: return $result;
47: }
48:
49: sub tan { sin($_[0]) / cos($_[0]) }
50: sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
51: sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
52:
53: sub html {
1.4 albertel 54: if ( $external::target eq "web" ) {
55: #$SCRIPT_RESULT.=@_[0];
56: return @_[0];
1.1 harris41 57: }
58: }
59:
60:
61: sub pow {return $_[0] ** $_[1]; }
62: sub ceil {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (int($_[0])+ 1); }
63: sub floor {return int($_[0]); }
64:
1.2 albertel 65: sub format {
66: my ($value,$fmt)=@_;
67: $SCRIPT_RESULT.=sprintf('%.'.$fmt,$value);
68: }
1.5 albertel 69:
70: sub map {
71: my $num = $#_/2;
72: my $i;
1.6 ! albertel 73: my @used;
! 74: my @permutation;
! 75: for ($i=0; $i < $num;) {
! 76: $rand = &random(1,$num,1);
! 77: if ( $used[$rand] == '0' ) {
! 78: $i++;
! 79: $used[$rand]='1';
! 80: $permutation[$i]=$rand;
! 81: }
! 82: }
1.5 albertel 83: for ( $i=1 ; $i<$num+1 ; $i++ ) {
1.6 ! albertel 84: ${$_[$permutation[$i]]}=$_[$i+$num]
1.5 albertel 85: }
86: }
87:
88: sub choose {
89: my $num = $_[0];
90: return $_[$num];
91: }
1.6 ! albertel 92: #$external::randomseed=time;
1.5 albertel 93: #$a=2;
94: #$b=2;
1.6 ! albertel 95: #$c=2;
! 96: #&map(1,\$a,\$b,\$c,3,4,5);
1.5 albertel 97: #print $a."\n".$b."\n";
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>