{"id":51073,"date":"2010-03-07T00:01:00","date_gmt":"2010-03-07T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2010\/03\/07\/hey-scripting-guy-weekend-scripter-fibonnaci-sequence-this\/"},"modified":"2010-03-07T00:01:00","modified_gmt":"2010-03-07T00:01:00","slug":"hey-scripting-guy-weekend-scripter-fibonnaci-sequence-this","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-weekend-scripter-fibonnaci-sequence-this\/","title":{"rendered":"Hey, Scripting Guy! Weekend Scripter: Fibonnaci Sequence This!"},"content":{"rendered":"<p class=\"MsoNormal\"><img decoding=\"async\" alt=\"Bookmark and Share\" src=\"http:\/\/s7.addthis.com\/static\/btn\/v2\/lg-share-en.gif\" width=\"125\" height=\"16\"><\/p>\n<p class=\"MsoNormal\">Microsoft Scripting Guy Ed Wilson here, it is warming up a bit down here in Charlotte, North Carolina in the United States, and therefore I tend to gravitate outside on weekends. At least, far enough outside to make it to my woodworking shop. Today, I was thinking about building a series of boxes. One of the golden rules in box design is the so-called <a href=\"http:\/\/en.wikipedia.org\/wiki\/Golden_ratio\"><font face=\"Segoe\">golden mean<\/font><\/a>. An off shot of the golden mean, are <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fibonacci_number\"><font face=\"Segoe\">Fibonacci numbers<\/font><\/a> where the next number in a series is made of the two previous numbers. The numbers would look like this:<\/p>\n<\/p>\n<p class=\"CodeBlock\"><font size=\"1\"><font face=\"Lucida Sans Typewriter\">1,2,3,5,8,13,21,34,55,89,144 &hellip;<\/p>\n<p><\/font><\/font><\/p>\n<p class=\"MsoNormal\">What does this series of numbers have to do with woodworking? You can use those numbers as proportions when making a series of stackable boxes, drawers for a chest of drawers, or a set of shelves. <\/p>\n<p class=\"MsoNormal\">An example of how these numbers would look when stacked is seen in the following image.<\/p>\n<p class=\"Fig-Graphic\">\n<p><img decoding=\"async\" title=\"Image of Fibonnaci numbers stacked\" alt=\"Image of Fibonnaci numbers stacked\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/march\/hey0307\/wes-03-07-10-01.jpg\" width=\"237\" height=\"120\">&nbsp;<\/p>\n<p class=\"MsoNormal\">There are functions available on-line that illustrate creating Fibonacci numbers in many different languages. In fact, the <a href=\"http:\/\/get-powershell.com\/2008\/01\/24\/fibonacci-series-in-powershell\/\"><font face=\"Segoe\">Get-PowerShell web site<\/font><\/a> even has one. I decided to write one myself &hellip; admittedly similar to the one that Andy wrote, but still a bit different. One of the cool things about my function is the use of multiple variable assignment in the For statement. This is seen here.<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">For($i = $j = 1; $i -lt $max)<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">Another thing that is cool, is the ability to add multiple values to variables on the same line. This is seen here.<\/p>\n<p class=\"CodeBlock\"><span><font face=\"Lucida Sans Typewriter\">$i,$j = ($i + $j),$i<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">The Get-Fibonacci.ps1 script is seen here. <\/p>\n<p class=\"CodeBlockScreenedHead\"><strong>Get-Fibonacci.ps1<\/p>\n<p><\/strong><\/p>\n<p class=\"CodeBlockScreened\"><span><font face=\"Lucida Sans Typewriter\">Function Get-Fibonacci<br \/>{<br \/><span>&nbsp;<\/span>Param([int]$max)<br \/><span>&nbsp; <\/span>For($i = $j = 1; $i -lt $max)<br \/><span>&nbsp;&nbsp; <\/span>{<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>$i<br \/><span>&nbsp;&nbsp;&nbsp; <\/span>$i,$j = ($i + $j),$i<br \/><span>&nbsp;&nbsp; <\/span>} #end for<br \/>} #end function<\/p>\n<p><\/font><\/span><\/p>\n<p class=\"MsoNormal\">When the function runs, it produces Fibonacci numbers up to the value you supply for <strong>$max<\/strong>. This is seen in the following image.<\/p>\n<p class=\"Fig-Graphic\">\n<p><img decoding=\"async\" title=\"Image of output when script runs\" alt=\"Image of output when script runs\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/hsg\/2010\/march\/hey0307\/wes-03-07-10-02.jpg\" width=\"600\" height=\"460\"><\/p>\n<p class=\"Num-Caption\">\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\">Fibonacci numbers are fun, and provide their own enjoyment. The ability of Windows PowerShell to allow for multiple value assignments in the for statement, and to assign multiple values to variables inside the loop makes the Windows PowerShell coding requirements much easier. This concludes weekend scripter for this weekend. <\/p>\n<p class=\"MsoNormal\">If you want to know exactly what we will be looking at tomorrow, follow us on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\"><font face=\"Segoe\">Twitter<\/font><\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send e-mail to us at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\"><font face=\"Segoe\">scripter@microsoft.com<\/font><\/a> or post them on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\"><font face=\"Segoe\">Official Scripting Guys Forum<\/font><\/a>. See you tomorrow. Until then, peace.<\/p>\n<p class=\"MsoNormal\">\n<p>&nbsp;<\/p>\n<\/p>\n<p><b><span>Ed Wilson and Craig Liebendorfer, Scripting Guys<\/p>\n<p><\/span><\/b><\/p>\n<p><b><span><\/span><\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft Scripting Guy Ed Wilson here, it is warming up a bit down here in Charlotte, North Carolina in the United States, and therefore I tend to gravitate outside on weekends. At least, far enough outside to make it to my woodworking shop. Today, I was thinking about building a series of boxes. One of [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[69,3,4,61,45],"class_list":["post-51073","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-functions","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Microsoft Scripting Guy Ed Wilson here, it is warming up a bit down here in Charlotte, North Carolina in the United States, and therefore I tend to gravitate outside on weekends. At least, far enough outside to make it to my woodworking shop. Today, I was thinking about building a series of boxes. One of [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=51073"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/51073\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=51073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=51073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=51073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}