Annotation of loncom/homework/templates/customhints.problem, revision 1.1

1.1     ! www         1: <problem>
        !             2: <script type="loncapa/perl"># Construct an Egyptian Fraction that can be represented by three terms with denominators between 3 and 12
        !             3: @denominators=(&random_permutation(&random(1,1000,1),(3..12)))[0..2];
        !             4: $egyptian='1/'.(join('+1/',sort{$a<=>$b}(@denominators)));
        !             5: $possible="A possible solution is $egyptian";
        !             6: 
        !             7: # Let the CAS figure out the value
        !             8: $solution=&cas('maxima',$egyptian);
        !             9: 
        !            10: # Subroutine that checks if the provided term is indeed an Egyptian Fraction
        !            11: sub analyze {
        !            12:     my ($expression)=@_;
        !            13:     $expression=~s/\s//gs;
        !            14:     $expression=~s/\+?1\//\,/gs;
        !            15:      if ($expression=~/^(\,[0-9]+)+$/) {
        !            16: # Format is indeed 1/n+1/m+...
        !            17:         $last=-1;
        !            18:         foreach $number (sort { $a<=>$b } split(/\,/,$expression)) {
        !            19: # Is a number used twice?
        !            20:              if ($last==$number) { return(0,1); }
        !            21:              $last=$number;
        !            22:           }
        !            23:           return(0,0);
        !            24:      }
        !            25:      return(1,0);
        !            26: }
        !            27: </script>
        !            28: 
        !            29: <startouttext />
        !            30: 
        !            31: Write $solution as an Egyptian Fraction<br />
        !            32: <endouttext />
        !            33: 
        !            34: <customresponse answerdisplay="$possible" id="11">
        !            35:     <answer type="loncapa/perl"># Analyze the format
        !            36: ($formaterror,$doubleerror)=&analyze($submission);
        !            37: if ($formaterror || $doubleerror) { return 'BAD_FORMULA'; }
        !            38: # It is an Egyptian Fraction, is the value correct?
        !            39: if (&cas('maxima',$submission.'-('.$egyptian.')') eq '0') {
        !            40:     return 'EXACT_ANS';
        !            41: }
        !            42: return 'INCORRECT';</answer>
        !            43:     <textline readonly="no" size="40" />
        !            44: 
        !            45:  <customhint name="format" id="12">
        !            46:       <answer type="loncapa/perl">if ((&analyze($submission))[0]) { return 'EXACT_ANS'; }
        !            47: return 'INCORRECT';</answer>
        !            48: </customhint>
        !            49: <hintpart on="format">
        !            50: <startouttext />
        !            51: <p>
        !            52: Egyptian Fractions have a format of 1/number+1/number+..., for example 1/3+1/17+1/52. 
        !            53: </p>
        !            54: <endouttext />
        !            55: </hintpart>
        !            56:  <customhint name="double" id="13">
        !            57:       <answer type="loncapa/perl">if ((&analyze($submission))[1]) { return 'EXACT_ANS'; }
        !            58: return 'INCORRECT';</answer>
        !            59: </customhint>
        !            60: <hintpart on="double">
        !            61: <startouttext />
        !            62: <p>
        !            63: Egyptian Fractions cannot have the same denominator more than once. For example, 1/3+1/17+1/4+/17 is not an Egyptian Fraction, as it has 17 twice as denominator.
        !            64: </p>
        !            65: <endouttext />
        !            66: </hintpart>
        !            67: </customresponse>
        !            68: </problem>
        !            69: 

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