[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ] The Golden Fibonacci Ratio (#69

Rudolfs Osins

3/3/2006 2:07:00 PM

So the task is visualisation of the Fibonacci series ?On 3/3/06, Ruby Quiz <james@grayproductions.net> wrote:> The three rules of Ruby Quiz:>> 1. Please do not post any solutions or spoiler discussion for this quiz until> 48 hours have passed from the time on this message.>> 2. Support Ruby Quiz by submitting ideas as often as you can:>> http://www.rubyquiz.co... 3. Enjoy!>> Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone> on Ruby Talk follow the discussion.>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=>> by Enrique Meza C>> You may have noticed that if you have a Golden Rectangle and you cut off a> square with side lengths equal to the length shorter rectangle side, then what> remains is another Golden Rectangle.>> This could go on forever. You can just keep cutting off these big squares and> getting smaller and smaller Golden rectangles.>> The idea with the Fibonacci series is to do the same thing in reverse. So the> quiz:>> What you do is start with a square (1 by 1), find the longer side, and add a> square of that size to the whole thing to form a new rectangle.>> So when we start with a 1 by 1 square the longest side is one, so we add another> square to it. Now we have a 2 by 1 rectangle>> Then the longest side is two, so we connect a 2 by 2 square to our 2 by 1> rectangle to get a 3 by 2 rectangle. This continues, and the sides of the> rectangle will always be a successive Fibonacci number. Eventually the> rectangle will be very close to a Golden Rectangle.>> I will do a few steps to let you see it in action:>> ###> # # 1 by 1, so we add 1 by 1 to get...> ###>> ######> # ## # Now it is 2 by 1, so we add 2 by 2 to get......> ######>> ######> # ## #> ######> ######> # # Now it is 2 by 3, so we add a 3 by 3 to get.......> # #> # #> # #> ######>> ###############> # ## ## #> ####### #> # ## #> # ## # Now it is 3 by 5, so we would add a 5 by 5 square.> # ## #> # ## #> ###############>>
7 Answers

Robert Retzbach

3/3/2006 2:25:00 PM

0

Hi,
the description is really exciting :>
But the main task is for me not clear too.

--verbose please


James Gray

3/3/2006 2:27:00 PM

0

On Mar 3, 2006, at 8:06 AM, Rudolfs Osins wrote:

> So the task is visualisation of the Fibonacci series ?

Correct. In block format.

James Edward Gray II


Jacob Fugal

3/3/2006 5:50:00 PM

0

On 3/3/06, James Edward Gray II <james@grayproductions.net> wrote:
> On Mar 3, 2006, at 8:25 AM, Robert Retzbach wrote:
>
> > Hi,
> > the description is really exciting :>
> > But the main task is for me not clear too.
>
> Basically the goal is to visualize the sequence. Perhaps you want to
> take a parameter and show the blocks that many steps in, or maybe you
> want to make it more like geek cinema and watch the sequence progress
> block by block...
>
> James Edward Gray II

Sample output for my solution, this may be a little clearer than
James' (still requires monospace font, of course):

$ ruby fibonacci_block.rb 6

###########################
# # # # #
##### # #
# # # #
# # # #
# # # #
########### #
# # #
# # #
# # #
# # #
# # #
# # #
# # #
# # #
# # #
###########################

Jacob Fugal


James Gray

3/3/2006 7:16:00 PM

0

On Mar 3, 2006, at 11:50 AM, Jacob Fugal wrote:

> On 3/3/06, James Edward Gray II <james@grayproductions.net> wrote:
>> On Mar 3, 2006, at 8:25 AM, Robert Retzbach wrote:
>>
>>> Hi,
>>> the description is really exciting :>
>>> But the main task is for me not clear too.
>>
>> Basically the goal is to visualize the sequence. Perhaps you want to
>> take a parameter and show the blocks that many steps in, or maybe you
>> want to make it more like geek cinema and watch the sequence progress
>> block by block...
>>
>> James Edward Gray II
>
> Sample output for my solution, this may be a little clearer than
> James' (still requires monospace font, of course):
>
> $ ruby fibonacci_block.rb 6
>
> ###########################
> # # # # #
> ##### # #
> # # # #
> # # # #
> # # # #
> ########### #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> ###########################

It might be good to note that multiple layouts are possible. For
example, the above could also spiral as follows:

###########################
# # #
# # #
# # #
# # #
# # #
# # #
# # #
# # #
# # #
# ###########
# # # # #
# ##### #
# # # #
# # # #
# # # #
###########################

James Edward Gray II



Jacob Fugal

3/3/2006 8:20:00 PM

0

On 3/3/06, James Edward Gray II <james@grayproductions.net> wrote:
> It might be good to note that multiple layouts are possible. For
> example, the above could also spiral as follows:
>
> ###########################
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # # #
> # ###########
> # # # # #
> # ##### #
> # # # #
> # # # #
> # # # #
> ###########################

Good point. I actually like that one better, and have altered my code
to produce it. :)

Jacob Fugal


Brian Mattern

3/4/2006 5:10:00 AM

0

Jacob Fugal wrote:

>On 3/3/06, James Edward Gray II <james@grayproductions.net> wrote:
>
>
>>It might be good to note that multiple layouts are possible. For
>>example, the above could also spiral as follows:
>>
>>###########################
>># # #
>># # #
>># # #
>># # #
>># # #
>># # #
>># # #
>># # #
>># # #
>># ###########
>># # # # #
>># ##### #
>># # # #
>># # # #
>># # # #
>>###########################
>>
>>
>
>Good point. I actually like that one better, and have altered my code
>to produce it. :)
>
>Jacob Fugal
>
>
>
Hi, I'm new to the ruby (and the quiz). I did a quick solution that has
a little cleaner output like so:

+---------------+---------+
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| +-+-+-----+
| | | | |
| +-+-+ |
| | | |
| | | |
| | | |
+---------------+---+-----+

i guess the next step is to animate it.
--
Brian Mattern


ToRA

3/5/2006 11:01:00 AM

0

Of course, when rendering large numbers of squares it can be nice to
shrink things a bit:

11:02:56 - tora@Eustacia:~/ruby/fibonacci
>ruby gfr.rb 8 1
+++--+-------+--------------------+
+++ | | |
| | | | |
+-+--+ | |
| | | |
| | | |
| | | |
| | | |
+----+-------+ |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
+------------+--------------------+

or make them larger...
>ruby gfr.rb 3 3
+--+--+
| | |
| | |
+--+--+
| |
| |
| |
| |
| |
+-----+

(crosses fingers that they render correctly)