Annotation of loncom/homework/default_homework.lcpm, revision 1.144
1.42 albertel 1: # The LearningOnline Network with CAPA
1.1 harris41 2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
1.42 albertel 3: #
1.144 ! www 4: # $Id: default_homework.lcpm,v 1.143 2009/02/06 10:43:48 riegler Exp $
1.42 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: #
1.76 albertel 29:
1.25 albertel 30: #init some globals
1.38 albertel 31: $hidden::RANDOMINIT=0;
1.22 ng 32: $pi=atan2(1,1)*4;
33: $rad2deg=180.0/$pi;
34: $deg2rad=$pi/180.0;
1.44 matthew 35: $"=' ';
1.116 albertel 36: use strict;
37: {
38: my $n = 0;
39: my $total = 0;
40: my $num_left = 0;
41: my @order;
42: my $type;
43:
44: sub init_permutation {
45: my ($size,$requested_type) = @_;
46: @order = (0..$size-1);
47: $n = $size;
48: $type = $requested_type;
49: if ($type eq 'ordered') {
50: $total = $num_left = 1;
51: } elsif ($type eq 'unordered') {
52: $total = $num_left = &factorial($size);
53: } else {
54: die("Unkown type: $type");
55: }
56: }
57:
58: sub get_next_permutation {
59: if ($num_left == $total) {
60: $num_left--;
1.117 albertel 61: return \@order;
1.116 albertel 62: }
63:
64: # Find largest index j with a[j] < a[j+1]
65:
66: my $j = scalar(@order) - 2;
67: while ($order[$j] > $order[$j+1]) {
68: $j--;
69: }
70:
71: # Find index k such that a[k] is smallest integer
72: # greater than a[j] to the right of a[j]
73:
74: my $k = scalar(@order) - 1;
75: while ($order[$j] > $order[$k]) {
76: $k--;
77: }
78:
79: # Interchange a[j] and a[k]
80:
81: @order[($k,$j)] = @order[($j,$k)];
82:
83: # Put tail end of permutation after jth position in increasing order
84:
85: my $r = scalar(@order) - 1;
86: my $s = $j + 1;
87:
88: while ($r > $s) {
89: @order[($s,$r)]=@order[($r,$s)];
90: $r--;
91: $s++;
92: }
93:
94: $num_left--;
1.117 albertel 95: return(\@order);
1.116 albertel 96: }
97:
98: sub get_permutations_left {
99: return $num_left;
100: }
101: }
1.3 albertel 102:
1.91 albertel 103: sub check_commas {
104: my ($response)=@_;
105: #print("$response ");
106: my @numbers=split(',',$response);
107: #print(" numbers ".join('-',@numbers)." ");
108: if (scalar(@numbers) > 1) {
109: #print(" numbers[0] ".$numbers[0]." ");
110: if (length($numbers[0]) > 3 || length($numbers[0]) == 0) { return -1; }
111: shift(@numbers);
112: #print(" numbers ".scalar(@numbers)." ");
113: while (scalar(@numbers) > 1) {
114: #print(" numbers ".join('-',@numbers)." ");
115: if (length($numbers[0]) != 3) { return -2; }
116: shift(@numbers);
117: }
118: my ($number)=split('\.',$numbers[0]);
119: #print(" number ".$number." ");
120: #print(" numbers[0] ".$numbers[0]." ");
121: if (length($number) != 3) { return -3; }
122: } else {
123: my ($number)=split('\.',$numbers[0]);
124: if (length($number) > 3) { return -4; }
125: }
126: return 1;
127: }
128:
1.117 albertel 129:
1.7 albertel 130: sub caparesponse_check {
1.74 albertel 131: my ($answer,$response)=@_;
1.73 albertel 132: #not properly used yet: calc
133: #not to be used: $ans_fmt
1.74 albertel 134: my $type=$LONCAPA::CAPAresponse_args{'type'};
135: my $tol=$LONCAPA::CAPAresponse_args{'tol'};
136: my $sig=$LONCAPA::CAPAresponse_args{'sig'};
1.88 albertel 137: my $ans_fmt=$LONCAPA::CAPAresponse_args{'format'};
1.74 albertel 138: my $unit=$LONCAPA::CAPAresponse_args{'unit'};
139: my $calc=$LONCAPA::CAPAresponse_args{'calc'};
140: my $samples=$LONCAPA::CAPAresponse_args{'samples'};
1.73 albertel 141:
142: my $tol_type=''; # gets it's value from whether tol has a % or not done
143: my $sig_lbound=''; #done
144: my $sig_ubound=''; #done
145:
146:
147: #type's definitons come from capaParser.h
1.116 albertel 148:
1.73 albertel 149: #remove leading and trailing whitespace
150: if (!defined($response)) {
151: $response='';
152: }
153: if ($response=~ /^\s|\s$/) {
154: $response=~ s:^\s+|\s+$::g;
1.119 albertel 155: &LONCAPA_INTERNAL_DEBUG("Removed ws now :$response:");
1.73 albertel 156: }
1.116 albertel 157:
1.117 albertel 158: #&LONCAPA_INTERNAL_DEBUG(" type is $type ");
1.100 albertel 159: if ($type eq 'cs' || $type eq 'ci') {
1.130 www 160: #for string answers make sure all places spaces occur, there is
1.76 albertel 161: #really only 1 space, in both the answer and the response
162: $answer=~s/ +/ /g;
163: $response=~s/ +/ /g;
1.100 albertel 164: } elsif ($type eq 'mc') {
165: $answer=~s/[\s,]//g;
166: $response=~s/[\s,]//g;
1.76 albertel 167: }
1.91 albertel 168: if ($type eq 'float' && $unit=~/\$/) {
1.126 www 169: if ($response!~/^\$|\$$/) { return ('NO_UNIT', undef); }
1.88 albertel 170: $response=~s/\$//g;
171: }
1.91 albertel 172: if ($type eq 'float' && $unit=~/\,/ && (&check_commas($response)<0)) {
173: return "COMMA_FAIL:";
174: }
1.88 albertel 175: $ans_fmt=~s/\W//g;
1.91 albertel 176: $unit=~s/[\$,]//g;
177: if ($type eq 'float') { $response=~s/,//g; }
1.88 albertel 178:
1.117 albertel 179: if (length($response) > 500) { return ('TOO_LONG',undef); }
1.73 albertel 180:
181: if ($type eq '' ) {
1.119 albertel 182: &LONCAPA_INTERNAL_DEBUG("Didn't find a type :$type: defaulting");
1.73 albertel 183: if ( $answer eq ($answer *1.0)) { $type = 2;
184: } else { $type = 3; }
185: } else {
1.107 albertel 186: if ($type eq 'cs') { $type = 4; }
1.73 albertel 187: elsif ($type eq 'ci') { $type = 3 }
188: elsif ($type eq 'mc') { $type = 5; }
189: elsif ($type eq 'fml') { $type = 8; }
1.107 albertel 190: elsif ($type eq 'math') { $type = 9; }
1.73 albertel 191: elsif ($type eq 'subj') { $type = 7; }
192: elsif ($type eq 'float') { $type = 2; }
193: elsif ($type eq 'int') { $type = 1; }
1.117 albertel 194: else { return ('ERROR', "Unknown type of answer: $type") }
1.73 albertel 195: }
196:
197: my $points;
198: my $id_list;
199: #formula type setup the sample points
200: if ($type eq '8') {
201: ($id_list,$points)=split(/@/,$samples);
1.119 albertel 202: &LONCAPA_INTERNAL_DEBUG("Found :$id_list:$points: points in $samples");
1.73 albertel 203: }
204: if ($tol eq '') {
205: $tol=0.0;
206: $tol_type=1; #TOL_ABSOLUTE
207: } else {
208: if ($tol =~ /%$/) {
209: chop $tol;
210: $tol_type=2; #TOL_PERCENTAGE
211: } else {
212: $tol_type=1; #TOL_ABSOLUTE
213: }
214: }
215:
1.85 albertel 216: ($sig_ubound,$sig_lbound)=&LONCAPA_INTERNAL_get_sigrange($sig);
217:
1.73 albertel 218: my $reterror="";
1.107 albertel 219: my $result;
1.142 raeburn 220: if (($type eq '9') || ($type eq '8')) {
221: if ($response=~/\=/) {
222: return ('BAD_FORMULA','Please submit just an expression, not an equation.');
1.143 riegler 223: } elsif ($response =~ /\,/ and $response !~ /^\s*\{.*\}\s*$/) {
1.142 raeburn 224: return ('BAD_FORMULA');
225: }
226: }
1.107 albertel 227: if ($type eq '9') {
1.108 www 228: $result = &maxima_check(&maxima_cas_formula_fix($response),&maxima_cas_formula_fix($answer),\$reterror);
1.107 albertel 229: } else {
1.109 albertel 230: if ($type eq '8') { # fml type
231: $response = &capa_formula_fix($response);
232: $answer = &capa_formula_fix($answer);
233: }
234: $result = &caparesponse_capa_check_answer($response,$answer,$type,
1.73 albertel 235: $tol_type,$tol,
236: $sig_lbound,$sig_ubound,
237: $ans_fmt,$unit,$calc,$id_list,
238: $points,$external::randomseed,
239: \$reterror);
1.107 albertel 240: }
1.73 albertel 241: if ($result == '1') { $result='EXACT_ANS'; }
242: elsif ($result == '2') { $result='APPROX_ANS'; }
243: elsif ($result == '3') { $result='SIG_FAIL'; }
244: elsif ($result == '4') { $result='UNIT_FAIL'; }
245: elsif ($result == '5') { $result='NO_UNIT'; }
246: elsif ($result == '6') { $result='UNIT_OK'; }
247: elsif ($result == '7') { $result='INCORRECT'; }
248: elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
249: elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
250: elsif ($result =='10') { $result='SUB_RECORDED'; }
251: elsif ($result =='11') { $result='BAD_FORMULA'; }
1.94 albertel 252: elsif ($result =='12' && !$response) { $result='MISSING_ANSWER'; }
253: elsif ($result =='12') { $result='WANTED_NUMERIC'; }
1.77 albertel 254: elsif ($result =='13') { $result='UNIT_INVALID_INSTRUCTOR'; }
255: elsif ($result =='141') { $result='UNIT_INVALID_STUDENT'; }
256: elsif ($result =='142') { $result='UNIT_INVALID_STUDENT'; }
257: elsif ($result =='143') { $result='UNIT_INVALID_STUDENT'; }
258: elsif ($result =='15') { $result='UNIT_IRRECONCIBLE'; }
1.73 albertel 259: else {$result = "ERROR: Unknown Result:$result:$@:";}
260:
1.119 albertel 261: &LONCAPA_INTERNAL_DEBUG("RetError $reterror: Answer $answer: Response $response: type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|");
262: &LONCAPA_INTERNAL_DEBUG(" $answer $response $result ");
1.139 raeburn 263: return ($result,$reterror);
1.37 albertel 264: }
265:
1.73 albertel 266:
1.37 albertel 267: sub caparesponse_check_list {
1.119 albertel 268: my $responses=$LONCAPA::CAPAresponse_args{'response'};
1.105 albertel 269: &LONCAPA_INTERNAL_DEBUG("args ".join(':',%LONCAPA::CAPAresponse_args));
1.74 albertel 270: my $type = $LONCAPA::CAPAresponse_args{'type'};
1.133 www 271: my $answerunit=$LONCAPA::CAPAresponse_args{'unit'};
272: &LONCAPA_INTERNAL_DEBUG("Got type :$type: answer unit :$answerunit:\n");
1.119 albertel 273:
274: my $num_input_lines =
275: scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}});
1.120 albertel 276:
277: if ($type ne '' ) {
1.119 albertel 278: if (scalar(@$responses) < $num_input_lines) {
1.105 albertel 279: return 'MISSING_ANSWER';
280: }
1.119 albertel 281: if (scalar(@$responses) > $num_input_lines) {
282: return 'EXTRA_ANSWER';
283: }
284:
285: }
286:
287: foreach my $which (0..($num_input_lines-1)) {
288: my $answer_size =
289: scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}[$which]});
290: if ($type ne ''
291: && $answer_size > 1) {
292: $responses->[$which]=[split(/,/,$responses->[$which])];
293: } else {
294: $responses->[$which]=[$responses->[$which]];
295: }
296: }
297: foreach my $which (0..($num_input_lines-1)) {
298: my $answer_size =
299: scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}[$which]});
300: my $response_size =
301: scalar(@{$responses->[$which]});
302: if ($answer_size > $response_size) {
303: return 'MISSING_ANSWER';
304: }
305: if ($answer_size < $response_size) {
1.105 albertel 306: return 'EXTRA_ANSWER';
307: }
1.73 albertel 308: }
1.119 albertel 309:
310: &LONCAPA_INTERNAL_DEBUG("Initial final response :$responses->[0][-1]:");
1.105 albertel 311: my $unit;
1.140 raeburn 312: if ($type eq 'float' || $type eq '') {
1.73 albertel 313: #for numerical problems split off the unit
1.128 www 314: # if ( $responses->[0][-1]=~ /(.*[^\s])\s+([^\s]+)/ ) {
1.132 www 315: if ( $responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/ ) {
1.119 albertel 316: $responses->[0][-1]=$1;
1.128 www 317: $unit=&capa_formula_fix($2);
318: &LONCAPA_INTERNAL_DEBUG("Found unit :$unit:");
1.73 albertel 319: }
320: }
1.119 albertel 321: &LONCAPA_INTERNAL_DEBUG("Final final response :$responses->[0][-1]:$unit:");
1.73 albertel 322: $unit=~s/\s//;
1.133 www 323: foreach my $response (@$responses) {
324: foreach my $element (@$response) {
1.138 raeburn 325: if (($type eq 'float') || (($type eq '') && ($unit ne ''))) {
326: $element =~ s/\s//g;
327: }
1.133 www 328: my $appendunit=$unit;
1.141 raeburn 329: if (($unit=~/\%/) && ($answerunit ne '%')) {
1.133 www 330: $element=$element/100;
331: $appendunit=~s/\%//;
332: }
333: if (($element==0) && ($unit!~/\w/) && ($answerunit=~/\w/)) {
334: $appendunit=$answerunit;
335: }
336: $element .= " $appendunit";
337: &LONCAPA_INTERNAL_DEBUG("Made response element :$element:");
338: }
1.119 albertel 339: }
340:
1.117 albertel 341: foreach my $thisanswer (@{ $LONCAPA::CAPAresponse_answer->{'answers'} }) {
342: if (!defined($thisanswer)) {
343: return ('ERROR','answer was undefined');
344: }
345: }
346:
347:
1.121 albertel 348: # &LONCAPA_INTERNAL_DEBUG(&LONCAPA_INTERNAL_Dumper($responses));
1.117 albertel 349: my %memoized;
350: if ($LONCAPA::CAPAresponse_answer->{'type'} eq 'ordered') {
1.119 albertel 351: for (my $i=0; $i<scalar(@$responses);$i++) {
1.117 albertel 352: my $answer = $LONCAPA::CAPAresponse_answer->{'answers'}[$i];
1.119 albertel 353: my $response = $responses->[$i];
1.117 albertel 354: my $key = "$answer\0$response";
1.119 albertel 355: my (@awards,@msgs);
356: for (my $j=0; $j<scalar(@$response); $j++) {
357: my ($award,$msg) = &caparesponse_check($answer->[$j],
358: $response->[$j]);
359: push(@awards,$award);
360: push(@msgs, $msg);
361: }
362: my ($award,$msg) =
363: &LONCAPA_INTERNAL_FINALIZEAWARDS(\@awards,\@msgs);
364: $memoized{$key} = [$award,$msg];
1.117 albertel 365: }
366: } else {
1.119 albertel 367: #FIXME broken with unorder responses where one is a <value>
368: # and the other is a <vector> (need to delay parse til
369: # inside the loop?)
370: foreach my $response (@$responses) {
371: my $response_size = scalar(@{$response});
1.117 albertel 372: foreach my $answer (@{ $LONCAPA::CAPAresponse_answer->{'answers'} }) {
373: my $key = "$answer\0$response";
1.119 albertel 374: my $answer_size = scalar(@{$answer});
375: my ($award,$msg);
376: if ($answer_size > $response_size) {
377: $award = 'MISSING_ANSWER';
378: } elsif ($answer_size < $response_size) {
379: $award = 'EXTRA_ANSWER';
380: } else {
381: my (@awards,@msgs);
382: for (my $j=0; $j<scalar(@$response); $j++) {
383: my ($award,$msg) = &caparesponse_check($answer->[$j],
384: $response->[$j]);
385: push(@awards,$award);
386: push(@msgs, $msg);
387: }
388: ($award,$msg) =
389: &LONCAPA_INTERNAL_FINALIZEAWARDS(\@awards,\@msgs);
390: }
391: $memoized{$key} = [$award,$msg];
1.117 albertel 392: }
393: }
394: }
395:
1.116 albertel 396: my ($final_award,$final_msg);
1.119 albertel 397: &init_permutation(scalar(@$responses),
1.116 albertel 398: $LONCAPA::CAPAresponse_answer->{'type'});
1.117 albertel 399:
1.118 albertel 400: # possible FIXMEs
401: # - significant time is spent calling non-safe space routine
402: # from safe space
403: # - early outs could be possible with classifying awards is to stratas
404: # and stopping as so as hitting the top strata
405: # - some early outs also might be possible with check ing the
406: # memoized hash of results (is correct even possible? etc.)
407:
1.117 albertel 408: my (@final_awards,@final_msg);
1.116 albertel 409: while( &get_permutations_left() ) {
1.117 albertel 410: my $order = &get_next_permutation();
1.116 albertel 411: my (@awards, @msgs, $i);
412: foreach my $thisanswer (@{ $LONCAPA::CAPAresponse_answer->{'answers'} }) {
1.119 albertel 413: my $key = "$thisanswer\0".$responses->[$order->[$i]];
1.117 albertel 414: push(@awards,$memoized{$key}[0]);
415: push(@msgs,$memoized{$key}[1]);
1.116 albertel 416: $i++;
1.119 albertel 417:
1.116 albertel 418: }
1.119 albertel 419: &LONCAPA_INTERNAL_DEBUG(" all awards ".join(':',@awards));
420:
1.116 albertel 421: my ($possible_award,$possible_msg) =
422: &LONCAPA_INTERNAL_FINALIZEAWARDS(\@awards,\@msgs);
1.119 albertel 423: &LONCAPA_INTERNAL_DEBUG(" pos awards ".$possible_award);
1.117 albertel 424: push(@final_awards,$possible_award);
425: push(@final_msg,$possible_msg);
1.73 albertel 426: }
1.117 albertel 427:
1.119 albertel 428: &LONCAPA_INTERNAL_DEBUG(" all final_awards ".join(':',@final_awards));
1.117 albertel 429: my ($final_award,$final_msg) =
430: &LONCAPA_INTERNAL_FINALIZEAWARDS(\@final_awards,\@final_msg,undef,1);
1.116 albertel 431: return ($final_award,$final_msg);
1.7 albertel 432: }
433:
1.124 www 434: sub cas {
1.137 www 435: my ($system,$input,$library)=@_;
1.124 www 436: my $output;
437: if ($system eq 'maxima') {
1.137 www 438: $output=&maxima_eval($input,$library);
1.144 ! www 439: } elsif ($system eq 'R') {
! 440: $output=&r_eval($input,$library);
1.137 www 441: } else {
442: $output='Error: unrecognized CAS';
1.124 www 443: }
444: return $output;
445: }
446:
1.4 albertel 447: sub tex {
1.73 albertel 448: if ( $external::target eq "tex" ) {
449: return $_[0];
450: } else {
451: return $_[1];
452: }
1.4 albertel 453: }
454:
1.24 ng 455: sub var_in_tex {
1.73 albertel 456: if ( $external::target eq "tex" ) {
457: return $_[0];
458: } else {
459: return "";
460: }
1.24 ng 461: }
462:
1.4 albertel 463: sub web {
1.73 albertel 464: if ( $external::target eq "tex" ) {
465: return $_[1];
1.26 ng 466: } else {
1.73 albertel 467: if ( $external::target eq "web" || $external::target eq "answer") {
468: return $_[2];
469: } else {
470: return $_[0];
471: }
1.4 albertel 472: }
473: }
474:
1.24 ng 475: sub html {
1.73 albertel 476: if ( $external::target eq "web" ) {
477: return shift;
478: }
1.24 ng 479: }
480:
1.1 harris41 481: sub hinton {
1.73 albertel 482: return 0;
1.1 harris41 483: }
484:
485: sub random {
1.61 albertel 486: my ($start,$end,$step)=@_;
487: if ( ! $hidden::RANDOMINIT ) {
488: if ($external::randomseed == 0) { $external::randomseed=1; }
489: if ($external::randomseed =~/,/) {
1.84 albertel 490: my ($num1,$num2)=split(/,/,$external::randomseed);
491: &random_set_seed(1,abs($num1));
492: } elsif ($external::randomseed =~/:/) {
493: my ($num1,$num2)=split(/:/,$external::randomseed);
1.61 albertel 494: &random_set_seed(abs($num1),abs($num2));
495: } else {
496: &random_set_seed(1,int(abs($external::randomseed)));
497: }
498: &math_random_uniform();
499: $hidden::RANDOMINIT=1;
500: }
501: if (!defined($step)) { $step=1; }
502: my $num=1+int(($end-$start)/$step);
503: my $result=$start + int(&math_random_uniform() * $num)*$step;
504: return $result;
1.1 harris41 505: }
506:
1.26 ng 507: sub random_normal {
1.73 albertel 508: my ($item_cnt,$seed,$av,$std_dev) = @_;
509: my @oldseed=&random_get_seed();
510: my @retArray;
511: &random_set_seed_from_phrase($seed);
512: @retArray=&math_random_normal($item_cnt,$av,$std_dev);
513: &random_set_seed(@oldseed);
514: return @retArray;
1.26 ng 515: }
516:
517: sub random_beta {
1.73 albertel 518: my ($item_cnt,$seed,$aa,$bb) = @_;
519: my @oldseed=&random_get_seed();
520: my @retArray;
521: &random_set_seed_from_phrase($seed);
522: @retArray=&math_random_beta($item_cnt,$aa,$bb);
523: &random_set_seed(@oldseed);
524: return @retArray;
1.26 ng 525: }
526:
527: sub random_gamma {
1.73 albertel 528: my ($item_cnt,$seed,$a,$r) = @_;
529: my @oldseed=&random_get_seed();
530: my @retArray;
531: &random_set_seed_from_phrase($seed);
532: @retArray=&math_random_gamma($item_cnt,$a,$r);
533: &random_set_seed(@oldseed);
534: return @retArray;
1.26 ng 535: }
536:
537: sub random_exponential {
1.73 albertel 538: my ($item_cnt,$seed,$av) = @_;
539: my @oldseed=&random_get_seed();
540: my @retArray;
541: &random_set_seed_from_phrase($seed);
542: @retArray=&math_random_exponential($item_cnt,$av);
543: &random_set_seed(@oldseed);
544: return @retArray;
1.26 ng 545: }
546:
547: sub random_poisson {
1.73 albertel 548: my ($item_cnt,$seed,$mu) = @_;
549: my @oldseed=&random_get_seed();
550: my @retArray;
551: &random_set_seed_from_phrase($seed);
552: @retArray=&math_random_poisson($item_cnt,$mu);
553: &random_set_seed(@oldseed);
554: return @retArray;
1.26 ng 555: }
556:
557: sub random_chi {
1.73 albertel 558: my ($item_cnt,$seed,$df) = @_;
559: my @oldseed=&random_get_seed();
560: my @retArray;
561: &random_set_seed_from_phrase($seed);
562: @retArray=&math_random_chi_square($item_cnt,$df);
563: &random_set_seed(@oldseed);
564: return @retArray;
1.26 ng 565: }
566:
567: sub random_noncentral_chi {
1.73 albertel 568: my ($item_cnt,$seed,$df,$nonc) = @_;
569: my @oldseed=&random_get_seed();
570: my @retArray;
571: &random_set_seed_from_phrase($seed);
572: @retArray=&math_random_noncentral_chi_square($item_cnt,$df,$nonc);
573: &random_set_seed(@oldseed);
574: return @retArray;
1.26 ng 575: }
576:
577: sub random_f {
1.73 albertel 578: my ($item_cnt,$seed,$dfn,$dfd) = @_;
579: my @oldseed=&random_get_seed();
580: my @retArray;
581: &random_set_seed_from_phrase($seed);
582: @retArray=&math_random_f($item_cnt,$dfn,$dfd);
583: &random_set_seed(@oldseed);
584: return @retArray;
1.26 ng 585: }
586:
587: sub random_noncentral_f {
1.73 albertel 588: my ($item_cnt,$seed,$dfn,$dfd,$nonc) = @_;
589: my @oldseed=&random_get_seed();
590: my @retArray;
591: &random_set_seed_from_phrase($seed);
592: @retArray=&math_random_noncentral_f($item_cnt,$dfn,$dfd,$nonc);
593: &random_set_seed(@oldseed);
594: return @retArray;
1.26 ng 595: }
596:
597: sub random_multivariate_normal {
1.73 albertel 598: my ($item_cnt,$seed,$mean,$covar) = @_;
599: my @oldseed=&random_get_seed();
600: &random_set_seed_from_phrase($seed);
1.87 albertel 601: my @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
1.73 albertel 602: &random_set_seed(@oldseed);
603: return @retArray;
1.26 ng 604: }
605:
606: sub random_multinomial {
1.73 albertel 607: my ($item_cnt,$seed,@p) = @_;
608: my @oldseed=&random_get_seed();
609: my @retArray;
610: &random_set_seed_from_phrase($seed);
1.87 albertel 611: my @retArray=&math_random_multinomial($item_cnt,@p);
1.73 albertel 612: &random_set_seed(@oldseed);
613: return @retArray;
1.26 ng 614: }
615:
616: sub random_permutation {
1.73 albertel 617: my ($seed,@inArray) = @_;
618: my @oldseed=&random_get_seed();
619: my @retArray;
620: &random_set_seed_from_phrase($seed);
621: @retArray=&math_random_permutation(@inArray);
622: &random_set_seed(@oldseed);
623: return @retArray;
1.26 ng 624: }
625:
626: sub random_uniform {
1.73 albertel 627: my ($item_cnt,$seed,$low,$high) = @_;
628: my @oldseed=&random_get_seed();
629: my @retArray;
630: &random_set_seed_from_phrase($seed);
631: @retArray=&math_random_uniform($item_cnt,$low,$high);
632: &random_set_seed(@oldseed);
633: return @retArray;
1.26 ng 634: }
635:
636: sub random_uniform_integer {
1.73 albertel 637: my ($item_cnt,$seed,$low,$high) = @_;
638: my @oldseed=&random_get_seed();
639: my @retArray;
640: &random_set_seed_from_phrase($seed);
641: @retArray=&math_random_uniform_integer($item_cnt,$low,$high);
642: &random_set_seed(@oldseed);
643: return @retArray;
1.26 ng 644: }
645:
646: sub random_binomial {
1.73 albertel 647: my ($item_cnt,$seed,$nt,$p) = @_;
648: my @oldseed=&random_get_seed();
649: my @retArray;
650: &random_set_seed_from_phrase($seed);
651: @retArray=&math_random_binomial($item_cnt,$nt,$p);
652: &random_set_seed(@oldseed);
653: return @retArray;
1.26 ng 654: }
655:
656: sub random_negative_binomial {
1.73 albertel 657: my ($item_cnt,$seed,$ne,$p) = @_;
658: my @oldseed=&random_get_seed();
659: my @retArray;
660: &random_set_seed_from_phrase($seed);
661: @retArray=&math_random_negative_binomial($item_cnt,$ne,$p);
662: &random_set_seed(@oldseed);
663: return @retArray;
1.26 ng 664: }
665:
1.103 albertel 666: sub abs { CORE::abs(shift) }
667: sub sin { CORE::sin(shift) }
668: sub cos { CORE::cos(shift) }
669: sub exp { CORE::exp(shift) }
670: sub int { CORE::int(shift) }
671: sub log { CORE::log(shift) }
672: sub atan2 { CORE::atan2($_[0],$_[1]) }
673: sub sqrt { CORE::sqrt(shift) }
1.23 ng 674:
1.59 albertel 675: sub tan { CORE::sin($_[0]) / CORE::cos($_[0]) }
1.21 harris41 676: #sub atan { atan2($_[0], 1); }
677: #sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
678: #sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
1.22 ng 679:
1.59 albertel 680: sub log10 { CORE::log($_[0])/CORE::log(10); }
1.22 ng 681:
1.20 harris41 682: sub factorial {
1.59 albertel 683: my $input = CORE::int(shift);
1.20 harris41 684: return "Error - unable to take factorial of an negative number ($input)" if $input < 0;
685: return "Error - factorial result is greater than system limit ($input)" if $input > 170;
686: return 1 if $input == 0;
687: my $result = 1;
688: for (my $i=2; $i<=$input; $i++) { $result *= $i }
689: return $result;
690: }
691:
692: sub sgn {
693: return -1 if $_[0] < 0;
694: return 0 if $_[0] == 0;
695: return 1 if $_[0] > 0;
696: }
697:
698: sub min {
699: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
700: return shift @sorted;
701: }
702:
703: sub max {
704: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
705: return pop @sorted;
706: }
1.1 harris41 707:
1.20 harris41 708: sub roundto {
709: my ($input,$n) = @_;
710: return sprintf('%.'.$n.'f',$input);
711: }
712:
713: sub to_string {
714: my ($input,$n) = @_;
1.26 ng 715: return sprintf($input) if $n eq "";
716: $n = '.'.$n if $n !~ /^\./;
1.20 harris41 717: return sprintf('%'.$n,$input) if $n ne "";
718: }
719:
720: sub sub_string {
721: my ($str,$start,$len) = @_;
722: return substr($str,$start-1,$len);
723: }
1.1 harris41 724:
725: sub pow {return $_[0] ** $_[1]; }
1.59 albertel 726: sub ceil {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? (CORE::int($_[0])+ 1) : CORE::int($_[0])); }
727: sub floor {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? CORE::int($_[0]) : (CORE::int($_[0])-1)); }
1.27 ng 728: #sub floor {return int($_[0]); }
1.1 harris41 729:
1.2 albertel 730: sub format {
1.73 albertel 731: my ($value,$fmt)=@_;
1.81 albertel 732: my ($dollarmode,$commamode,$alwaysperiod,$options);
733: if ($fmt =~ /^([^\d]*)(.*)/) { $options=$1; $fmt=$2; }
734: #if ($options =~ /\$/) { $dollamode=1; }
735: #if ($options =~ /,/) { $commamode=1; }
1.82 albertel 736: if ($options =~ /\./) { $alwaysperiod=1; }
1.99 ng 737: my $result;
1.97 albertel 738: if ($fmt=~/s$/i) {
739: $result=&format_significant_figures($value,$fmt);
740: } else {
741: $fmt=~s/e/E/g;
1.99 ng 742: $result=sprintf('%.'.$fmt,$value);
1.97 albertel 743: if ($alwaysperiod && $fmt eq '0f') { $result .='.'; }
744: $result=~s/(E[+-]*)0/$1/;
745: }
1.81 albertel 746: #if ($dollarmode) {$result=&dollarformat($result);}
747: #if ($commamode) {$result=&commaformat($result);}
1.73 albertel 748: return $result;
1.46 albertel 749: }
750:
1.75 albertel 751: sub chemparse {
752: my ($reaction) = @_;
1.96 albertel 753: my @tokens = split(/(\s\+|\->|<=>|<\-|\.)/,$reaction);
1.75 albertel 754: my $formula = '';
755: foreach my $token (@tokens) {
756: if ($token eq '->' ) {
757: $formula .= '<m>\ensuremath{\rightarrow}</m> ';
758: next;
759: }
1.96 albertel 760: if ($token eq '<-' ) {
761: $formula .= '<m>\ensuremath{\leftarrow}</m> ';
762: next;
763: }
1.75 albertel 764: if ($token eq '<=>') {
765: if ($external::target eq 'web' &&
766: &EXT('request.browser.unicode')) {
1.76 albertel 767: $formula .= '⇌ ';
1.75 albertel 768: } else {
769: $formula .= &web('<=> ','<m>\ensuremath{\rightleftharpoons}</m> ',
1.95 albertel 770: '<=> ');
1.75 albertel 771: }
772: next;
773: }
1.96 albertel 774: if ($token eq '.') {
775: $formula =~ s/(\ \;| )$//;
776: $formula .= '·';
777: next;
778: }
779: $token =~ /^\s*([\d|\/]*(?:&frac\d\d)?)(.*)/;
1.90 albertel 780: $formula .= $1 if ($1 ne '1'); # stoichiometric coefficient
1.75 albertel 781:
782: my $molecule = $2;
783: # subscripts
1.78 albertel 784: $molecule =~ s|(?<=[a-zA-Z\)\]\s])(\d+)|<sub>$1</sub>|g;
1.75 albertel 785: # superscripts
786: $molecule =~ s|\^(\d*[+\-]*)|<sup>$1</sup>|g;
787: # strip whitespace
788: $molecule =~ s/\s*//g;
789: # forced space
790: $molecule =~ s/_/ /g;
1.96 albertel 791: $molecule =~ s/-/−/g;
1.75 albertel 792: $formula .= $molecule.' ';
793: }
794: # get rid of trailing space
1.87 albertel 795: $formula =~ s/(\ \;| )$//;
1.75 albertel 796: return &xmlparse($formula);
797: }
798:
1.46 albertel 799: sub prettyprint {
1.73 albertel 800: my ($value,$fmt,$target)=@_;
801: my $result;
802: if (!$target) { $target = $external::target; }
1.75 albertel 803: if ($fmt =~ /chem/i) { return(&chemparse($value)); }
1.81 albertel 804: my ($dollarmode,$commamode,$alwaysperiod,$options);
805: if ($fmt =~ /^([^\d]*)(.*)/) { $options=$1; $fmt=$2; }
1.86 albertel 806: if ($options =~ /\$/) { $dollarmode=1; }
1.81 albertel 807: if ($options =~ /,/) { $commamode=1; }
808: if ($options =~ /\./) { $alwaysperiod=1; }
1.97 albertel 809: if ($fmt=~/s$/i) {
810: $value=&format_significant_figures($value,$fmt);
811: } elsif ($fmt) {
812: $value=sprintf('%.'.$fmt,$value);
813: }
1.81 albertel 814: if ($alwaysperiod && $fmt eq '0f') {
815: if ($target eq 'tex') {
816: $value .='\\ensuremath{.}';
817: } else {
818: $value .='.';
819: }
820: }
1.73 albertel 821: if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/i ) {
822: my $frac=$1;
823: if ($dollarmode) { $frac=&dollarformat($frac); }
1.80 albertel 824: if ($commamode) { $frac=&commaformat($frac); }
1.73 albertel 825: my $exponent=$2;
826: $exponent=~s/^\+0*//;
827: $exponent=~s/^-0*/-/;
828: $exponent=~s/^-0*/-/;
829: if ($exponent eq '-') { undef($exponent); }
830: if ($exponent) {
831: if ($target eq 'web') {
832: $result=$frac.'×10<sup>'.$exponent.'</sup>';
833: } elsif ($target eq 'tex') {
834: $result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
835: } else {
836: $result=$value;
837: }
838: } else {
839: $result=$frac;
840: }
841: } else {
1.48 albertel 842: $result=$value;
1.86 albertel 843: if ($dollarmode) { $result=&dollarformat($result,$target); }
844: elsif ($commamode) { $result=&commaformat($result,$target); }
1.46 albertel 845: }
1.73 albertel 846: return $result;
1.48 albertel 847: }
848:
1.80 albertel 849: sub commaformat {
1.73 albertel 850: my ($number,$target) = @_;
851: if ($number =~ /\./) {
1.102 albertel 852: while ($number =~ /([^0-9]*)([0-9]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) {
853: $number = $1.$2.','.$3.$4;
1.73 albertel 854: }
855: } else {
1.102 albertel 856: while ($number =~ /^([^0-9]*)([0-9]+)([^,][^,][^,])([,0-9]*)$/) {
857: $number = $1.$2.','.$3.$4;
1.73 albertel 858: }
859: }
1.80 albertel 860: return $number;
861: }
862:
863: sub dollarformat {
864: my ($number,$target) = @_;
865: if (!$target) { $target = $external::target; }
866: $number=&commaformat($number,$target);
1.73 albertel 867: if ($target eq 'tex') {
868: $number='\$'.$number; #' stupid emacs
869: } else {
870: $number='$'.$number; #' stupid emacs
871: }
872: return $number;
1.2 albertel 873: }
1.5 albertel 874:
1.97 albertel 875: # format of form ns or nS where n is an integer
876: sub format_significant_figures {
877: my ($number,$format) = @_;
878: return '0' if ($number == 0);
879: # extract number of significant figures needed
880: my ($sig) = ($format =~ /(\d+)s/i);
881: # arbitrary choice - suggestions ?? or throw error message?
882: $sig = 3 if ($sig eq '');
883: # save the minus sign
884: my $sign = ($number < 0) ? '-' : '';
885: $number = abs($number);
886: # needed to correct for a number greater than 1 (or
887: my $power = ($number < 1) ? 0 : 1;
888: # could round up. Take the integer part of log10.
889: my $x10 = int(log($number)/log(10));
890: # find number with values left of decimal pt = # of sign figs.
891: my $xsig = $number*10**($sig-$x10-$power);
892: # get just digits left of decimal pt - also rounds off correctly
893: my $xint = sprintf('%.0f',$xsig);
894: # save any trailing zero's
895: my ($zeros) = ($xint =~ /(0+)$/);
896: # return number to original magnitude
897: my $numSig = $xint*10**($x10-$sig+$power);
898: # insert trailing zero's if have decimal point
899: $numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/;
1.98 albertel 900: # put a decimal pt for number ending with 0 and length = # of sig fig
901: $numSig.='.' if (length($numSig) == $sig && $numSig =~ /0$/);
902: if (length($numSig) < $sig) {
903: $numSig.='.'.substr($zeros,0,($sig-length($numSig)));
904: }
1.97 albertel 905: # return number with sign
906: return $sign.$numSig;
907:
908: }
909:
1.5 albertel 910: sub map {
1.27 ng 911: my ($phrase,$dest,$source)=@_;
1.51 albertel 912: my @oldseed=&random_get_seed();
1.27 ng 913: my @seed = &random_seed_from_phrase($phrase);
914: &random_set_seed(@seed);
915: my $destct = scalar(@$dest);
1.28 ng 916: if (!$source) {
917: my @output;
918: my @idx = &math_random_permuted_index($destct);
919: my $ctr = 0;
920: while ($ctr < $destct) {
921: $output[$ctr] = $$dest[$idx[$ctr]];
1.27 ng 922: $ctr++;
1.28 ng 923: }
1.51 albertel 924: &random_set_seed(@oldseed);
1.28 ng 925: return @output;
1.27 ng 926: } else {
1.28 ng 927: my $num = scalar(@$source);
928: my @idx = &math_random_permuted_index($num);
929: my $ctr = 0;
930: my $tot = $num;
931: $tot = $destct if $destct < $num;
932: if (ref($$dest[0])) {
933: while ($ctr < $tot) {
934: ${$$dest[$ctr]} = $$source[$idx[$ctr]];
935: $ctr++;
936: }
937: } else {
938: while ($ctr < $tot) {
939: $$dest[$ctr] = $$source[$idx[$ctr]];
940: $ctr++;
941: }
942: }
1.27 ng 943: }
1.56 albertel 944: &random_set_seed(@oldseed);
1.51 albertel 945: return '';
1.27 ng 946: }
947:
948: sub rmap {
949: my ($phrase,$dest,$source)=@_;
1.51 albertel 950: my @oldseed=&random_get_seed();
1.27 ng 951: my @seed = &random_seed_from_phrase($phrase);
952: &random_set_seed(@seed);
953: my $destct = scalar(@$dest);
1.28 ng 954: if (!$source) {
955: my @idx = &math_random_permuted_index($destct);
956: my $ctr = 0;
957: my @r_idx;
958: while ($ctr < $destct) {
959: $r_idx[$idx[$ctr]] = $ctr;
960: $ctr++;
961: }
962: my @output;
963: $ctr = 0;
964: while ($ctr < $destct) {
965: $output[$ctr] = $$dest[$r_idx[$ctr]];
1.27 ng 966: $ctr++;
1.28 ng 967: }
1.51 albertel 968: &random_set_seed(@oldseed);
1.28 ng 969: return @output;
1.27 ng 970: } else {
1.28 ng 971: my $num = scalar(@$source);
972: my @idx = &math_random_permuted_index($num);
973: my $ctr = 0;
974: my $tot = $num;
975: $tot = $destct if $destct < $num;
976: my @r_idx;
1.27 ng 977: while ($ctr < $tot) {
1.28 ng 978: $r_idx[$idx[$ctr]] = $ctr;
1.27 ng 979: $ctr++;
1.28 ng 980: }
981: $ctr = 0;
982: if (ref($$dest[0])) {
983: while ($ctr < $tot) {
984: ${$$dest[$ctr]} = $$source[$r_idx[$ctr]];
985: $ctr++;
986: }
987: } else {
988: while ($ctr < $tot) {
989: $$dest[$ctr] = $$source[$r_idx[$ctr]];
990: $ctr++;
991: }
992: }
1.6 albertel 993: }
1.51 albertel 994: &random_set_seed(@oldseed);
995: return '';
1.5 albertel 996: }
1.22 ng 997:
1.23 ng 998: sub capa_id { return }
999:
1000: sub problem { return }
1001:
1.22 ng 1002: sub name{
1.73 albertel 1003: my $fullname = &EXT('environment.lastname').', '.&EXT('environment.firstname').' '.&EXT('environment.middlename');
1004: $fullname = "" if $fullname eq ", ";
1005: $fullname =~ s/\%2d/-/g;
1006: return $fullname;
1.22 ng 1007: }
1008:
1009: sub student_number {
1.73 albertel 1010: my $id = &EXT('environment.id');
1011: $id = '' if $id eq "";
1012: return $id;
1.22 ng 1013: }
1014:
1015: sub class {
1.73 albertel 1016: my $course = &EXT('course.description');
1017: $course = '' if $course eq "";
1018: return $course;
1.22 ng 1019: }
1020:
1.112 www 1021: sub firstname {
1022: my $firstname = &EXT('environment.firstname');
1023: $firstname = '' if $firstname eq "";
1024: return $firstname;
1025: }
1026:
1027: sub lastname {
1028: my $lastname = &EXT('environment.lastname');
1029: $lastname = '' if $lastname eq "";
1030: return $lastname;
1031: }
1032:
1.22 ng 1033: sub sec {
1.73 albertel 1034: my $sec = &EXT('request.course.sec');
1035: $sec = '' if $sec eq "";
1036: return $sec;
1.22 ng 1037: }
1038:
1.136 www 1039: sub submission {
1040: my ($partid,$responseid,$subnumber)=@_;
1041: my $sub='';
1042: if ($subnumber) { $sub=$subnumber.':'; }
1043: return &EXT('user.resource.'.$sub.'resource.'.$partid.'.'.$responseid.'.submission');
1044: }
1045:
1046: sub currentpart {
1047: return $external::part;
1048: }
1049:
1.135 www 1050: sub eval_time {
1051: my ($timestamp)=@_;
1052: unless ($timestamp) { return ''; }
1053: return &locallocaltime($timestamp);
1054: }
1055:
1.23 ng 1056: sub open_date {
1.134 www 1057: my ($partid)=@_;
1058: unless ($partid) { $partid=0; }
1.135 www 1059: return &eval_time(&EXT('resource.'.$partid.'.opendate'));
1.23 ng 1060: }
1061:
1.134 www 1062: sub due_date {
1063: my ($partid)=@_;
1064: unless ($partid) { $partid=0; }
1.135 www 1065: return &eval_time(&EXT('resource.'.$partid.'.duedate'));
1.23 ng 1066: }
1067:
1068: sub answer_date {
1.134 www 1069: my ($partid)=@_;
1070: unless ($partid) { $partid=0; }
1.135 www 1071: return &eval_time(&EXT('resource.'.$partid.'.answerdate'));
1.24 ng 1072: }
1073:
1.136 www 1074: sub open_date_epoch {
1075: my ($partid)=@_;
1076: unless ($partid) { $partid=0; }
1077: return &EXT('resource.'.$partid.'.opendate');
1078: }
1079:
1080: sub due_date_epoch {
1081: my ($partid)=@_;
1082: unless ($partid) { $partid=0; }
1083: return &EXT('resource.'.$partid.'.duedate');
1084: }
1085:
1086: sub answer_date_epoch {
1087: my ($partid)=@_;
1088: unless ($partid) { $partid=0; }
1089: return &EXT('resource.'.$partid.'.answerdate');
1090: }
1091:
1.24 ng 1092: sub array_moments {
1.73 albertel 1093: my @input=@_;
1094: my (@output,$N);
1095: $N=scalar (@input);
1096: $output[0]=$N;
1097: if ($N <= 1) {
1098: $output[1]=$input[0];
1099: $output[1]="Input array not defined" if ($N == 0);
1100: $output[2]="variance undefined for N<=1";
1101: $output[3]="skewness undefined for N<=1";
1102: $output[4]="kurtosis undefined for N<=1";
1103: return @output;
1104: }
1105: my $sum=0;
1106: foreach my $line (@input) {
1107: $sum+=$line;
1108: }
1109: $output[1] = $sum/$N;
1110: my ($x,$sdev,$var,$skew,$kurt) = 0;
1111: foreach my $line (@input) {
1112: $x=$line-$output[1];
1113: $var+=$x**2;
1114: $skew+=$x**3;
1115: $kurt+=$x**4;
1116: }
1117: $output[2]=$var/($N-1);
1118: $sdev=CORE::sqrt($output[2]);
1119: if ($sdev == 0) {
1120: $output[3]="inf-variance=0";
1121: $output[4]="inf-variance=0";
1122: return @output;
1123: }
1124: $output[3]=$skew/($sdev**3*$N);
1125: $output[4]=$kurt/($sdev**4*$N)-3;
1.24 ng 1126: return @output;
1127: }
1.5 albertel 1128:
1129: sub choose {
1.73 albertel 1130: my $num = $_[0];
1131: return $_[$num];
1.5 albertel 1132: }
1.23 ng 1133:
1.101 albertel 1134: #&sum1(1,$x,sub { &sum1($_[0],2*$_[0], sub { fact($_[0])**2 })});
1135: #sub sum1 {
1136: # my ($start,$end,$sub)=@_;
1137: # my $sum=0;
1138: # for (my $i=$start;$i<=$end;$i++) {
1139: # $sum+=&$sub($i);
1140: # }
1141: # return $sum
1142: #}
1143:
1144: #&sum2('a',1,$x,'&sum2(\'b\',$a,2*$a, \'&factorial($b)**2\')');
1145: #sub sum2 {
1146: # my ($varname,$start,$end,$line)=@_;
1147: # my $sum=0;
1148: # for (my $i=$start;$i<=$end;$i++) {
1149: # my $func=sub {
1150: # eval("\$".$varname."=$i");
1151: # eval($line);
1152: # };
1153: # $sum+=&$func($i);
1154: # }
1155: # return $sum
1156: #}
1157:
1.49 albertel 1158: # expiremental idea
1159: sub proper_path {
1.73 albertel 1160: my ($path)=@_;
1161: if ( $external::target eq "tex" ) {
1162: return '/home/httpd/html'.$path;
1163: } else {
1164: return $path;
1165: }
1.49 albertel 1166: }
1.23 ng 1167:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>