Re: [QUIZ] Circle Drawing (#166)



Matthew Moss ha scritto:
## Circle Drawing (#166)

This week we're going to keep it simple... very simple.

Given a radius, draw an ASCII circle.

For example:

ruby circle.rb 7

Should produce a circle of radius 7:

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


Note that most fonts do not have a square aspect ratio, which is why the
above output may look like an oval, despite my calculations for a circle. It
is acceptable if your code produces similar output.


However, _for extra credit_ you may support an additional argument that
specifies the aspect ratio (height divided by width).

ruby circle.rb 7 1.4

This should draw a circle of radius 7 with aspect ratio of 1.4. If done
correctly, your output will actually look like a circle (assuming 1.4 is an
accurate measure of the actual aspect ratio).





A bit of ruby art :-)

http://pastie.org/216459
http://pastie.org/216462

I don't know if my benchmark is done properly.. I do it quickly and just
for fun :-) Please give me feedback..

Benchmark details:

num_of_runs = 100
radius = 7
ratio = 2.0

This benchmark has been executed on a MacBook 2,16Ghz with 2Gb of RAM
running Linux Ubuntu 7.10.

Andrea



.



Relevant Pages

  • Re: Pi in non-euclidiean spaces
    ... different on curved surfaces. ... For a surface that isn't flat, this ratio will not be ... For example, on a sphere of radius R, for a circle of radius r ...
    (sci.math)
  • Re: [QUIZ] Random Points within a Circle (#234)
    ... Generating random numbers is a useful feature and Ruby provides us ... The quiz this week ... is to generate random points uniformly distributed within a circle of ... a given radius and position. ...
    (comp.lang.ruby)
  • Re: "Strong typing vs. strong testing" [OT]
    ... the ratio of the circumference of a circle to twice its radius; ... the complex logarithm of -1 divided by the negative of the complex square ...
    (comp.lang.python)
  • Re: Pi in non-euclidiean spaces
    ... Whereas pi is defined as the ratio of the circumference of a circle to ... ratio of lengths of a semicircle to radius .. ... rotation angle unit in a flat plane. ...
    (sci.math)
  • Re: "Strong typing vs. strong testing" [OT]
    ... Incorrect -- it's not necessarily so that the ratio of the ... circumference to the radius of a circle is always the same number. ... But in Euclidean geometry it *can* be proven. ...
    (comp.lang.python)