<br><br><div class="gmail_quote">On Wed, Sep 29, 2010 at 1:15 AM, rog <span dir="ltr"><<a href="mailto:rog@pynguins.com">rog@pynguins.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Shashwat Anand wrote:<div><div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On Wed, Sep 29, 2010 at 12:14 AM, Rog <<a href="mailto:rog@pynguins.com" target="_blank">rog@pynguins.com</a> <mailto:<a href="mailto:rog@pynguins.com" target="_blank">rog@pynguins.com</a>>> wrote:<br>
<br>
    Hi all,<br>
    Have been grappling with a list problem for hours...<br>
    a = [2, 3, 4, 5,.....]<br>
    b = [4, 8, 2, 6,.....]<br>
    Basicly I am trying to place a[0], b[0] in a seperate list<br>
    IF a[2] and b[2] is present.<br>
<br>
<br>
You are not exactly clear with your problem statement.<br>
Care to elaborate it more.<br>
<br>
    I have tried sets, zip etc with no success.<br>
    I am tackling Euler projects with Python 3.1, with minimal<br>
    knowledge, and having to tackle the language as I progress.<br>
    Enjoyable frustration :)<br>
<br>
    --<br>
    Rog<br>
    <a href="http://www.rog.pynguins.com" target="_blank">http://www.rog.pynguins.com</a><br>
    --<br>
    <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br>
<br>
<br>
<br>
-- <br>
~l0nwlf<br>
</blockquote>
<br></div></div>
"Let d(/n/) be defined as the sum of proper divisors of /n/ (numbers less than /n/ which divide evenly into /n/).<br>
If d(/a/) = /b/ and d(/b/) = /a/, where /a/ ≠ /b/, then /a/ and /b/ are an amicable pair and each of /a/ and /b/ are called amicable numbers.<br>
<br>
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.<br>
<br>
Evaluate the sum of all the amicable numbers under 10000."<br>
<br>
from Project Euler.<br>
I have all answers contained in two lists but need to extract the amicable pairs.<br>
eg<br>
a = [200, 4, 284,.....]<br>
b = [284, 9, 200, ......]<br>
Hope that helps.<br>
Thanks for the link.<br></blockquote><div><br></div><div>I am not sure how and what you managed, but what I understand you need to calculate sum of divisors.</div><div>A quick unoptimized solution can be,</div><div><br></div>

<div><span class="Apple-style-span" style="font-family: Times; font-size: medium; line-height: 17px; "><pre style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.1em; font-family: monospace; ">

<span class="o">>>></span> <span class="k" style="line-height: 13px; color: rgb(0, 51, 204); font-weight: bold; ">def</span> <span class="nf">divsum</span><span class="p">(</span><span class="n">n</span><span class="p">):</span><span class="k" style="line-height: 13px; color: rgb(0, 51, 204); font-weight: bold; ">return</span> <span class="nb" style="line-height: 13px; color: rgb(0, 170, 170); ">sum</span><span class="p">(</span><span class="n">i</span> <span class="k" style="line-height: 13px; color: rgb(0, 51, 204); font-weight: bold; ">for</span> <span class="n">i</span> <span class="ow" style="line-height: 13px; color: rgb(51, 102, 255); ">in</span> <span class="nb" style="line-height: 13px; color: rgb(0, 170, 170); ">range</span><span class="p">(</span><span class="mi" style="line-height: 13px; color: rgb(0, 0, 0); ">1</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span class="k" style="line-height: 13px; color: rgb(0, 51, 204); font-weight: bold; ">if</span> <span class="ow" style="line-height: 13px; color: rgb(51, 102, 255); ">not</span> <span class="n">n</span> <span class="o">%</span> <span class="n">i</span><span class="p">)</span>
<span class="o">...</span> 
<span class="o">>>></span> <span class="n">divsum</span><span class="p">(</span><span class="mi" style="line-height: 13px; color: rgb(0, 0, 0); ">220</span><span class="p">)</span>
<span class="mi" style="line-height: 13px; color: rgb(0, 0, 0); ">284</span>
<span class="o">>>></span> <span class="n">divsum</span><span class="p">(</span><span class="mi" style="line-height: 13px; color: rgb(0, 0, 0); ">284</span><span class="p">)</span>
<span class="mi" style="line-height: 13px; color: rgb(0, 0, 0); ">220</span></pre><pre style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.1em; font-family: monospace; ">

<span class="mi" style="line-height: 13px; color: rgb(0, 0, 0); "><br></span></pre></span></div><div>Now all is left is looping and little maths, since upper bound is not high, brute force is Ok.</div><div><br></div><div>

<spoiler> <a href="http://codepad.org/g6PRyoiV">http://codepad.org/g6PRyoiV</a> </spoiler>  # For reference</div><div><div><br></div></div><div>Also I guess you missed 'Reply All', please take care of it next time.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888">
Rog<br>
<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>~l0nwlf<br>