<?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; fractions</title>
	<atom:link href="http://blog.dreamshire.com/tag/fractions/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 33 Solution</title>
		<link>http://blog.dreamshire.com/2009/04/22/project-euler-problem-33-solution/</link>
		<comments>http://blog.dreamshire.com/2009/04/22/project-euler-problem-33-solution/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 06:31:52 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Project Euler Solutions]]></category>
		<category><![CDATA[Solutions 30-39]]></category>
		<category><![CDATA[fractions]]></category>
		<category><![CDATA[Project Euler]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.dreamshire.com/?p=884</guid>
		<description><![CDATA[Discover all the fractions with an unorthodox cancelling method.]]></description>
			<content:encoded><![CDATA[<h4><u>Problem Description</u></h4>
<p>The fraction <sup>49</sup>/<sub>98</sub> is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that <sup>49</sup>/<sub>98</sub> = <sup>4</sup>/<sub>8</sub>, which is correct, is obtained by cancelling the 9s.</p>
<p>We shall consider fractions like, <sup>30</sup>/<sub>50</sub> = <sup>3</sup>/<sub>5</sub>, to be trivial examples.</p>
<p>There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.</p>
<p>If the product of these four fractions is given in its lowest common terms, find the value of the denominator.</p>
<h4><u>Analysis</u></h4>
<p>This is curious problem and was able to solve it in just a few lines and 84 iterations.  Just generated all fractions with 2 digit numerators and denominators and ignored &#8216;trivial&#8217; examples.  Used symmetry to consider distinct fractions &#8211; which was really not necessary, but&#8230;why not.</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;">d = <span style="color: #ff4500;">1</span>
<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;">1</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>:
  <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;">1</span>, i<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> k <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;">1</span>, j<span style="color: black;">&#41;</span>:
      ki = k<span style="color: #66cc66;">*</span><span style="color: #ff4500;">10</span> + i
      ij = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">10</span> + j
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>ij/ki == <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>j<span style="color: black;">&#41;</span>/k<span style="color: black;">&#41;</span>:
        d <span style="color: #66cc66;">*</span>= ij/ki
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Answer to PE33 = &quot;</span>,d</pre></div></div>

<h4><u>Comments</u></h4>
<p>Added the float function to keep calculations from converting to integers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.dreamshire.com/2009/04/22/project-euler-problem-33-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
