<?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>Ticklish Techs &#187; maths</title>
	<atom:link href="http://www.ticklishtechs.net/tag/maths/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ticklishtechs.net</link>
	<description>a mostly .NET but also some other cool techs blog</description>
	<lastBuildDate>Wed, 05 Jan 2011 21:44:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Hunting high and low</title>
		<link>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/</link>
		<comments>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 11:48:31 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/</guid>
		<description><![CDATA[Here is a nice little challenge, Benjamin came up with some months ago: &#8220;From a list of numbers find the smallest and the largest one &#8211; but do not use more than 1,5 comparisons per number.&#8221; Dear reader: Try it! The solution is simple, straight forward and very nice. And I didn&#8217;t find it. I [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a nice little challenge, Benjamin came up with some months ago: &#8220;From a list of numbers find the smallest and the largest one &#8211; but do not use more than 1,5 comparisons per number.&#8221;</p>
<p>Dear reader: Try it!</p>
<p>The solution is simple, straight forward and very nice. And I didn&#8217;t find it.</p>
<p>I found something else. My approach was to look at the largest-number-so-far (max) and the smallest-number-so-far (min) as the boundaries of a region. A number outside this region must be larger than max or smaller than min and causes that boundary to change.</p>
<p>To check if a number (a) was outside that region a little computation came to my mind:</p>
<pre class="code">check = (max - a)*(min - a);</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>You would expect n to be smaller than max, so (max-n) should be positive.</p>
<p>You would expect n to be larger than min, so (n-min) should be positive, too.</p>
<p>Two positive numbers multiplied result in a positive number again.</p>
<p>So, if n was outside the boundaries, <font size="2" face="Courier New">check</font> would become negative. I only had to check which boundary was exceeded and that&#8217;s it:</p>
<pre class="code"><span style="color: blue">if (</span>check &lt; 0)
<span style="color: blue">    if </span>(a &gt; max)
        max = a;
    <span style="color: blue">else
        </span>min = a;</pre>
<p>Using this approach the number of comparisons&nbsp; converges to 1 when the length of the list grows. So I found a solution that is way better than 1,5 comparisons per number, didn&#8217;t I?</p>
<h3>Boooooh</h3>
<p>No, I didn&#8217;t. I cheated. In fact&nbsp; <font size="2" face="Courier New">(max-a)</font> and <font size="2" face="Courier New">(min-a)</font> are comparisons, they just don&#8217;t use &gt; or &lt;.</p>
<p>(Actually it&#8217;s the other way around: To compute &lt; or &gt; most processors do a subtraction and compare the result to 0.)</p>
<p>So &#8211; if you count the subtractions as well you get 3+ comparisons per number&#8230;</p>
<p>The intended solution to the challenge (and the code you should provide in your exam) is:</p>
<pre class="code">a = list[count++];
b = list[count++];

<span style="color: blue">if </span>(a&lt;b)
{
    <span style="color: blue">if </span>(a&lt;min) min = a;
    <span style="color: blue">if </span>(b&gt;max) max = b;
}
<span style="color: blue">else
</span>{
    <span style="color: blue">if </span>(b &lt; min) min = b;
    <span style="color: blue">if </span>(a &gt; max) max = a;
}
</pre>
<h3>&nbsp;</h3>
<h3>So &#8211; what&#8217;s the point of this post?</h3>
<p>The point is: My silly approach can be faster than the standard solution. Depending on the type and range of the numbers in the list calculating and probing <font size="2" face="Courier New">check</font> needs less time than the comparisons in the standard solution.</p>
<p>It may not be much, but sometimes small advantages matter.&nbsp; For example: For an integer-list of length 10^8 with values from -10.000 to 10.000 my approach is 0.02 seconds faster (on my current laptop). And has less code.</p>
<p>So if you feel like using it &#8211; I won&#8217;t charge you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/07/14/hunting-high-and-low/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Permutations and the number 9 (proof)</title>
		<link>http://www.ticklishtechs.net/2009/02/27/permutations-and-the-number-9-proof/</link>
		<comments>http://www.ticklishtechs.net/2009/02/27/permutations-and-the-number-9-proof/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 16:47:06 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/02/10/permutations-and-the-number-9-proof/</guid>
		<description><![CDATA[Ten days ago I promised a proof why the differences of any permutation of the same digits is always a multiple of 9. Here it is Let&#8217;s say x and y are digits and &#8216;xy&#8217; is not &#8216;x*y&#8217;, but the number that consist of the digits x and y. xy &#8211; yx = multiple of [...]]]></description>
			<content:encoded><![CDATA[<p>Ten days ago I promised a proof why the <a href="http://www.ticklishtechs.net/2009/01/21/permutations-and-the-number-9/">differences of any permutation of the same digits is always a multiple of 9</a>. Here it is</p>
<p>Let&#8217;s say x and y are digits and &#8216;xy&#8217; is not &#8216;x*y&#8217;, but the number that consist of the digits x and y.</p>
<p>xy &#8211; yx = multiple of 9.</p>
<p>Is it always true? Yes, it is:</p>
<p>(10x + 1y) &#8211; (10y + 1x) = multiple of 9?    <br />9x &#8211; 9y = multiple of 9?     <br />9(x-y) = multiple of 9? Yes, for sure.</p>
<p>I calculated the numeric values of <strong>xy</strong> and <strong>yx</strong> by &quot;10 times the higher position + 1 time the lower position&quot;, just like we all do every day in our beloved decimal-system. More formally we describe the factor for the position (1, 10, 100&#8230;) by</p>
<p>10^position, (position is zero-based, counting from right to left, of course)</p>
<p>Now, when we change the position of a single digit within a number we change its numeric value from</p>
<p>x*10^(old position) to x*10^(new position).</p>
<p>We can neglect x here, because it&#8217;s a factor that occurs in both values, so we can get rid of it by division.    <br />The remaining part for building the difference is</p>
<p>10^p1 &#8211; 10^p2, a formula that always produces multiples of 9: 10-1, 1000-100, 10-1000000.</p>
<h3>Conclusion</h3>
<p>Since the difference of a number and one of it&#8217;s permutations is a sum of (10^p1-10^p2)-parts, which are all multiples of 9, the total also can be divided by 9.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/02/27/permutations-and-the-number-9-proof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Permutations and the number 9</title>
		<link>http://www.ticklishtechs.net/2009/02/17/permutations-and-the-number-9/</link>
		<comments>http://www.ticklishtechs.net/2009/02/17/permutations-and-the-number-9/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 16:43:14 +0000</pubDate>
		<dc:creator>Wolfram Bernhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/01/21/permutations-and-the-number-9/</guid>
		<description><![CDATA[Lately I stumbled over permutations and noticed a funny fact: When you take any integer, produce a permutation and subtract one form the other, you always get a multiple of 9. It works with a any length. Some examples: Length 2 23 &#8211; 32 = -9&#160; 84 &#8211; 48 = 36 60 &#8211; 06 = [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I stumbled over permutations and noticed a funny fact: When you take any integer, produce a permutation and subtract one form the other, you always get a multiple of 9. </p>
<p>It works with a any length. Some examples: </p>
<p>Length 2    <br />23 &#8211; 32 = -9&#160; <br />84 &#8211; 48 = 36     <br />60 &#8211; 06 = 54 </p>
<p>Length 3    <br />123 &#8211; 132 = -9     <br />and so on&#8230; </p>
<p>It still works for changing the front position:    <br />123 &#8211; 213 = -90 </p>
<p>In fact it works for changing any position:    <br />123 &#8211; 321 = -198 (-22*9) </p>
<p>This leads to the conclusion I stated in the beginning. The difference of any permutation of the same number is a multiple of 9. Feel free to check it with you favorite numbers.</p>
<p>It&#8217;s not a great mathematical invention (if it is, please let me know), but I didn&#8217;t know it, didn&#8217;t expect it und find it kind of fascinating. I asked a couple of friends and no one was aware of this. </p>
<p>I still try to find a way to use these fact, maybe for spell-check-like for numbers or a fast calculation of permutations, but so far it seems just useless <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
<p>Instead I can provide a proof for numbers of any length and I&#8217;ll post it here in ten days from today. Meanwhile I want you to try it yourself. The proof is really, really simple, almost trivial and it won&#8217;t cost you more than five minutes to understand it all. </p>
<p>Please email or comment your solution!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/02/17/permutations-and-the-number-9/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

