<?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: The Golden Ratio</title>
	<atom:link href="http://blog.jayway.com/2009/10/24/the-golden-ratio/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com/2009/10/24/the-golden-ratio/</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sun, 12 Feb 2012 05:23:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Ulrik Sandberg</title>
		<link>http://blog.jayway.com/2009/10/24/the-golden-ratio/comment-page-1/#comment-15848</link>
		<dc:creator>Ulrik Sandberg</dc:creator>
		<pubDate>Sun, 15 Nov 2009 18:34:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jayway.com/?p=2139#comment-15848</guid>
		<description>I had expected some Scala wizards to criticize my feeble attempt at coding an algorithm in Scala, but it didn&#039;t happen. So I&#039;ll do it myself instead.

What do I really want to do? If n is 1, the larger number should be divided by the smaller number. Otherwise, calculate the sum of the numbers and repeat on the larger number and the sum,  for one less iteration. 

I&#039;ll start the interactive Scala shell and type this in:

scala&gt;  def phi(a:Double, b:Double, n:Int): Double = n match {
     &#124; case 1 =&gt; (a max b)/(a min b)                          
     &#124; case _ =&gt; phi((a max b), a+b, n-1)                     
     &#124; }
phi: (Double,Double,Int)Double

Testing it, and what do you know? It works:

scala&gt; phi(5., 8., 20)
res1: Double = 1.618033988957902</description>
		<content:encoded><![CDATA[<p>I had expected some Scala wizards to criticize my feeble attempt at coding an algorithm in Scala, but it didn&#8217;t happen. So I&#8217;ll do it myself instead.</p>
<p>What do I really want to do? If n is 1, the larger number should be divided by the smaller number. Otherwise, calculate the sum of the numbers and repeat on the larger number and the sum,  for one less iteration. </p>
<p>I&#8217;ll start the interactive Scala shell and type this in:</p>
<p>scala&gt;  def phi(a:Double, b:Double, n:Int): Double = n match {<br />
     | case 1 =&gt; (a max b)/(a min b)<br />
     | case _ =&gt; phi((a max b), a+b, n-1)<br />
     | }<br />
phi: (Double,Double,Int)Double</p>
<p>Testing it, and what do you know? It works:</p>
<p>scala&gt; phi(5., 8., 20)<br />
res1: Double = 1.618033988957902</p>
]]></content:encoded>
	</item>
</channel>
</rss>

