version 1.1, 2010/12/20 18:14:18
|
version 1.7, 2015/06/03 10:25:12
|
Line 1
|
Line 1
|
<problem> |
<problem> |
|
<parameter name="externalurl" type="string" description="URL for external testing" /> |
<script type="loncapa/perl"> |
<script type="loncapa/perl"> |
sub fact { |
sub fact { |
my $n=shift; |
my $n=shift; |
if ($n==1) { |
if ($n<=1) { |
return $n; |
return 1; |
} else { |
} else { |
return $n*&fact($n-1); |
return $n*&fact($n-1); |
} |
} |
} |
} |
|
|
$testvalues='0=1'; |
$testvalues='0=1'; |
for ($i=1,3) { |
foreach $i (1..3) { |
$rand=&random(3,8,1); |
$rand=&random(3,8,1); |
$testvalues.=','.$rand.'='.&fact($rand); |
$testvalues.=','.$rand.'='.&fact($rand); |
} |
} |
|
|
|
# |
|
# Set anything else you want to pass in this hash. |
|
# Name-value pairs will be passed as posted form parameters. |
|
# |
|
%args=('somecode' => (<<'ENDCODE') |
|
sub negative { |
|
my ($number)=@_; |
|
return $number<0; |
|
} |
|
ENDCODE |
|
); |
|
# Get a URL if it is externally set |
|
$externalurl=¶meter_setting('externalurl'); |
|
# |
|
# Important: set your default URL here |
|
# |
|
unless ($externalurl=~/\w/) { $externalurl='http://localhost/cgi-bin/sampleexternal.pl'; } |
|
# |
</script> |
</script> |
|
|
|
|
<startouttext />Write a Perl subroutine called <tt>factorial</tt>, which returns the factorial of its argument, e.g. <tt>&factorial(17)=17!</tt>. |
<startouttext />Write a Perl subroutine called <tt>factorial</tt>, which returns the factorial of its argument, e.g. <tt>&factorial(17)=17!</tt>. You can use the |
|
boolean function <tt>&negative(number)</tt>, which returns <tt>true</tt> if the argument is negative. |
<instructorcomment> |
<instructorcomment> |
Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment> |
Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment> |
<endouttext /> |
<endouttext /> |
<externalresponse url="http://localhost/cgi-bin/sampleexternal.pl" answer="$testvalues"> |
<externalresponse url="$externalurl" answer="$testvalues" form="%args" answerdisplay="The most elegant (and dangerous) solution is recursive."> |
<textfield /> |
<textfield></textfield> |
|
|
</externalresponse> |
</externalresponse> |
</problem> |
</problem> |