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

1.1       www         1: <problem>
1.5       www         2: <parameter name="externalurl" type="string" description="URL for external testing" />
1.1       www         3: <script type="loncapa/perl">
                      4: sub fact {
                      5:    my $n=shift;
1.7     ! droeschl    6:    if ($n<=1) {
        !             7:       return 1;
1.1       www         8:    } else {
                      9:       return $n*&fact($n-1);
                     10:    }
                     11: }
                     12: 
                     13: $testvalues='0=1';
1.2       www        14: foreach $i (1..3) {
1.1       www        15:    $rand=&random(3,8,1);
                     16:    $testvalues.=','.$rand.'='.&fact($rand);
                     17: }
1.4       www        18: 
1.5       www        19: #
                     20: # Set anything else you want to pass in this hash.
                     21: # Name-value pairs will be passed as posted form parameters.
                     22: #
1.4       www        23: %args=('somecode' => (<<'ENDCODE')
                     24: sub negative {
                     25:    my ($number)=@_;
                     26:    return $number<0;
                     27: }
                     28: ENDCODE
                     29: );
1.5       www        30: # Get a URL if it is externally set
                     31: $externalurl=&parameter_setting('externalurl');
                     32: #
                     33: # Important: set your default URL here
                     34: #
                     35: unless ($externalurl=~/\w/) { $externalurl='http://localhost/cgi-bin/sampleexternal.pl'; }
                     36: #
1.1       www        37: </script>
                     38: 
                     39: 
1.4       www        40: <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
                     41: boolean function <tt>&amp;negative(number)</tt>, which returns <tt>true</tt> if the argument is negative.
1.1       www        42: <instructorcomment>
                     43: Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment>
                     44: <endouttext />
1.5       www        45: <externalresponse url="$externalurl" answer="$testvalues" form="%args" answerdisplay="The most elegant (and dangerous) solution is recursive.">
1.6       bisitz     46: <textfield></textfield>
1.1       www        47: 
                     48: </externalresponse>
                     49: </problem>

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