<?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>LongSpine.com &#187; Uncategorised</title>
	<atom:link href="http://longspine.com/category/uncategorised/feed/" rel="self" type="application/rss+xml" />
	<link>http://longspine.com</link>
	<description>Yes, we are lazy.</description>
	<lastBuildDate>Tue, 06 Jul 2010 10:49:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<atom:link rel="next" href="http://longspine.com/category/uncategorised/feed/?page=2" />

		<item>
		<title>No More Markdown Plugin!</title>
		<link>http://longspine.com/uncategorised/no-more-markdown-plugin/</link>
		<comments>http://longspine.com/uncategorised/no-more-markdown-plugin/#comments</comments>
		<pubDate>Mon, 10 May 2010 14:54:36 +0000</pubDate>
		<dc:creator>poomk</dc:creator>
				<category><![CDATA[Uncategorised]]></category>

		<guid isPermaLink="false">http://longspine.com/?p=200</guid>
		<description><![CDATA[I&#8217;ve been using Markdown for WordPress and bbPress since the creation of this website, September 2009. It replaces the default visual and html editors with a simple, syntax-based editor. After half a year of using this plugin, problems occurred. The disadvantage of this plugin is that one is forced to use Markdown. And because of that, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://wordpress.org/extend/plugins/markdown-for-wordpress-and-bbpress/">Markdown for WordPress and bbPress</a> since the creation of this website, September 2009. It replaces the default visual and html editors with a simple, syntax-based editor. After half a year of using this plugin, problems occurred.</p>
<p>The disadvantage of this plugin is that one is forced to use Markdown. And because of that, there are many conflicts with some other plugins especially when html and short-tags involve. And once the Markdown plugin is disabled, all posted articles will turn into markdown code. It seems like this plugin didn&#8217;t even translate Markdown syntax into HTML before publishing, instead HTML is rendered real-time when being viewd.</p>
<p>In the end I had to choose between using Markdown (with restricted freedom), or the original Visual &amp; HTML editor. Despite of the extra efforts, I chose the original editor. So I can be free from the architectural flaw of this plugin.</p>
<p>If you are the one who use this plugin, think twice. It might ruin all your posts someday if the website is modified.</p>
]]></content:encoded>
			<wfw:commentRss>http://longspine.com/uncategorised/no-more-markdown-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tray Selection Problem in HP LaserJet 4000</title>
		<link>http://longspine.com/uncategorised/tray-selection-problem-in-hp-laserjet/</link>
		<comments>http://longspine.com/uncategorised/tray-selection-problem-in-hp-laserjet/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 11:19:30 +0000</pubDate>
		<dc:creator>poomk</dc:creator>
				<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://longspine.com/?p=114</guid>
		<description><![CDATA[If the printer has extended trays, e.g. tray 3, and if the PostScript (PS) driver is used, the printer will always select the paper from tray 1, even though there&#8217;s no paper in that tray. So far, I have found no &#8220;solution&#8221; to the problem. The best thing we can do is avoiding the automatic [...]]]></description>
			<content:encoded><![CDATA[<p>If the printer has extended trays, e.g. tray 3, and if the PostScript (PS) driver is used, the printer will always select the paper from tray 1, even though there&#8217;s no paper in that tray.</p>
<p>So far, I have found no &#8220;solution&#8221; to the problem. The best thing we can do is avoiding the automatic paper tray selection by setting different paper size and type.</p>
<blockquote><p>HP LaserJet 4000 Family Printers &#8211; Default Paper Tray Selections</p>
<p>ISSUE:<br />
If a job is sent to the printer, which paper tray will the HP LaserJet 4000 family printer pull paper from if a specific paper tray is not selected within the software application or printer properties.</p>
<p>SOLUTION:<br />
If the HP LaserJet 4000 family printer has all of the trays set to the same paper size and paper type, it will select paper from the paper trays in the following order when &gt;Tray 1 = First in the Paper Handling menu on the printers front control panel.</p>
<p>NOTE: If Tray 1 = CASSETTE, it will be the last tray to have paper taken from it.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211; TABELLE &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Using a PCL driver to print Using a PostScript (R) Emulation driver to print PostScript Emulation (Tray 4 not installed)<br />
Tray 1 (MP Tray) Tray 1 (MP Tray) Tray 1 (MP Tray)<br />
Tray 4 (if installed) Tray 4 (If Installed) Tray 3 (Standard on the 4000T/TN models optional on 4000/N)<br />
Tray 3 (Standard on the 4000T/TN models, optional on 4000/N) Tray 3 (Standard on the 4000T/TN models, optional on 4000/N) Tray 2<br />
Tray 2 Tray 2</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8211; TABELLE &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>Configure Tray 1 = FIRST:<br />
1. Press the MENU button.<br />
2. Press the ITEM button until Paper Handling Menu appears in the control panel display and press the Select button.<br />
3. Press the ITEM button until Tray 1 Mode appears in the control panel display and press Select .<br />
4. Press the Value button to until FIRST appears in the control panel display and press Select . If paper is loaded in Tray 1, the printer will pull paper from that tray first.</p></blockquote>
<p>From: <a href="http://debianforum.de/forum/viewtopic.php?f=15&amp;p=739745#p739744">debianforum.de</a></p>
]]></content:encoded>
			<wfw:commentRss>http://longspine.com/uncategorised/tray-selection-problem-in-hp-laserjet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Framemaker and its mouse-scrolling problem</title>
		<link>http://longspine.com/uncategorised/framemaker-and-its-mouse-scrolling-problem/</link>
		<comments>http://longspine.com/uncategorised/framemaker-and-its-mouse-scrolling-problem/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 15:04:33 +0000</pubDate>
		<dc:creator>poomk</dc:creator>
				<category><![CDATA[Uncategorised]]></category>

		<guid isPermaLink="false">http://longspine.com/?p=103</guid>
		<description><![CDATA[Introduction Related to my master thesis, I have to use the old Framemaker 5.5 on Windows XP. It is an interesting publishing program and, in my opinion, it&#8217;s a good compromise between Latex and OpenOffice (or Microsoft Words). It&#8217;s worth to mention that there&#8217;re many WYSIWYG implementations of Latex. A program called LyX is one [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p><strong></strong>Related to my master thesis, I have to use the old Framemaker 5.5 on Windows XP. It is an interesting publishing program and, in my opinion, it&#8217;s a good compromise between Latex and OpenOffice (or Microsoft Words).</p>
<p>It&#8217;s worth to mention that there&#8217;re many WYSIWYG implementations of Latex. A program called <a href="http://www.lyx.org/">LyX </a>is one of the most popular. However, I tried to use it in my CFD report but I felt that it was not right. There must be something wrong with the GUI, because most of the Latex commands I need are hard to find. After that I just switched back to Vim+Latex which was still not the best solution.</p>
<p>On the other hand, Framemaker has a lot better GUI with additional basic drawing tools. There are still some issues that it uses proprietary (close) formats, the cost is relatively high for home users, and mouse-scrolling doesn&#8217;t work properly. Only the latter problem can be solved so far.</p>
<p>The cause of this problem could be that its legacy cross-platform design doesn&#8217;t support mouse wheel at the beginning. It might be the same case as many UNIX/Linux terminals that have their own implementation of middle-click. This problem can be solved by using another application that grabs the mouse-wheel commands and translate it into new commands that are supported by Framemaker.</p>
<p><strong>Solution for Windows Users</strong></p>
<p>Install <a href="http://ehiti.de/katmouse/">KatMouse</a> or the equivalent program such as Logitech MouseWare. I chose KatMouse because it does its very function while not interfering with the default mouse-setting at all.</p>
<p><strong>Solution for Mac Users</strong></p>
<p>I have read about a program called <a href="http://www.usboverdrive.com/USBOverdrive/News.html">USB Overdrive</a> which does the same trick. I haven&#8217;t tried it out though.</p>
<p><strong>Further Readings</strong></p>
<ul>
<li>http://www.tek-tips.com/faqs.cfm?fid=5003#</li>
<li>http://kb2.adobe.com/cps/323/323607.html</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://longspine.com/uncategorised/framemaker-and-its-mouse-scrolling-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Prime Numbers Using Python</title>
		<link>http://longspine.com/uncategorised/finding-prime-numbers-using-python/</link>
		<comments>http://longspine.com/uncategorised/finding-prime-numbers-using-python/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 21:57:01 +0000</pubDate>
		<dc:creator>poomk</dc:creator>
				<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[prime numbers]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://longspine.com/?p=12</guid>
		<description><![CDATA[เขียนโปรแกรมหาจำนวนเฉพาะอย่างง่ายๆในห้าไอเดียโดยใช้ Python ไอเดียแรก จำนวนเฉพาะคือจำนวนเต็มบวกใดๆที่ไม่มีจำนวนเต็มบวกอื่นๆหารมันลงตัว 12345678910111213# prime1.py prime = &#91;2&#93; for i in xrange&#40;3, 100000&#41;: flag = True &#160; &#160; &#160; &#160; &#160; &#160; # สมมุติว่าจำนวน i เป็นจำนวนเฉพาะ for j in xrange&#40;2, i&#41;: &#160;# จำนวน j ใดๆที่มีค่าน้อยกว่า i ต้องหารจำนวนนี้ไม่ลงตัว (ยกเว้น 1) if &#40;i % j == 0&#41;: &#160; &#160;# แต่ถ้าหารได้ลงตัว (มีเศษเป็น 0) flag = False &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>เขียนโปรแกรมหาจำนวนเฉพาะอย่างง่ายๆในห้าไอเดียโดยใช้ Python</p>
<p><strong>ไอเดียแรก</strong></p>
<p>จำนวนเฉพาะคือจำนวนเต็มบวกใดๆที่ไม่มีจำนวนเต็มบวกอื่นๆหารมันลงตัว</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># prime1.py</span><br />
<br />
prime = <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">100000</span><span style="color: black;">&#41;</span>:<br />
flag = <span style="color: #008000;">True</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># สมมุติว่าจำนวน i เป็นจำนวนเฉพาะ</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, i<span style="color: black;">&#41;</span>: &nbsp;<span style="color: #808080; font-style: italic;"># จำนวน j ใดๆที่มีค่าน้อยกว่า i ต้องหารจำนวนนี้ไม่ลงตัว (ยกเว้น 1)</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> j == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>: &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># แต่ถ้าหารได้ลงตัว (มีเศษเป็น 0)</span><br />
flag = <span style="color: #008000;">False</span> &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># เราก็พบว่าจำนวนนั้นไม่ใช่จำนวนเฉพาะ</span><br />
<span style="color: #ff7700;font-weight:bold;">break</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># ออกจากลูปทันที</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> flag == <span style="color: #008000;">True</span>: &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># ถ้าพิสูจน์แล้วว่าเป็นจำนวนเฉพาะจริงๆ</span><br />
prime.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># ให้ใส่ค่านั้นเข้าไปในตัวแปร prime</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> prime</div></td></tr></tbody></table></div>
<p>สังเกตว่าผมใช้คำสั่ง xrange แทน range เพราะเมื่อต้องการวนรอบเป็นจำนวนรอบมากๆแล้ว xrange จะเร็วกว่าเล็กน้อย ส่วนรายละเอียดนั้นเราจะไม่กล่าวถึงในที่นี้</p>
<p><strong>ไอเดียที่สอง</strong></p>
<p>เนื่องจากบางจำนวนที่ถูกนำมาหารนั้นเป็นตัวประกอบของอีกจำนวน ดังนั้นเราจึงสามารถลดจำนวนตัวหารเหลือแค่จำนวนที่ไม่มีจำนวนอื่นเป็นตัวประกอบ ซึ่งก็คือจำนวนเฉพาะที่มีค่าน้อยจำนวนที่ต้องการจะหานั่นเอง</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># prime2.py</span><br />
<br />
prime = <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">100000</span><span style="color: black;">&#41;</span>:<br />
flag = <span style="color: #008000;">True</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> prime: &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># จำนวน j ใดๆที่เป็นจำนวนเฉพาะและมีค่าน้อยกว่า i ต้องหารจำนวนนี้ไม่ลงตัว</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> j == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:<br />
flag = <span style="color: #008000;">False</span><br />
<span style="color: #ff7700;font-weight:bold;">break</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> flag == <span style="color: #008000;">True</span>:<br />
prime.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> prime</div></td></tr></tbody></table></div>
<p><strong>ไอเดียที่สาม</strong></p>
<p>ลดจำนวนตัวที่ต้องวนหารลง เนื่องจากจำนวนเต็มใดๆ j สูงสุดที่จะหาจำนวนเต็มใดๆ i ได้นั้น จะต้องมีค่าไม่มากไปกว่ารากที่สองของ i</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># prime3.py</span><br />
<br />
prime = <span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">100000</span><span style="color: black;">&#41;</span>:<br />
flag = <span style="color: #008000;">True</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> prime:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>j <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> i<span style="color: black;">&#41;</span>: &nbsp; <span style="color: #808080; font-style: italic;"># ถ้า j มีค่ามากกว่าตัวหารสุงสุดที่เป็นไปได้ (มีค่ามากกว่ารากที่สองของ i)</span><br />
<span style="color: #ff7700;font-weight:bold;">break</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># ให้ออกจากลูป</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> j == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:<br />
flag = <span style="color: #008000;">False</span><br />
<span style="color: #ff7700;font-weight:bold;">break</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> flag == <span style="color: #008000;">True</span>:<br />
prime.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> prime</div></td></tr></tbody></table></div>
<p><strong>ไอเดียที่สี่</strong></p>
<p>เราสามารถใช้หน่วยความจำของคอมพิวเตอร์มาช่วยในการคำนวณได้โดยใช้วิธี<a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes">ซีฟของเอราทอสเทนีส</a> ซึ่งความเร็วที่ได้มาเพิ่มนั้นจะถูกแลกกับหน่วยความจำที่เสียไประหว่างคำนวณ</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># prime4.py</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> numpy<br />
<br />
n = <span style="color: #ff4500;">100000</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># หาจำนวนเฉพาะที่มีค่าน้อยกว่า 100000</span><br />
<br />
primeArr = numpy.<span style="color: black;">zeros</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span> &nbsp; <span style="color: #808080; font-style: italic;"># สร้าง array ขนาด n</span><br />
primeArr<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># 0 ไม่ใช่จำนวนเฉพาะ</span><br />
primeArr<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># 1 ก็ไม่ใช่</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, n<span style="color: black;">&#41;</span>:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> primeArr<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span>: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># ถ้าจำนวนนั้นเป็นจำนวนเฉพาะ</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>i <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span>, n, i<span style="color: black;">&#41;</span>: <span style="color: #808080; font-style: italic;"># จำนวนอื่นๆที่จำนวนนั้นเป็นตัวประกอบจะไม่ใช่จำนวนเฉพาะ</span><br />
primeArr<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span><br />
<br />
prime = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, n<span style="color: black;">&#41;</span>:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> primeArr<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span>: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># เก็บจำนวนเฉพาะไว่ในตัวแปร prime</span><br />
prime.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> prime</div></td></tr></tbody></table></div>
<p>ทดลองความเร็วของทั้งสี่ตัวอย่างบนเครื่องผม โดยให้หาจำนวนเฉพาะที่มีค่าต่ำกว่าหนึ่งแสน เราจะได้ผลลัพท์ตามคาด</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime1.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;6m16.043s<br />
user &nbsp; &nbsp;5m58.734s<br />
sys &nbsp; &nbsp; 0m12.869s<br />
poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime2.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;0m20.074s<br />
user &nbsp; &nbsp;0m19.761s<br />
sys &nbsp; &nbsp; 0m0.028s<br />
poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime3.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;0m0.703s<br />
user &nbsp; &nbsp;0m0.692s<br />
sys &nbsp; &nbsp; 0m0.004s<br />
poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime4.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;0m0.570s<br />
user &nbsp; &nbsp;0m0.552s<br />
sys &nbsp; &nbsp; 0m0.004s</div></td></tr></tbody></table></div>
<p><strong>ไอเดียที่ห้า</strong></p>
<p>สืบเนื่องจากผลลัทพธืด้านบน เราเห็นว่าวิธีซีฟนั้นได้ผลลัพท์ดีที่สุด แต่เนื่องจากหน่วยความจำเรามีจำกัดทำให้เราไม่สามารถใช้ซีฟหาจำนวนเฉพาะมากๆได้ เราสามารถเอาสองวิธีนี้มาเขียนรวมกันแบบลูกครึ่ง (hybrid) คือใช้ซีฟหาจำนวนเฉพาะขนาดต่ำๆก่อน แล้วนำจำนวนเฉพาะนั้นไปหาจำนวนเฉพาะที่สูงขึ้นไปโดยใช้วิธีเดิม</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;"># prime5.py: Hybrid Sieve-Iterative</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> numpy<br />
<br />
n = <span style="color: #ff4500;">10000000</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># ใช้ซีฟหาจำนวนเฉพาะที่มีค่าน้อยกว่า 10,000,000</span><br />
<br />
primeArr = numpy.<span style="color: black;">zeros</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><br />
primeArr<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span><br />
primeArr<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, n<span style="color: black;">&#41;</span>:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> primeArr<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span>:<br />
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>i <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span>, n, i<span style="color: black;">&#41;</span>:<br />
primeArr<span style="color: black;">&#91;</span>j<span style="color: black;">&#93;</span> = <span style="color: #ff4500;">1</span><br />
<br />
prime = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, n<span style="color: black;">&#41;</span>:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> primeArr<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> == <span style="color: #ff4500;">0</span>:<br />
prime.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>n, <span style="color: #ff4500;">20000000</span><span style="color: black;">&#41;</span>: &nbsp;<span style="color: #808080; font-style: italic;"># หาต่อจนถึงตัวที่ 20,000,000</span><br />
flag = <span style="color: #008000;">True</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> prime:<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>j <span style="color: #66cc66;">**</span> <span style="color: #ff4500;">2</span> <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> i<span style="color: black;">&#41;</span>:<br />
<span style="color: #ff7700;font-weight:bold;">break</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i <span style="color: #66cc66;">%</span> j == <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:<br />
flag = <span style="color: #008000;">False</span><br />
<span style="color: #ff7700;font-weight:bold;">break</span><br />
<span style="color: #ff7700;font-weight:bold;">if</span> flag == <span style="color: #008000;">True</span>:<br />
prime.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">print</span> prime</div></td></tr></tbody></table></div>
<p><strong>เปรียบเทียบ</strong></p>
<p>ลองเปรียบเทียบความเร็วของตัวอย่างที่ 3, 5 (วิธีซีฟลูกครึ่ง), และ 4 (วิธีซีฟ) โดยหาจำนวนเฉพาะที่มีค่าน้อยกว่า 20,000,000 จะได้</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime3.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;9m19.625s<br />
user &nbsp; &nbsp;9m15.983s<br />
sys &nbsp; &nbsp; 0m0.980s<br />
poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime5.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;6m14.933s<br />
user &nbsp; &nbsp;6m13.023s<br />
sys &nbsp; &nbsp; 0m0.648s<br />
poomk<span style="color: #000000; font-weight: bold;">@</span>gemini:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>prime$ <span style="color: #000000; font-weight: bold;">time</span> .<span style="color: #000000; font-weight: bold;">/</span>prime4.py <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<br />
<br />
real &nbsp; &nbsp;1m24.342s<br />
user &nbsp; &nbsp;1m23.113s<br />
sys &nbsp; &nbsp; 0m0.304s</div></td></tr></tbody></table></div>
<p>จากผลลัพท์นี้สรุปได้คร่าวๆว่า ซีฟช่วยคุณได้จริงๆ</p>
<p>ดังนั้นถ้าคุณต้องการหาจำนวนเฉพาะที่มีขนาดเกินพันล้านแล้วละก็ เดินไปซื้อแรมมาใส่แล้วค่อยรันยังเร็วกว่า</p>
]]></content:encoded>
			<wfw:commentRss>http://longspine.com/uncategorised/finding-prime-numbers-using-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://longspine.com/uncategorised/hello-world/</link>
		<comments>http://longspine.com/uncategorised/hello-world/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 15:15:54 +0000</pubDate>
		<dc:creator>poomk</dc:creator>
				<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://leo.poomk.com/?p=1</guid>
		<description><![CDATA[Welcome to the wordpress version of Longspine.com! I also moved to a new server. These are some notes about this website: Xen-based VPS with 512 MB RAM at prgmr.com the new host is in US,  so all accesses from Europe will be a lot slower, however, it&#8217;s faster for people in Thailand. WordPress 2.8.4 was [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the wordpress version of Longspine.com!  I also moved to a new server. These are some notes about this website:</p>
<ul>
<li> Xen-based VPS with 512 MB RAM at <a href="http://www.prgmr.com/xen/">prgmr.com</a></li>
<li>the new host is in US,  so all accesses from Europe will be a lot slower, however, it&#8217;s faster for people in Thailand.</li>
<li>WordPress 2.8.4 was installed</li>
<li>CodeColorer
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Hello, World!&quot;</span></div></td></tr></tbody></table></div>
</li>
<li>WP QuickLaTeX 2.5.2 <center><img src="http://quicklatex.com/cache/ql_d952e98ea6f6e5ec72451a64be41fd84.gif" alt=" 1 + {1 \over 1 + {\strut 1 \over 1 + {\strut 1\over 1 + {\strut 1\over 1 + … }}}} " title=" 1 + {1 \over 1 + {\strut 1 \over 1 + {\strut 1\over 1 + {\strut 1\over 1 + … }}}} " style="vertical-align: -77px; border: none;"/></center></li>
</ul>
<p>All posts from the Drupal version shall be all imported, by hand! There are not so many though, thanks to my laziness.</p>
]]></content:encoded>
			<wfw:commentRss>http://longspine.com/uncategorised/hello-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
