[LON-CAPA-users] prime factorization
Justin Gray
lon-capa-users@mail.lon-capa.org
Wed, 19 Mar 2008 15:39:29 -0700
------=_Part_22073_13745795.1205966369968
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Many thanks for the Perl references.
Determining whether a polynomial is factored can be handled easily using
mathresponse. Here is an example:
<problem>
<script type="loncapa/perl">
$answer = "(x - 3)(x + 3)";
</script>
<startouttext />
Factor: <p></p>
<m>$x^2 - 9 = $</m>
<endouttext />
<mathresponse cas="maxima" answerdisplay="$answer" args="$answer">
<answer>is(RESPONSE[1] = LONCAPALIST[1]);</answer>
<textline readonly="no" size="40" />
</mathresponse>
</problem>
The above example will accept (x - 3)(x + 3) as correct but not x^2 - 9. :)
However, I do not know how to modify this problem to test whether an integer
has been factored into primes. The example below will accept 60 as a correct
answer. :(
<problem>
<script type="loncapa/perl">
$answer = "2^2*3*5";
</script>
<startouttext />
Find the prime factorization: <p></p>
<m>$60 = $</m>
<endouttext />
<mathresponse cas="maxima" answerdisplay="$answer" args="$answer">
<answer>is(RESPONSE[1] = LONCAPALIST[1]);</answer>
<textline readonly="no" size="40" />
</mathresponse>
</problem>
If anyone knows how I could modify the answer algorithm
<answer>is(RESPONSE[1] = LONCAPALIST[1]);</answer> so that only a complete
factorization of 60 is accepted I would be grateful.
Justin
On Tue, Mar 18, 2008 at 8:00 PM, Roy Vson <royvson@gmail.com> wrote:
> Justin: I don't have code to give you, but here are some citations with
> code
> Perl Cookbook, 2nd ed. pp 87-89
>
> Mastering Algorithms with Perl, pp505-510.
>
> Also, look at CPAN: google prime factors site:cpan.org.
>
> Have fun.
>
> Roy
>
>
> On Tue, Mar 18, 2008 at 9:14 PM, Justin Gray <jgray@math.sfu.ca> 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
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> _______________________________________________
> 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------=_Part_22073_13745795.1205966369968
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Many thanks for the Perl references. <br><br>Determining whether a polynomial is factored can be handled easily using mathresponse. Here is an example:<br><br><problem><br><script type="loncapa/perl"><br>
$answer = "(x - 3)(x + 3)";<br></script><br> <startouttext /><br>Factor: <p></p><br><br><m>$x^2 - 9 = $</m><br> <endouttext /><br><br> <mathresponse cas="maxima" answerdisplay="$answer" args="$answer"><br>
<answer>is(RESPONSE[1] = LONCAPALIST[1]);</answer><br><br> <br> <textline readonly="no" size="40" /><br> </mathresponse><br></problem><br><br><br>The above example will accept (x - 3)(x + 3) as correct but not x^2 - 9. :) <br>
<br>However, I do not know how to modify this problem to test whether an integer has been factored into primes. The example below will accept 60 as a correct answer. :(<br><br><br><problem><br><script type="loncapa/perl"><br>
$answer = "2^2*3*5";<br></script><br> <startouttext /><br>Find the prime factorization: <p></p><br><br><m>$60 = $</m><br> <endouttext /><br><br> <mathresponse cas="maxima" answerdisplay="$answer" args="$answer"><br>
<answer>is(RESPONSE[1] = LONCAPALIST[1]);</answer><br><br> <br> <textline readonly="no" size="40" /><br> </mathresponse><br></problem><br><br>If anyone knows how I could modify the answer algorithm
<answer>is(RESPONSE[1] = LONCAPALIST[1]);</answer> so that
only a complete factorization of 60 is accepted I would be grateful.<br><br>Justin<br><br><br><div class="gmail_quote">On Tue, Mar 18, 2008 at 8:00 PM, Roy Vson <<a href="mailto:royvson@gmail.com">royvson@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Justin: I don't have code to give you, but here are some citations with code<br>
Perl Cookbook, 2nd ed. pp 87-89<br>
<br>
Mastering Algorithms with Perl, pp505-510.<br>
<br>
Also, look at CPAN: google prime factors site:<a href="http://cpan.org" target="_blank">cpan.org</a>.<br>
<br>
Have fun.<br>
<br>
Roy<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
On Tue, Mar 18, 2008 at 9:14 PM, Justin Gray <<a href="mailto:jgray@math.sfu.ca">jgray@math.sfu.ca</a>> wrote:<br>
> Does anyone know how to write a mathresponse problem with an answer<br>
> algorithm that will check whether an integer has been factored into primes?<br>
><br>
> Justin<br>
><br>
> --<br>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
> Justin Gray Tel. 778-782-4237<br>
> Dept. of Mathematics Fax. 778-782-4947<br>
> Simon Fraser University<br>
> 8888 University Drive<br>
> Burnaby, B.C. V5A 1S6<br>
> Canada<br>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
</div></div>_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href="mailto:LON-CAPA-users@mail.lon-capa.org">LON-CAPA-users@mail.lon-capa.org</a><br>
<a href="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target="_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>Justin Gray Tel. 778-782-4237<br>Dept. of Mathematics Fax. 778-782-4947<br>Simon Fraser University<br>8888 University Drive<br>
Burnaby, B.C. V5A 1S6<br>Canada<br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------=_Part_22073_13745795.1205966369968--