<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Primes Problem in Python</title>
	<atom:link href="http://log.egamal.com/2010/02/primes-exceed-time-limit/feed/" rel="self" type="application/rss+xml" />
	<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/</link>
	<description>life.log()</description>
	<lastBuildDate>Sat, 31 Dec 2011 19:45:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: me</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7020</link>
		<dc:creator>me</dc:creator>
		<pubDate>Sat, 06 Feb 2010 12:54:58 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7020</guid>
		<description>Well, I knew that fact in the meeting, Ahmed Soliman told me That ..
And I tried that now and they both had the same id :)

BTW, The theme is Mac-like :)</description>
		<content:encoded><![CDATA[<p>Well, I knew that fact in the meeting, Ahmed Soliman told me That ..<br />
And I tried that now and they both had the same id <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>BTW, The theme is Mac-like <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KAM</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7018</link>
		<dc:creator>KAM</dc:creator>
		<pubDate>Sat, 06 Feb 2010 06:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7018</guid>
		<description>about the girlish thing , check this and it may give you some insights :)
http://www.23monkeys.com/designs/python


and another thing , even numerical and string data types have the same behavior and are implemented in the say way.
For Strings , it doesn&#039;t matter because they&#039;re immutable anyway so you can&#039;t see the effect of changing it somewhere and seeing this change every where through different variables referencing the same object.
and the same thing will apply for integers.

you can check this by
&lt;pre class=&#039;brush:python&#039;&gt;
x = &quot;test&quot;
y = x
print id(x)
print id(y)
&lt;/pre&gt;

:) .. BTW , i love the elegance of your theme.</description>
		<content:encoded><![CDATA[<p>about the girlish thing , check this and it may give you some insights <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<a href="http://www.23monkeys.com/designs/python" rel="nofollow">http://www.23monkeys.com/designs/python</a></p>
<p>and another thing , even numerical and string data types have the same behavior and are implemented in the say way.<br />
For Strings , it doesn&#8217;t matter because they&#8217;re immutable anyway so you can&#8217;t see the effect of changing it somewhere and seeing this change every where through different variables referencing the same object.<br />
and the same thing will apply for integers.</p>
<p>you can check this by</p>
<pre class='brush:python'>
x = "test"
y = x
print id(x)
print id(y)
</pre>
<p> <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .. BTW , i love the elegance of your theme.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: me</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7017</link>
		<dc:creator>me</dc:creator>
		<pubDate>Sat, 06 Feb 2010 03:13:57 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7017</guid>
		<description>well I didn&#039;t get the girlish thing, but it sounded like you meant the pythonic style that enforces less special characters including ampersand ..
Finally I always considered python data structures (tuple, list and dictionary) to be acting like numeric and string data types ..
But It sounds they are not .. and it sounds that PHP effect is still there ..
as PHP array used to be deeply copied in assignment ..
&lt;pre class=&#039;brush:php&#039;&gt;
$myArray = array(1,2,3);
$yourArray = $myArray ; // here $yourArray is new copy of $myArray .. &quot;deeply&quot; copied 
$yourArray[0] = 3;
$myArray[0] =2;
var_dump($myArray); // first element will be 2
var_dump($yourArray);//first element will be 3
&lt;/pre&gt;

Again thanks for your participation KAM :)</description>
		<content:encoded><![CDATA[<p>well I didn&#8217;t get the girlish thing, but it sounded like you meant the pythonic style that enforces less special characters including ampersand ..<br />
Finally I always considered python data structures (tuple, list and dictionary) to be acting like numeric and string data types ..<br />
But It sounds they are not .. and it sounds that PHP effect is still there ..<br />
as PHP array used to be deeply copied in assignment ..</p>
<pre class='brush:php'>
$myArray = array(1,2,3);
$yourArray = $myArray ; // here $yourArray is new copy of $myArray .. "deeply" copied
$yourArray[0] = 3;
$myArray[0] =2;
var_dump($myArray); // first element will be 2
var_dump($yourArray);//first element will be 3
</pre>
<p>Again thanks for your participation KAM <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KAM</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7014</link>
		<dc:creator>KAM</dc:creator>
		<pubDate>Fri, 05 Feb 2010 16:31:11 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7014</guid>
		<description>&quot;So first of all did you expected that .. from Python behavior .. ?&quot;

Maybe python&#039;s everything-is-so-easy behavior may tell you that it&#039;s assigning by value but - a big one is coming - think again , what would things be like if you are assigning by value ? Things will be OK until you need a reference to your objects - as in passing by reference - so python will have to give developers some way to extract the reference - yeah i know pointers and the big &quot;&amp;&quot; is popping up now - and Oops we are hit again by the complex and hazardous pointer programming which some programmers hate - those girls - and we have noway to avoid it.
Now think of the world with assign by reference :) , it&#039;s a pretty nice and girlish one.

The same behavior exist in Java and i&#039;m sure it&#039;ll be in every other programming language that wants to avoid the pointer programming - unless i&#039;m mistaken-.</description>
		<content:encoded><![CDATA[<p>&#8220;So first of all did you expected that .. from Python behavior .. ?&#8221;</p>
<p>Maybe python&#8217;s everything-is-so-easy behavior may tell you that it&#8217;s assigning by value but &#8211; a big one is coming &#8211; think again , what would things be like if you are assigning by value ? Things will be OK until you need a reference to your objects &#8211; as in passing by reference &#8211; so python will have to give developers some way to extract the reference &#8211; yeah i know pointers and the big &#8220;&amp;&#8221; is popping up now &#8211; and Oops we are hit again by the complex and hazardous pointer programming which some programmers hate &#8211; those girls &#8211; and we have noway to avoid it.<br />
Now think of the world with assign by reference <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  , it&#8217;s a pretty nice and girlish one.</p>
<p>The same behavior exist in Java and i&#8217;m sure it&#8217;ll be in every other programming language that wants to avoid the pointer programming &#8211; unless i&#8217;m mistaken-.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: me</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7013</link>
		<dc:creator>me</dc:creator>
		<pubDate>Fri, 05 Feb 2010 13:13:29 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7013</guid>
		<description>http://www.lastengine.com/syntax-highlighter-wordpress-plugin/#usage

Check this page for how to use the syntax highlighter ..
I don&#039;t want to search any pre-known algorithms before running out of trials :)

Thanks for your help :)</description>
		<content:encoded><![CDATA[<p><a href="http://www.lastengine.com/syntax-highlighter-wordpress-plugin/#usage" rel="nofollow">http://www.lastengine.com/syntax-highlighter-wordpress-plugin/#usage</a></p>
<p>Check this page for how to use the syntax highlighter ..<br />
I don&#8217;t want to search any pre-known algorithms before running out of trials <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks for your help <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KAM</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7012</link>
		<dc:creator>KAM</dc:creator>
		<pubDate>Fri, 05 Feb 2010 13:06:01 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7012</guid>
		<description>Just a question , how do you write your code with syntax high-lighting enabled in you blog ?( is it just [code][/code] ? ) .

And by the way , Prime Number Generation is a huge topic and a topic under research for centuries . So , yes there must be a better solution. :)</description>
		<content:encoded><![CDATA[<p>Just a question , how do you write your code with syntax high-lighting enabled in you blog ?( is it just [code][/code] ? ) .</p>
<p>And by the way , Prime Number Generation is a huge topic and a topic under research for centuries . So , yes there must be a better solution. <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: me</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7011</link>
		<dc:creator>me</dc:creator>
		<pubDate>Fri, 05 Feb 2010 12:46:39 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7011</guid>
		<description>Again ..
time limit exceeded	-	 4.9M memory usage :(

BTW, someone -using C#- had time limit exceed and 14 M memory usage :)

There must be a better solution
Thanks KAM I Saved .2 Mega</description>
		<content:encoded><![CDATA[<p>Again ..<br />
time limit exceeded	-	 4.9M memory usage <img src='http://log.egamal.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>BTW, someone -using C#- had time limit exceed and 14 M memory usage <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There must be a better solution<br />
Thanks KAM I Saved .2 Mega</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: me</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7010</link>
		<dc:creator>me</dc:creator>
		<pubDate>Fri, 05 Feb 2010 12:33:17 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7010</guid>
		<description>Thanks for your comment ..
So first of all did you expected that .. from Python behavior .. ?
2,3
Reason of doing that is I&#039;m thinking of using this list in next time .. I generate primes..
Anyway:
Check that:
&lt;pre class=&quot;brush:python&quot;&gt;
times = input()
while times &gt; 0:
    times -= 1
    limits = raw_input()
    limits = limits.split(&quot; &quot;)
    downLimit = int(limits[0])
    upLimit = int(limits[1])
    numsList = []
    if downLimit &lt;= 2:
        numsList = [i for i in range(2,upLimit) if  i == 2 or i % 2]
    else:
        numsList = [i for i in range(downLimit,upLimit) if  i % 2 ]

    for oddNumber in numsList:
        primeNumber = True;
        for number in range( 2 , oddNumber / 2):
            if oddNumber % number == 0:
                primeNumber = False;
                break;
        
        if primeNumber:
            print oddNumber

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for your comment ..<br />
So first of all did you expected that .. from Python behavior .. ?<br />
2,3<br />
Reason of doing that is I&#8217;m thinking of using this list in next time .. I generate primes..<br />
Anyway:<br />
Check that:</p>
<pre class="brush:python">
times = input()
while times > 0:
    times -= 1
    limits = raw_input()
    limits = limits.split(" ")
    downLimit = int(limits[0])
    upLimit = int(limits[1])
    numsList = []
    if downLimit < = 2:
        numsList = [i for i in range(2,upLimit) if  i == 2 or i % 2]
    else:
        numsList = [i for i in range(downLimit,upLimit) if  i % 2 ]

    for oddNumber in numsList:
        primeNumber = True;
        for number in range( 2 , oddNumber / 2):
            if oddNumber % number == 0:
                primeNumber = False;
                break;

        if primeNumber:
            print oddNumber
</pre>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: KAM</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7009</link>
		<dc:creator>KAM</dc:creator>
		<pubDate>Fri, 05 Feb 2010 12:15:04 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7009</guid>
		<description>Just to clarify , &quot;in point 3&quot; - mine not yours - loop here as in &quot;while&quot; loop.</description>
		<content:encoded><![CDATA[<p>Just to clarify , &#8220;in point 3&#8243; &#8211; mine not yours &#8211; loop here as in &#8220;while&#8221; loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KAM</title>
		<link>http://log.egamal.com/2010/02/primes-exceed-time-limit/comment-page-1/#comment-7008</link>
		<dc:creator>KAM</dc:creator>
		<pubDate>Fri, 05 Feb 2010 12:11:42 +0000</pubDate>
		<guid isPermaLink="false">http://log.egamal.com/?p=241#comment-7008</guid>
		<description>hehe .. exceeds the time limit :) .. it should.

First about your first note:
&quot;python-strangely&quot; :D  ... Actually , i can say &quot;AlSayedGamal - strangely - haven&#039;t already known about that yet :)&quot;

Second some obvious - and stupid - optimizations:

1 -
numsList = [i for i in range(downLimit,upLimit) if (i%2 or i==2) and i != 1 and i!=0]
do you know that you&#039;re asking every single element in the list created by range(x,y) if it&#039;s 1 and if it&#039;s 0 and if it&#039;s 2 .. is it possible to have more than 0 , 1 , 2 elements .... just start from 3 and then include 2 later ( of course after checking you downLimit to see where should you start )

2 -
if not primeNumber:
            primesList.remove( oddNumber )
begad alot of time will be wasted here (unless python&#039;s implementation is caching the last list accesses :), you can just print the primes - and this is exactly what you did later :D - since the list itself is of no good later

if primeNumber:
            print THE_PRIME

3 - Use another approach
Just keep incrementing from your donwLimit to your upLimit in a loop and do all the possible checks in a nested loop - which will safe you the overhead of creating a zillion list.</description>
		<content:encoded><![CDATA[<p>hehe .. exceeds the time limit <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .. it should.</p>
<p>First about your first note:<br />
&#8220;python-strangely&#8221; <img src='http://log.egamal.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />   &#8230; Actually , i can say &#8220;AlSayedGamal &#8211; strangely &#8211; haven&#8217;t already known about that yet <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8221;</p>
<p>Second some obvious &#8211; and stupid &#8211; optimizations:</p>
<p>1 -<br />
numsList = [i for i in range(downLimit,upLimit) if (i%2 or i==2) and i != 1 and i!=0]<br />
do you know that you&#8217;re asking every single element in the list created by range(x,y) if it&#8217;s 1 and if it&#8217;s 0 and if it&#8217;s 2 .. is it possible to have more than 0 , 1 , 2 elements &#8230;. just start from 3 and then include 2 later ( of course after checking you downLimit to see where should you start )</p>
<p>2 -<br />
if not primeNumber:<br />
            primesList.remove( oddNumber )<br />
begad alot of time will be wasted here (unless python&#8217;s implementation is caching the last list accesses <img src='http://log.egamal.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> , you can just print the primes &#8211; and this is exactly what you did later <img src='http://log.egamal.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  &#8211; since the list itself is of no good later</p>
<p>if primeNumber:<br />
            print THE_PRIME</p>
<p>3 &#8211; Use another approach<br />
Just keep incrementing from your donwLimit to your upLimit in a loop and do all the possible checks in a nested loop &#8211; which will safe you the overhead of creating a zillion list.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

