<?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: Half a number, half it again and add it to the first half.</title>
	<atom:link href="http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/</link>
	<description>Faith, Solaris, and Chicken Korma, by Anton Parol</description>
	<lastBuildDate>Mon, 20 Jun 2011 20:37:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Anton Parol</title>
		<link>http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/comment-page-1/#comment-445</link>
		<dc:creator>Anton Parol</dc:creator>
		<pubDate>Fri, 05 Dec 2008 10:14:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.parolski.com/?p=136#comment-445</guid>
		<description>Liam. I&#039;ve got an interesting reply coming up, once I&#039;ve the chance to write it up!!

Anton</description>
		<content:encoded><![CDATA[<p>Liam. I&#8217;ve got an interesting reply coming up, once I&#8217;ve the chance to write it up!!</p>
<p>Anton</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Liam McBrien</title>
		<link>http://www.parolski.com/2008/12/03/half-a-number-half-it-again-and-add-it-to-the-first-half/comment-page-1/#comment-443</link>
		<dc:creator>Liam McBrien</dc:creator>
		<pubDate>Thu, 04 Dec 2008 14:04:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.parolski.com/?p=136#comment-443</guid>
		<description>Of course, you could just do away with the loop and use a formula:

(starting number) - (starting number / (2 ^ (number of iterations))

Since that&#039;s effectively what you&#039;re doing. Adding half of a half to a half is the same as subtracting a quarter - which is a half of a half.

So if we start with 10, iterations 1 to 5 would be represented by:

10 - (10 / 2^1) =&gt; 10 - (10 / 2) =&gt; 10 - 5 =&gt; 5
10 - (10 / 2^2) =&gt; 10 - (10 / 4) =&gt; 10 - 2.5 =&gt; 7.5
10 - (10 / 2^3) =&gt; 10 - (10 / 8) =&gt; 10 - 1.25 =&gt; 8.75
10 - (10 / 2^4) =&gt; 10 - (10 / 16) =&gt; 10 - 0.625 =&gt; 9.375
10 - (10 / 2^5) =&gt; 10 - (10 / 32) =&gt; 10 - 0.3125 =&gt; 9.6875

This also definitively answers the question of whether you ever reach ten - you won&#039;t, since you&#039;re always subtracting the result of a division by a power of two (which becomes infinitesimal for large powers, but will never equal zero).

It&#039;s also a good lesson in optimisation. I haven&#039;t tried the Java implementation, but I&#039;ll bet it runs quicker than a loop! Right enough, a significant amount of the time spent in your program is probably all the System.out.println() calls - these actually take up a suprising amount of execution time when you&#039;re doing stuff like this (it is I/O, after all)!</description>
		<content:encoded><![CDATA[<p>Of course, you could just do away with the loop and use a formula:</p>
<p>(starting number) &#8211; (starting number / (2 ^ (number of iterations))</p>
<p>Since that&#8217;s effectively what you&#8217;re doing. Adding half of a half to a half is the same as subtracting a quarter &#8211; which is a half of a half.</p>
<p>So if we start with 10, iterations 1 to 5 would be represented by:</p>
<p>10 &#8211; (10 / 2^1) =&gt; 10 &#8211; (10 / 2) =&gt; 10 &#8211; 5 =&gt; 5<br />
10 &#8211; (10 / 2^2) =&gt; 10 &#8211; (10 / 4) =&gt; 10 &#8211; 2.5 =&gt; 7.5<br />
10 &#8211; (10 / 2^3) =&gt; 10 &#8211; (10 / <img src='http://www.parolski.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> =&gt; 10 &#8211; 1.25 =&gt; 8.75<br />
10 &#8211; (10 / 2^4) =&gt; 10 &#8211; (10 / 16) =&gt; 10 &#8211; 0.625 =&gt; 9.375<br />
10 &#8211; (10 / 2^5) =&gt; 10 &#8211; (10 / 32) =&gt; 10 &#8211; 0.3125 =&gt; 9.6875</p>
<p>This also definitively answers the question of whether you ever reach ten &#8211; you won&#8217;t, since you&#8217;re always subtracting the result of a division by a power of two (which becomes infinitesimal for large powers, but will never equal zero).</p>
<p>It&#8217;s also a good lesson in optimisation. I haven&#8217;t tried the Java implementation, but I&#8217;ll bet it runs quicker than a loop! Right enough, a significant amount of the time spent in your program is probably all the System.out.println() calls &#8211; these actually take up a suprising amount of execution time when you&#8217;re doing stuff like this (it is I/O, after all)!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

