<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zhtlancer&#039;s blog &#187; Project Eular</title>
	<atom:link href="http://zhtlancer.com/category/algorithm/project-eular/feed/" rel="self" type="application/rss+xml" />
	<link>http://zhtlancer.com</link>
	<description>alpha...</description>
	<lastBuildDate>Mon, 16 Jan 2012 17:10:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Project Eular #4 #5 #6 (Python)</title>
		<link>http://zhtlancer.com/2010/02/project-eular-4-5-6-python/</link>
		<comments>http://zhtlancer.com/2010/02/project-eular-4-5-6-python/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 04:21:20 +0000</pubDate>
		<dc:creator>zhtlancer</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Project Eular]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zhtlancer.com/?p=47599</guid>
		<description><![CDATA[接着扫四道水题 #4 Find the largest palindrome made from the product of two 3-digit numbers. A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. #!/usr/bin/env python biggest = [...]]]></description>
			<content:encoded><![CDATA[<p>接着扫四道水题<br />
<strong><a href="http://projecteuler.net/index.php?section=problems&#038;id=4" target="_blank" onclick="pageTracker._trackPageview('/outgoing/projecteuler.net/index.php?section=problems_038_id=4&amp;referer=');">#4 Find the largest palindrome made from the product of two 3-digit numbers.</a></strong></p>
<blockquote><p>
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.</p>
<p>Find the largest palindrome made from the product of two 3-digit numbers.
</p></blockquote>
<pre name="code" class="python">
#!/usr/bin/env python

biggest = 0

def isPalindromic(num):
    num_str = str(num)
    num_halflen = len(num_str)/2
    for idx in range(0, num_halflen):
        if num_str[idx] != num_str[-(idx+1)]:
            return False
    return True

for x in range(100, 999):
    for y in range(100, 999):
        if isPalindromic(x*y) and x*y > biggest:
            biggest = x*y

print biggest
</pre>
<p><strong><a href="http://projecteuler.net/index.php?section=problems&#038;id=5" target="_blank" onclick="pageTracker._trackPageview('/outgoing/projecteuler.net/index.php?section=problems_038_id=5&amp;referer=');">#5 What is the smallest number divisible by each of the numbers 1 to 20?</a></strong></p>
<blockquote><p>
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.</p>
<p>What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?
</p></blockquote>
<pre name="code" class="python">
#!/usr/bin/env python

def isPrimeUnder20(num):
    for tmp in range(2, num):
        if num%tmp == 0:
            return False
    return True

factor_list = []

for x in range(2, 20):
    if isPrimeUnder20(x):
        power_x = 1
        while x**power_x <= 20:
            power_x += 1
        factor_list.append(x**(power_x-1))
        print x,power_x-1

prod = 1
for x in factor_list:
    prod *= x

print prod
</pre>
<p><strong><a href="http://projecteuler.net/index.php?section=problems&#038;id=6" target="_blank" onclick="pageTracker._trackPageview('/outgoing/projecteuler.net/index.php?section=problems_038_id=6&amp;referer=');">#6 What is the difference between the sum of the squares and the square of the sums?</a></strong></p>
<blockquote><p>
The sum of the squares of the first ten natural numbers is,<br />
1^(2) + 2^(2) + ... + 10^(2) = 385</p>
<p>The square of the sum of the first ten natural numbers is,<br />
(1 + 2 + ... + 10)^(2) = 55^(2) = 3025</p>
<p>Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.</p>
<p>Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
</p></blockquote>
<pre name="code" class="python">
#!/usr/bin/env python

sum_of_square = 0
for x in range(1, 101):
    sum_of_square += x**2

sum_tmp = 0
for x in range(1, 101):
    sum_tmp += x
square_of_sum = sum_tmp**2

delta = square_of_sum - sum_of_square
print delta
</pre>
<hr />
<p><small>© zhtlancer for <a href="http://zhtlancer.com">zhtlancer&#039;s blog</a>, 2010. |
<a href="http://zhtlancer.com/2010/02/project-eular-4-5-6-python/">Permalink</a> |
<a href="http://zhtlancer.com/2010/02/project-eular-4-5-6-python/#comments">暂无评论</a> |
Add to
<a href="http://del.icio.us/post?url=http://zhtlancer.com/2010/02/project-eular-4-5-6-python/&title=Project Eular #4 #5 #6 (Python)" onclick="pageTracker._trackPageview('/outgoing/del.icio.us/post?url=http_//zhtlancer.com/2010/02/project-eular-4-5-6-python/_title=Project_Eular_4_5_6_Python&amp;referer=');">del.icio.us</a>
<br/>
Post tags: <a href="http://zhtlancer.com/tag/algorithm/" rel="tag">Algorithm</a>, <a href="http://zhtlancer.com/tag/project-eular/" rel="tag">Project Eular</a>, <a href="http://zhtlancer.com/tag/python/" rel="tag">Python</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://zhtlancer.com/2010/02/project-eular-4-5-6-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Eular #3 (Python)</title>
		<link>http://zhtlancer.com/2010/01/project-eular-3-python/</link>
		<comments>http://zhtlancer.com/2010/01/project-eular-3-python/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 04:49:16 +0000</pubDate>
		<dc:creator>zhtlancer</dc:creator>
				<category><![CDATA[Project Eular]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Algorithm]]></category>

		<guid isPermaLink="false">http://zhtlancer.com/?p=47597</guid>
		<description><![CDATA[好久没有动这个了，今天再扫一道水题。 Find the largest prime factor of a composite number. The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 题目的数据规模很小，所以可以直接偷懒穷举，so… #!/usr/bin/env python num = 600851475143 seg_size = 10000 base_factor = 0 prime_factors = [] while base_factor*seg_size < num: for tmp in range(seg_size*base_factor, [...]]]></description>
			<content:encoded><![CDATA[<p>好久没有动这个了，今天再扫一道水题。</p>
<blockquote><p>
<strong>Find the largest prime factor of a composite number.</strong><br />
The prime factors of 13195 are 5, 7, 13 and 29.<br />
What is the largest prime factor of the number 600851475143 ?
</p></blockquote>
<p>题目的数据规模很小，所以可以直接偷懒穷举，so…</p>
<pre name="code" class="python">
#!/usr/bin/env python  

num = 600851475143
seg_size = 10000
base_factor = 0
prime_factors = []

while base_factor*seg_size < num:
    for tmp in range(seg_size*base_factor, seg_size*(base_factor+1)):
        if tmp>1 and num%tmp == 0:
            prime_factors.append(tmp)
            while num%tmp == 0:
                num = num / tmp
            print "num:",num," ",tmp
        base_factor = base_factor + 1

print prime_factors
</pre>
<hr />
<p><small>© zhtlancer for <a href="http://zhtlancer.com">zhtlancer&#039;s blog</a>, 2010. |
<a href="http://zhtlancer.com/2010/01/project-eular-3-python/">Permalink</a> |
<a href="http://zhtlancer.com/2010/01/project-eular-3-python/#comments">暂无评论</a> |
Add to
<a href="http://del.icio.us/post?url=http://zhtlancer.com/2010/01/project-eular-3-python/&title=Project Eular #3 (Python)" onclick="pageTracker._trackPageview('/outgoing/del.icio.us/post?url=http_//zhtlancer.com/2010/01/project-eular-3-python/_title=Project_Eular_3_Python&amp;referer=');">del.icio.us</a>
<br/>
Post tags: <a href="http://zhtlancer.com/tag/algorithm/" rel="tag">Algorithm</a>, <a href="http://zhtlancer.com/tag/project-eular/" rel="tag">Project Eular</a>, <a href="http://zhtlancer.com/tag/python/" rel="tag">Python</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://zhtlancer.com/2010/01/project-eular-3-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Eular #2 (Python)</title>
		<link>http://zhtlancer.com/2009/07/project-eular-2-python/</link>
		<comments>http://zhtlancer.com/2009/07/project-eular-2-python/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 14:04:31 +0000</pubDate>
		<dc:creator>zhtlancer</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Project Eular]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zhtlancer.yo2.cn/?p=43327</guid>
		<description><![CDATA[Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, &#8230; Find the sum of all the even-valued terms in the sequence which do not exceed four million. [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:<br />
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, &#8230;<br />
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
</p></blockquote>
<p>这道题也很水，所以不多说了&#8230;</p>
<pre name="code" class="python">
#!/usr/bin/env python

sum = 0
num1 = 0
num2 = 1
while num2 <= 4000000:
    print num2
    if num2 % 2 == 0:
        sum += num2
    temp = num2
    num2 = num1+num2
    num1 = temp
print sum
</pre>
<hr />
<p><small>© zhtlancer for <a href="http://zhtlancer.com">zhtlancer&#039;s blog</a>, 2009. |
<a href="http://zhtlancer.com/2009/07/project-eular-2-python/">Permalink</a> |
<a href="http://zhtlancer.com/2009/07/project-eular-2-python/#comments">暂无评论</a> |
Add to
<a href="http://del.icio.us/post?url=http://zhtlancer.com/2009/07/project-eular-2-python/&title=Project Eular #2 (Python)" onclick="pageTracker._trackPageview('/outgoing/del.icio.us/post?url=http_//zhtlancer.com/2009/07/project-eular-2-python/_title=Project_Eular_2_Python&amp;referer=');">del.icio.us</a>
<br/>
Post tags: <a href="http://zhtlancer.com/tag/algorithm/" rel="tag">Algorithm</a>, <a href="http://zhtlancer.com/tag/project-eular/" rel="tag">Project Eular</a>, <a href="http://zhtlancer.com/tag/python/" rel="tag">Python</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://zhtlancer.com/2009/07/project-eular-2-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Eular #1(Python)</title>
		<link>http://zhtlancer.com/2009/07/project-euler-1/</link>
		<comments>http://zhtlancer.com/2009/07/project-euler-1/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 12:34:22 +0000</pubDate>
		<dc:creator>zhtlancer</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Project Eular]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://zhtlancer.yo2.cn/?p=43280</guid>
		<description><![CDATA[接触Python一年多了，但一直没有用它写过什么正经的东西。刚好这个暑假暂时没法回家，在学校也不是特别忙，就把之前觊觎已久的Project Eular翻出来，准备用Python扫一遍，就当作学习Python了。不过以我可怜的水平，不知道能坚持几道&#8230; 今天先扫一道超级水题，增强下信心吧…… Project Eular #1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. sum = 0 for num in [...]]]></description>
			<content:encoded><![CDATA[<p>接触Python一年多了，但一直没有用它写过什么正经的东西。刚好这个暑假暂时没法回家，在学校也不是特别忙，就把之前觊觎已久的Project Eular翻出来，准备用Python扫一遍，就当作学习Python了。不过以我可怜的水平，不知道能坚持几道&#8230;</p>
<p>今天先扫一道超级水题，增强下信心吧……<br />
Project Eular #1</p>
<blockquote><p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.<br />
Find the sum of all the multiples of 3 or 5 below 1000.</p></blockquote>
<pre name="code" class="python">sum = 0
for num in range(3,1000,3):
    sum ＝ sum+num
for num in range(5,1000,5):
    sum = sum+num
for num in range(15,1000,15):
    sum = sum-num
print sum
</pre>
<hr />
<p><small>© zhtlancer for <a href="http://zhtlancer.com">zhtlancer&#039;s blog</a>, 2009. |
<a href="http://zhtlancer.com/2009/07/project-euler-1/">Permalink</a> |
<a href="http://zhtlancer.com/2009/07/project-euler-1/#comments">暂无评论</a> |
Add to
<a href="http://del.icio.us/post?url=http://zhtlancer.com/2009/07/project-euler-1/&title=Project Eular #1(Python)" onclick="pageTracker._trackPageview('/outgoing/del.icio.us/post?url=http_//zhtlancer.com/2009/07/project-euler-1/_title=Project_Eular_1_Python&amp;referer=');">del.icio.us</a>
<br/>
Post tags: <a href="http://zhtlancer.com/tag/algorithm/" rel="tag">Algorithm</a>, <a href="http://zhtlancer.com/tag/project-eular/" rel="tag">Project Eular</a>, <a href="http://zhtlancer.com/tag/python/" rel="tag">Python</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://zhtlancer.com/2009/07/project-euler-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

