1: <problem>
2: <script type="loncapa/perl">
3: sub fact {
4: my $n=shift;
5: if ($n==1) {
6: return $n;
7: } else {
8: return $n*&fact($n-1);
9: }
10: }
11:
12: $testvalues='0=1';
13: foreach $i (1..3) {
14: $rand=&random(3,8,1);
15: $testvalues.=','.$rand.'='.&fact($rand);
16: }
17:
18: %args=('somecode' => (<<'ENDCODE')
19: sub negative {
20: my ($number)=@_;
21: return $number<0;
22: }
23: ENDCODE
24: );
25:
26:
27: </script>
28:
29:
30: <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
31: boolean function <tt>&negative(number)</tt>, which returns <tt>true</tt> if the argument is negative.
32: <instructorcomment>
33: Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment>
34: <endouttext />
35: <externalresponse url="http://localhost/cgi-bin/sampleexternal.pl" answer="$testvalues" form="%args" answerdisplay="The most elegant (and dangerous) solution is recursive.">
36: <textfield />
37:
38: </externalresponse>
39: </problem>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>