<?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: Fibonacci Sequence &#8230; in PowerShell</title>
	<atom:link href="http://huddledmasses.org/fibbonaci-sequence-in-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org/fibbonaci-sequence-in-powershell/</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Mon, 15 Mar 2010 20:36:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Joel 'Jaykul' Bennett</title>
		<link>http://huddledmasses.org/fibbonaci-sequence-in-powershell/comment-page-1/#comment-140826</link>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
		<pubDate>Sun, 03 Feb 2008 05:35:47 +0000</pubDate>
		<guid isPermaLink="false">http://HuddledMasses.org/fibbonaci-sequence-in-powershell/#comment-140826</guid>
		<description>Yeah, it&#039;s true, I didn&#039;t think of that when I read it at first, but the example that Hanselman gave in ruby is almost literally PowerShell, except it lacks dollar signs, and has those pesky extra words ;-)   (not sure why his example for ruby assumes the target number is in a variable @size@ already, but let&#039;s go with that, for the sake of equal comparisons):

h5. Ruby

&lt;code lang=&quot;ruby&quot;&gt;
x1,x2 = 0,1; 0.upto(size){puts x1; x1 += x2; x1,x2 = x2,x1}
&lt;/code&gt;

h5. PowerShell

&lt;code lang=&quot;posh&quot;&gt;
$x1,$x2 = 0,1; 0..$size&#124;%{$x1; $x1,$x2 = ($x1+$x2),$x1}
&lt;/code&gt;

Of course, although we all know that these solutions perform *way* better than the recursive algorithms, the only reason anyone bothers with fibonacci as an algorithm is to teach recursion, right?  It&#039;s a simple elegant recursive problem ... and a great example of why recursion isn&#039;t always the right answer, even when it&#039;s elegant. :-&#124;

Oh, and just for the record, if you wanted to get the correct output to match the output of the &quot;fib&quot; function above, you&#039;d need to change it just a tad (I think the Ruby solution is wrong too, but I don&#039;t have an interpreter handy, and I&#039;m in a hurry):

&lt;code lang=&quot;posh&quot;&gt;
$x1,$x2 = 0,1; 0..$size&#124;%{$x1,$x2 = ($x1+$x2),$x1}; $x1
&lt;/code&gt;

See also &quot;Recursion in PowerShell ... Slow&quot;:http://huddledmasses.org/recursion-in-powershell-slow/</description>
		<content:encoded><![CDATA[<p>Yeah, it&#8217;s true, I didn&#8217;t think of that when I read it at first, but the example that Hanselman gave in ruby is almost literally PowerShell, except it lacks dollar signs, and has those pesky extra words <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />    (not sure why his example for ruby assumes the target number is in a variable <code>size</code> already, but let&#8217;s go with that, for the sake of equal comparisons):</p>
<h5>Ruby</h5>
<div class="ruby code ruby" style="font-family:monospace;">
x1,x2 = <span style="color:#006666;">0</span>,<span style="color:#006666;">1</span>; 0.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span>size<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#CC0066; font-weight:bold;">puts</span> x1; x1 <span style="color:#006600; font-weight:bold;">+</span>= x2; x1,x2 = x2,x1<span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp;</div>
<h5>PowerShell</h5>
<div class="posh code posh" style="font-family:monospace;">
<span style="color: #660033; font-weight: bold;">$x1</span>,<span style="color: #660033; font-weight: bold;">$x2</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span>; 0..<span style="color: #660033; font-weight: bold;">$size</span><span style="color: #66cc66;">|%</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$x1</span>; <span style="color: #660033; font-weight: bold;">$x1</span>,<span style="color: #660033; font-weight: bold;">$x2</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$x1</span><span style="color: #66cc66;">+</span><span style="color: #660033; font-weight: bold;">$x2</span><span style="color: #333;">&#41;</span>,<span style="color: #660033; font-weight: bold;">$x1</span><span style="color: #333;">&#125;</span><br />
&nbsp;</div>
<p>Of course, although we all know that these solutions perform <strong>way</strong> better than the recursive algorithms, the only reason anyone bothers with fibonacci as an algorithm is to teach recursion, right?  It&#8217;s a simple elegant recursive problem &#8230; and a great example of why recursion isn&#8217;t always the right answer, even when it&#8217;s elegant. <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_neutral.gif' alt=':-|' class='wp-smiley' /> </p>
<p>Oh, and just for the record, if you wanted to get the correct output to match the output of the &#8220;fib&#8221; function above, you&#8217;d need to change it just a tad (I think the Ruby solution is wrong too, but I don&#8217;t have an interpreter handy, and I&#8217;m in a hurry):</p>
<div class="posh code posh" style="font-family:monospace;">
<span style="color: #660033; font-weight: bold;">$x1</span>,<span style="color: #660033; font-weight: bold;">$x2</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span>; 0..<span style="color: #660033; font-weight: bold;">$size</span><span style="color: #66cc66;">|%</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$x1</span>,<span style="color: #660033; font-weight: bold;">$x2</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$x1</span><span style="color: #66cc66;">+</span><span style="color: #660033; font-weight: bold;">$x2</span><span style="color: #333;">&#41;</span>,<span style="color: #660033; font-weight: bold;">$x1</span><span style="color: #333;">&#125;</span>; <span style="color: #660033; font-weight: bold;">$x1</span><br />
&nbsp;</div>
<p>See also <a href="http://huddledmasses.org/recursion-in-powershell-slow/">Recursion in PowerShell &#8230; Slow</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffery Hicks</title>
		<link>http://huddledmasses.org/fibbonaci-sequence-in-powershell/comment-page-1/#comment-140376</link>
		<dc:creator>Jeffery Hicks</dc:creator>
		<pubDate>Thu, 31 Jan 2008 19:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://HuddledMasses.org/fibbonaci-sequence-in-powershell/#comment-140376</guid>
		<description>I just found this mentioned on a related blog from Bruce&#039;s book (I must have not gotten that far yet) which is even better.  This will display the sequence up to 1000

$c=$p=1; while ($c -lt 1000) { $c; $c,$p = ($c+$p), $c }</description>
		<content:encoded><![CDATA[<p>I just found this mentioned on a related blog from Bruce&#8217;s book (I must have not gotten that far yet) which is even better.  This will display the sequence up to 1000</p>
<p>$c=$p=1; while ($c -lt 1000) { $c; $c,$p = ($c+$p), $c }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeffery Hicks</title>
		<link>http://huddledmasses.org/fibbonaci-sequence-in-powershell/comment-page-1/#comment-140375</link>
		<dc:creator>Jeffery Hicks</dc:creator>
		<pubDate>Thu, 31 Jan 2008 19:26:52 +0000</pubDate>
		<guid isPermaLink="false">http://HuddledMasses.org/fibbonaci-sequence-in-powershell/#comment-140375</guid>
		<description>This only gives you the last number in the sequence. Here&#039;s a solution I came up with awhile ago (I&#039;m very geeky for stuff like this) that uses recursion so you get the full sequence:

Function Get-Fibonacci {
    Param([int]$n=0)

    if ($n -eq 0) {$result = 0}
    elseif ($n -eq 1) { $result =1}
    else {
    
    $result=(Get-Fibonacci($n-1)) + (Get-Fibonacci ($n-2))
    }
    
    write $result 

}

for ($x=0;$x -le 11;$x++) {
    Get-Fibonacci $x
}</description>
		<content:encoded><![CDATA[<p>This only gives you the last number in the sequence. Here&#8217;s a solution I came up with awhile ago (I&#8217;m very geeky for stuff like this) that uses recursion so you get the full sequence:</p>
<p>Function Get-Fibonacci {<br />
    Param([int]$n=0)</p>
<p>    if ($n -eq 0) {$result = 0}<br />
    elseif ($n -eq 1) { $result =1}<br />
    else {</p>
<p>    $result=(Get-Fibonacci($n-1)) + (Get-Fibonacci ($n-2))<br />
    }</p>
<p>    write $result </p>
<p>}</p>
<p>for ($x=0;$x -le 11;$x++) {<br />
    Get-Fibonacci $x<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://huddledmasses.org/fibbonaci-sequence-in-powershell/comment-page-1/#comment-140353</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Thu, 31 Jan 2008 15:55:07 +0000</pubDate>
		<guid isPermaLink="false">http://HuddledMasses.org/fibbonaci-sequence-in-powershell/#comment-140353</guid>
		<description>I like the pipeline method. Very cool. You can also use double variable assignment.

http://www.get-powershell.com/
http://getpowershell.wordpress.com/2008/01/24/fibonacci-series-in-powershell/</description>
		<content:encoded><![CDATA[<p>I like the pipeline method. Very cool. You can also use double variable assignment.</p>
<p><a href="http://www.get-powershell.com/" rel="nofollow">http://www.get-powershell.com/</a><br />
<a href="http://getpowershell.wordpress.com/2008/01/24/fibonacci-series-in-powershell/" rel="nofollow">http://getpowershell.wordpress.com/2008/01/24/fibonacci-series-in-powershell/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
