Annotation of loncom/homework/templates/sampleexternal.problem, revision 1.4

1.1       www         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';
1.2       www        13: foreach $i (1..3) {
1.1       www        14:    $rand=&random(3,8,1);
                     15:    $testvalues.=','.$rand.'='.&fact($rand);
                     16: }
1.4     ! www        17: 
        !            18: %args=('somecode' => (<<'ENDCODE')
        !            19: sub negative {
        !            20:    my ($number)=@_;
        !            21:    return $number<0;
        !            22: }
        !            23: ENDCODE
        !            24: );
        !            25: 
        !            26: 
1.1       www        27: </script>
                     28: 
                     29: 
1.4     ! www        30: <startouttext />Write a Perl subroutine called <tt>factorial</tt>, which returns the factorial of its argument, e.g. <tt>&amp;factorial(17)=17!</tt>. You can use the
        !            31: boolean function <tt>&amp;negative(number)</tt>, which returns <tt>true</tt> if the argument is negative.
1.1       www        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 />
1.4     ! www        35: <externalresponse url="http://localhost/cgi-bin/sampleexternal.pl" answer="$testvalues" form="%args" answerdisplay="The most elegant (and dangerous) solution is recursive.">
1.1       www        36: <textfield />
                     37: 
                     38: </externalresponse>
                     39: </problem>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>