[LON-CAPA-users] prime factorization
Gerd Kortemeyer
lon-capa-users@mail.lon-capa.org
Wed, 19 Mar 2008 20:57:48 -0400
Hi,
I don't know the specifics of what your problem needs to do, but
oftentimes one can save *a lot* of computing time by randomizing the
solution, i.e., turn the problem upside turn when you generate it.
For example, you could have LON-CAPA randomly generate
3,3,5,7,13
and then present the student with
4095
The OR-type answer (unordered) might be a good way to request the
factors. Unfortunately, that gives away how many factors there are,
so another way to check the result might be a simple customresponse
that separates the answer-string by commas.
Here's an example:
<problem>
<script type="loncapa/perl">@primes=(2,3,5,7,11,13,17,19,23); # prime
numbers
$nfactors=&random(3,6,1); # number of factors
$number=1;
@factors=();
for ($i=1;$i<=$nfactors;$i++) {
$newprime=$primes[&random(0,$#primes,1)];
$number*=$newprime;
push(@factors,$newprime);
}
$answer=join(',',sort{$a<=>$b}(@factors));</script>
<startouttext />Factorize $number into primes. Separate the primes by
commas.<endouttext />
<customresponse answerdisplay="$answer">
<answer type="loncapa/perl"># We do not want a vector
if ($submission!~/^[\d\s\,]+$/) { return 'WANTED_NUMERIC'; }
@submission=sort(split(/\s*\,\s*/,$submission));
@answer=sort(@factors);
if ($#answer!=$#submission) { return 'INCORRECT'; }
for ($i=0;$i<=$#answer;$i++) {
if ($answer[$i]!=$submission[$i]) { return 'INCORRECT'; }
}
return 'EXACT_ANS';</answer>
<textline readonly="no" />
</customresponse>
</problem>
- Gerd.
On Mar 19, 2008, at 6:42 PM, Justin Gray wrote:
> Hi Peter,
>
> I would be very interested to know if you find a way of tackling
> this type of problem.
>
> Many thanks,
> Justin
>
> On Wed, Mar 19, 2008 at 3:36 PM, Peter Riegler <p.riegler@fh-
> wolfenbuettel.de> wrote:
> Hi Justen,
>
> although that won't help you immediately:
> In principle this is a simple problem using a computer algebra system
> (such as maxima in case of loncapa) if computer algebra systems
> were not
> carrying out numerical computations immediately and thus reverting any
> numerical factorization into a single number within giving the user
> any
> change to interfer.
> We have several problems of this type. Therefore I have currently a
> student working on this. It might end up in a special purpose maxima
> package. (Guy, forgive me if you are ever going to read this ...)
>
> Regards
>
> Peter
>
> Justin Gray wrote:
>
> > Does anyone know how to write a mathresponse problem with an answer
> > algorithm that will check whether an integer has been factored
> into primes?
> >
> > Justin
> >
> > --
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Justin Gray Tel. 778-782-4237
> > Dept. of Mathematics Fax. 778-782-4947
> > Simon Fraser University
> > 8888 University Drive
> > Burnaby, B.C. V5A 1S6
> > Canada
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> --
> Peter Riegler
> Fachhochschule Braunschweig/Wolfenbüttel
> Salzdahlumer Str. 46/48, 38302 Wolfenbüttel
> Tel. +49 5331 939 6314, Fax. +49 5331 939 6002
> email: p.riegler@fh-wolfenbuettel.de
> http://public.rz.fh-wolfenbuettel.de/~riegler
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Justin Gray Tel. 778-782-4237
> Dept. of Mathematics Fax. 778-782-4947
> Simon Fraser University
> 8888 University Drive
> Burnaby, B.C. V5A 1S6
> Canada
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~