|
|
 |
 |
 |
 |
Ruby Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Fwd: Please Forward: Ruby Quiz Submission
Begin forwarded message:
> From: "Justin Ethier" <justin.eth @gmail.com> > Date: May 29, 2007 12:42:14 PM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > Hello Everyone, > Here are links to the code for my solution: > http://justin.ethier.googlepages.com/fractal_model.rb > http://justin.ethier.googlepages.com/fractal_draw.rb > http://justin.ethier.googlepages.com/tc_fractal_modeler.rb > Basically there are 2 parts to it. The first one takes the depth > level and base fractal shape, and recursively creates a list of > directions that can be traced to draw the fractal. For example, the > fractal at level 1 is defined as: > [0, 90, 0, 270, 0] also written as [Right, Up, Right, Down, Right] > The second part creates an RMagick canvas and traces out each line > one-at-a-time to draw the actual fractal. > There are probably more efficient ways of doing this, but this > approach works well at lower levels. > Thanks, > Justin
Begin forwarded message:
> From: David Patterson <bob0the0mig @cox.net> > Date: June 1, 2007 8:22:59 AM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > I've been following Ruby Quiz for the last few months, but this is my > first submission. > This is my hand written code: > (1..100).each {|x| > temp += (x%3==0) ? "Fizz" : "" > temp += (x%5==0) ? "Buzz" : "" > puts (temp.size==0) ? x : temp > } > this didn't run because temp is Nil, which gets me sometimes. > Quick fix to: > (1..100).each {|x| > temp = (x%3==0) ? "Fizz" : "" > temp += (x%5==0) ? "Buzz" : "" > puts (temp.size==0) ? x : temp > } > and it ran fine. I wonder how bad this sort of error would be. > Thanks > for the quizzes! > David Patterson
Begin forwarded message:
> From: "Rene Koning" <rene.kon @gmail.com> > Date: June 1, 2007 9:22:37 AM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > Quiz #126 > I don't know if they would hire me, but this is what I would come > up with in the mentioned circumstances: > class Fixnum > def dividable_by?(num) > self % num == 0 > end > end > (1..100).each do |num| > puts case true > when num.dividable_by?(3*5): "fizzbuzz" > when num.dividable_by?(5): "buzz" > when num.dividable_by?(3): "fizz" > else num.to_s > end > end
Begin forwarded message:
> From: Steven Soroka <ste @clearlinewebsystems.ca> > Date: June 1, 2007 10:38:14 AM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > #!/usr/bin/ruby > class Fixnum > alias_method :old_to_s, :to_s > def to_s > s = "Fizz" if self % 3 == 0 > s = (s || "") + "Buzz" if self % 5 == 0 > "#{s || old_to_s}" > end > end > (1..100).each {|i| puts i } > Steven Soroka > Clearline Web Systems > 1586 Wall Street > Winnipeg, Manitoba R3E 2S4 > http://www.clearlinewebsystems.ca > 204.786.3334
Begin forwarded message:
> From: Jared Haworth <jared.hawo @gmail.com> > Date: June 1, 2007 12:10:27 PM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > Since I'm not a member of the Ruby-Talk list: > 1.upto(100) do |n| > output = Array.new > output << "Fizz" if (n % 3 == 0) > output << "Buzz" if (n % 5 == 0) > output << n if output.empty? > puts output.to_s > end > I tried to strike the right balance between clever and readable. > It's been my experience that people I'm working with would rather > see the simple solution instead of the overly elegant 'Ruby' > solution. Maybe that's the point of the test, not just for me to > show off how awesome I can be, but to show if I can write code that > others can understand? I can't wait to see what some of the others > have come up with, though. > - Jared Haworth
Begin forwarded message:
> From: James Koppel <darmani @yahoo.com> > Date: June 1, 2007 12:37:16 PM CDT > To: submiss @rubyquiz.com, submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > I look forward to seeing if anyone can cut down this ridiculously- > simple problem any further (or obfuscate it interestingly). > 1.upto 100 do |n| > print n unless n % 3 == 0 or n % 5 == 0 > print "Fizz" if n % 3 == 0 > print "Buzz" if n % 5 == 0 > puts > end > The fish are biting. > Get more visitors on your site using Yahoo! Search Marketing.
Begin forwarded message:
> From: "Colin A. Bartlett" <c @kineticweb.com> > Date: June 3, 2007 8:03:28 AM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > #!/usr/bin/env ruby > # > # Created by Colin A. Bartlett on 2007-06-03. > # Copyright (c) 2007. All rights reserved. > # Released under the terms of the MIT license. > (1..100).each do |n| > ret = "" > ret += "Fizz" if n.divmod(3).last == 0 > ret += "Buzz" if n.divmod(5).last == 0 > ret = n if ret == "" > puts ret > end
Begin forwarded message:
> From: "Kevin Barnes" <vinbar @gmail.com> > Date: June 3, 2007 2:22:55 PM CDT > To: submiss @rubyquiz.com > Subject: Please Forward: Ruby Quiz Submission > def say(n) > "%s%s" % [(t=(n%3==0)) ? 'Fizz' : '', (n%5==0) ? 'Buzz' : (t ? > '' : n)] > end > (1..100).each { |n| puts say(n) } > -- > Kevin Barnes
Begin forwarded message:
> From: "Linklater, Lloyd \(IT\)" <LINK @voughtaircraft.com> > Date: June 6, 2007 1:03:25 PM CDT > To: <submiss @rubyquiz.com> > Subject: Please Forward: Ruby Quiz Submission > I saw quiz 61 and wanted to send in something. I am a ruby n00b > and want to contribute if I can. > When generating DND stats, you get to roll 4 dice and use the 3 > best rolls. This is done for 6 stats. My version rolls ten > thousand times and picks a good one from them. This stat list is > then shown with the best stat in the first place and sorted > descending. The idea behind this sorting is more than just making > it easier to read. It allows for other code to place the stats > intelligently. e.g. warriors get strength first, constitution > second, etc. Wizards get intelligence first and dex second, and so > on. > ar = Array.new > stats = Array.new > bestStats = Array.new > 10_000.times do |k| > 6.times do |j| > 4.times {|i| ar[i] = rand(6)} > ar.sort! > stats[j] = ar[1] + ar[2] + ar[3] + 3 > end > bestStats[k] = stats.sort > end > bestStats.sort!.reverse! > p bestStats[0].reverse > I do not know if I am writing good code or not. I am too new to > ruby for that. I can know that it looks good to me and it works. :) > Thanks! > Lloyd Linklater
Begin forwarded message:
> From: "Linklater, Lloyd \(IT\)" <LINK @voughtaircraft.com> > Date: June 6, 2007 1:05:08 PM CDT > To: <submiss @rubyquiz.com> > Subject: Please Forward: Ruby Quiz Submission > ok. oops! The reverses are very important. Here is a fix. I was > giving the worst pick not the best. heh > ar = Array.new > stats = Array.new > bestStats = Array.new > 10_000.times do |k| > 6.times do |j| > 4.times {|i| ar[i] = rand(6)} > ar.sort! > stats[j] = ar[1] + ar[2] + ar[3] + 3 > end > bestStats[k] = stats.sort.reverse > end > bestStats.sort!.reverse! > p bestStats[0]
Begin forwarded message:
> From: "Linklater, Lloyd \(IT\)" <LINK @voughtaircraft.com> > Date: June 6, 2007 1:11:09 PM CDT > To: <submiss @rubyquiz.com> > Subject: Please Forward: Ruby Quiz Submission > Ok, I know that this has got to be annoying, but it is my first > time and I just had to ask. Is this a better way to do it? > ar = Array.new > stats = Array.new > bestStats = Array.new > 10_000.times do |k| > 6.times do |j| > ar = [rand(6), rand(6), rand(6), rand(6)].sort > stats[j] = ar[1] + ar[2] + ar[3] + 3 > end > bestStats[k] = stats.sort.reverse > end > p bestStats.sort.reverse[0] > OK. Even if I think of a super improvement, I will keep it to > myself. Thanks again! > Lloyd Linklater
|
 |
 |
 |
 |
|