File:
[LON-CAPA] /
loncom /
homework /
templates /
customhints.problem
Revision
1.3:
download - view:
text,
annotated -
select for diffs
Sun Oct 31 12:33:08 2010 UTC (14 years, 1 month ago) by
www
Branches:
MAIN
CVS tags:
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
HEAD,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
Better return codes
<problem>
<script type="loncapa/perl"># Construct an Egyptian Fraction that can be represented by three terms with denominators between 3 and 12
@denominators=(&random_permutation(&random(1,1000,1),(3..12)))[0..2];
$egyptian='1/'.(join('+1/',sort{$a<=>$b}(@denominators)));
$possible="A possible solution is $egyptian";
# Let the CAS figure out the value
$solution=&cas('maxima',$egyptian);
# Subroutine that checks if the provided term is indeed an Egyptian Fraction
sub analyze {
my ($expression)=@_;
$expression=~s/\s//gs;
$expression=~s/\+?1\//\,/gs;
if ($expression=~/^(\,[0-9]+)+$/) {
# Format is indeed 1/n+1/m+...
$last=-1;
foreach $number (sort { $a<=>$b } split(/\,/,$expression)) {
# Is a number used twice?
if ($last==$number) { return(0,1); }
$last=$number;
}
return(0,0);
}
return(1,0);
}
</script>
<startouttext />
Write $solution as an Egyptian Fraction<br />
<endouttext />
<customresponse answerdisplay="$possible" id="11">
<answer type="loncapa/perl"># Analyze the format
($formaterror,$doubleerror)=&analyze($submission);
if ($formaterror || $doubleerror) { return 'WRONG_FORMAT'; }
# It is an Egyptian Fraction, is the value correct?
if (&cas('maxima',$submission.'-('.$egyptian.')') eq '0') {
return 'EXACT_ANS';
}
return 'INCORRECT';</answer>
<textline readonly="no" size="40" />
<customhint name="format" id="12">
<answer type="loncapa/perl">if ((&analyze($submission))[0]) { return 'EXACT_ANS'; }
return 'INCORRECT';</answer>
</customhint>
<hintpart on="format">
<startouttext />
<p>
Egyptian Fractions have a format of 1/number+1/number+..., for example 1/3+1/17+1/52.
</p>
<endouttext />
</hintpart>
<customhint name="double" id="13">
<answer type="loncapa/perl">if ((&analyze($submission))[1]) { return 'EXACT_ANS'; }
return 'INCORRECT';</answer>
</customhint>
<hintpart on="double">
<startouttext />
<p>
Egyptian Fractions cannot have the same denominator more than once. For example, 1/3+1/17+1/4+1/17 is not an Egyptian Fraction, as it has 17 twice as denominator.
</p>
<endouttext />
</hintpart>
</customresponse>
</problem>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>