<?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>Dreamshire &#187; Bouncy Numbers</title>
	<atom:link href="http://blog.dreamshire.com/tag/bouncy-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dreamshire.com</link>
	<description>Showing what's behind the curtain</description>
	<lastBuildDate>Wed, 01 Sep 2010 02:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Project Euler Problem 113 Solution</title>
		<link>http://blog.dreamshire.com/2009/06/12/project-euler-problem-113-solution/</link>
		<comments>http://blog.dreamshire.com/2009/06/12/project-euler-problem-113-solution/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 21:06:37 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 100-149]]></category>
		<category><![CDATA[Bouncy Numbers]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=1638</guid>
		<description><![CDATA[How many numbers below a googol (10**100) are not "bouncy"?]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.</p>
<p>Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420.</p>
<p>We shall call a positive integer that is neither increasing nor decreasing a &quot;bouncy&quot; number; for example, 155349.</p>
<p>As <i>n</i> increases, the proportion of bouncy numbers below <i>n</i> increases such that there are only 12951 numbers below one-million that are not bouncy and only 277032 non-bouncy numbers below 10<sup>10</sup>.</p>
<p>How many numbers below a googol (10<sup>100</sup>) are not bouncy?</p>
<h4><u>Analysis</u></h4>
<p>Whenever a problem asks for the number of elements in a set, as does this one, then the solution in typically a counting problem solved with combinometrics.</p>
<p>Our solution uses the general formula that counts the monotonically increasing/decreasing digits ignoring leading zeros.</p>
<h4><u>Solution</u></h4>
<p>Runs < 1 second in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> Euler <span style="color: #ff7700;font-weight:bold;">import</span> binomial
&nbsp;
n=<span style="color: #ff4500;">100</span>
<span style="color: #ff7700;font-weight:bold;">print</span> binomial<span style="color: black;">&#40;</span>n+<span style="color: #ff4500;">10</span>,<span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span> + binomial<span style="color: black;">&#40;</span>n+<span style="color: #ff4500;">9</span>,<span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span> - <span style="color: #ff4500;">10</span><span style="color: #66cc66;">*</span>n - <span style="color: #ff4500;">2</span></pre></div></div>

<h4><u>Comments</u></h4>
<p>More information on the <em>Euler</em> module can be found on the <a href="http://blog.dreamshire.com/2009/03/26/94/">tools page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/06/12/project-euler-problem-113-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler Problem 112 Solution</title>
		<link>http://blog.dreamshire.com/2009/06/11/project-euler-problem-112-solution/</link>
		<comments>http://blog.dreamshire.com/2009/06/11/project-euler-problem-112-solution/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 18:22:15 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 100-149]]></category>
		<category><![CDATA[Bouncy Numbers]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=1629</guid>
		<description><![CDATA[Investigating the density of "bouncy" numbers.]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468.</p>
<p>Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420.</p>
<p>We shall call a positive integer that is neither increasing nor decreasing a &quot;bouncy&quot; number; for example, 155349.</p>
<p>Clearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand (525) are bouncy. In fact, the least number for which the proportion of bouncy numbers first reaches 50% is 538.</p>
<p>Surprisingly, bouncy numbers become more and more common and by the time we reach 21780 the proportion of bouncy numbers is equal to 90%.</p>
<p>Find the least number for which the proportion of bouncy numbers is exactly 99%.</p>
<h4><u>Analysis</u></h4>
<p>It was a surprise how long this program took to run.  The <em>is_bouncy()</em> routine seemed to slow things down.  We begin at the 90% point specified in the problem description and wait for the ratio to hit 99%.</p>
<h4><u>Solution</u></h4>
<p>Runs < 7 seconds in Python.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> is_bouncy<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>:
  inc, dec, s = <span style="color: #008000;">False</span>, <span style="color: #008000;">False</span>, <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> s<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&gt;</span> s<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>: inc = <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">elif</span> s<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">&lt;</span> s<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>: dec = <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> inc <span style="color: #ff7700;font-weight:bold;">and</span> dec: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
n, p = <span style="color: #ff4500;">21780</span>, <span style="color: #ff4500;">0.90</span>
b = n <span style="color: #66cc66;">*</span> p
<span style="color: #ff7700;font-weight:bold;">while</span> p <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0.99</span>:
  n += <span style="color: #ff4500;">1</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> is_bouncy<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>: b += <span style="color: #ff4500;">1</span>
  p = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>b<span style="color: black;">&#41;</span>/n
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer to PE112 = &quot;</span>, n</pre></div></div>

<h4><u>Comments</u></h4>
<p>The <em>float()</em> function was required to convert to floating point.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/06/11/project-euler-problem-112-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
