Re: Ruby Quiz #62
- From: James Edward Gray II <james@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 20 Jan 2006 13:12:43 +0900
On Jan 19, 2006, at 8:06 PM, Adam Shelly wrote:
On 1/19/06, James Edward Gray II <james@xxxxxxxxxxxxxxxxxxx> wrote:This version of the code seems to fix at least this case:
There's a small bug in your code, James: If you pass a box that fits the trunk exactly, you get an exception. The culprit is this line from #try_adding box
# score the remaining open space score = rows[1..-2].map { |row| row[/_(_+)/, 1] }.compact. map { |open| open.size }.inject { |sum, n| sum + n }
score is nil if there is no open space. you need to make it ... inject(0) {|sum,n| ...
Great catch again. I'm glad someone is watching over me. I need all the help I can get, as we can see!
You've got a good heuristic, but it still makes mistakes.
Oh, no doubt. Good example.
On a totally unrelated note - I discovered something odd when working on this solution: irb(main):010:0> r=1..9 => 1..9 irb(main):011:0> r.last => 9 irb(main):012:0> r.include? r.last => true irb(main):013:0> r=1...9 => 1...9 irb(main):014:0> r.last => 9 irb(main):015:0> r.include? r.last => false
I really expected (1...9).last to return 8. I guess this is just another way ranges are screwy.
Na, that's not odd at all. Just tell yourself .. is inclusive and ... is exclusive (with regards to the last member). See how that extra dot pushes it off the end there... ;)
James Edward Gray II
.
- Follow-Ups:
- Re: Ruby Quiz #62
- From: Adam Shelly
- Re: Ruby Quiz #62
- From: Jay Anderson
- Re: Ruby Quiz #62
- References:
- Ruby Quiz #62
- From: Andrew Dudzik
- Re: Ruby Quiz #62
- From: James Edward Gray II
- Re: Ruby Quiz #62
- From: Adam Shelly
- Ruby Quiz #62
- Prev by Date: Re: Dictionary of Known English ignore words
- Next by Date: Re: [newbie] this month, the next month, and the one after that
- Previous by thread: Re: Ruby Quiz #62
- Next by thread: Re: Ruby Quiz #62
- Index(es):
Relevant Pages
|