# [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 />

<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

<problem>
<script type="loncapa/perl">
</script>
<startouttext />
Find the prime factorization: <p></p>

<m>\$60 = \$</m>
<endouttext />

<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
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> _______________________________________________
> 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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

------=_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>&lt;problem&gt;<br>&lt;script type=&quot;loncapa/perl&quot;&gt;<br>
\$answer = &quot;(x - 3)(x + 3)&quot;;<br>&lt;/script&gt;<br>&nbsp;&nbsp;&nbsp; &lt;startouttext /&gt;<br>Factor: &lt;p&gt;&lt;/p&gt;<br><br>&lt;m&gt;\$x^2 - 9 = \$&lt;/m&gt;<br>&nbsp;&nbsp;&nbsp; &lt;endouttext /&gt;<br><br>&nbsp;&nbsp;&nbsp; &lt;mathresponse cas=&quot;maxima&quot; answerdisplay=&quot;\$answer&quot; args=&quot;\$answer&quot;&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;answer&gt;is(RESPONSE[1] = LONCAPALIST[1]);&lt;/answer&gt;<br><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;textline readonly=&quot;no&quot; size=&quot;40&quot; /&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/mathresponse&gt;<br>&lt;/problem&gt;<br><br><br>The above example will accept (x - 3)(x + 3) as correct but not x^2 - 9.&nbsp; :) <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.&nbsp; :(<br><br><br>&lt;problem&gt;<br>&lt;script type=&quot;loncapa/perl&quot;&gt;<br>
\$answer = &quot;2^2*3*5&quot;;<br>&lt;/script&gt;<br>&nbsp;&nbsp;&nbsp; &lt;startouttext /&gt;<br>Find the prime factorization: &lt;p&gt;&lt;/p&gt;<br><br>&lt;m&gt;\$60 = \$&lt;/m&gt;<br>&nbsp;&nbsp;&nbsp; &lt;endouttext /&gt;<br><br>&nbsp;&nbsp;&nbsp; &lt;mathresponse cas=&quot;maxima&quot; answerdisplay=&quot;\$answer&quot; args=&quot;\$answer&quot;&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;answer&gt;is(RESPONSE[1] = LONCAPALIST[1]);&lt;/answer&gt;<br><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;textline readonly=&quot;no&quot; size=&quot;40&quot; /&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/mathresponse&gt;<br>&lt;/problem&gt;<br><br>If anyone knows how I could modify the answer algorithm
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 &lt;<a href="mailto:royvson@gmail.com">royvson@gmail.com</a>&gt; 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: &nbsp;I don&#39;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: &nbsp; &nbsp;google &nbsp;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 &lt;<a href="mailto:jgray@math.sfu.ca">jgray@math.sfu.ca</a>&gt; wrote:<br>
&gt; Does anyone know how to write a mathresponse problem with an answer<br>
&gt; algorithm that will check whether an integer has been factored into primes?<br>
&gt;<br>
&gt; Justin<br>
&gt;<br>
&gt; --<br>
&gt; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
&gt; &nbsp;Justin Gray Tel. 778-782-4237<br>
&gt; Dept. of Mathematics Fax. 778-782-4947<br>
&gt; Simon Fraser University<br>
&gt; 8888 University Drive<br>
&gt; Burnaby, B.C. V5A 1S6<br>