[#150244] Defining regexp's and variables set by them — Garance A Drosehn <drosihn@...>

Sometimes I get in a situation where I have a case statement

13 messages 2005/08/01

[#150361] algorithm help — "Ara.T.Howard" <Ara.T.Howard@...>

14 messages 2005/08/02

[#150371] Style question: when to use underscores — "francisrammeloo@..." <francisrammeloo@...>

When should you use underscores to

14 messages 2005/08/02

[#150385] different order of parameters... — JZ <usenet@...>

I'm trying to understand how to call methods in Ruby. Is it possible to

13 messages 2005/08/02
[#150387] Re: different order of parameters... — Yukihiro Matsumoto <matz@...> 2005/08/02

Hi,

[#150439] enum collection of constant values — Garance A Drosehn <drosihn@...>

I'd like to have a set of constants for a class, where their values

18 messages 2005/08/02

[#150451] setting up ruby on os x 10.2 — Julian Leviston <julian@...>

Hi All!

12 messages 2005/08/02

[#150495] array or with non-array — Simon Strandgaard <neoneye@...>

Sometimes wish that [3, 5, 13] | [8] can be written as [3, 5, 13] | 8

30 messages 2005/08/02
[#150502] Re: [RCR] array or with non-array — Eric Mahurin <eric_mahurin@...> 2005/08/02

--- Simon Strandgaard <neoneye@gmail.com> wrote:

[#150506] Re: [RCR] array or with non-array — Yukihiro Matsumoto <matz@...> 2005/08/02

Hi,

[#150519] Re: [RCR] array or with non-array — Eric Mahurin <eric_mahurin@...> 2005/08/03

--- Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

[#150581] ruby-dev summary 26468-26661 — Takaaki Tateishi <ttate@...>

Here are recent ruby-dev summaries.

52 messages 2005/08/03
[#150710] Re: ruby-dev summary 26468-26661 — "David A. Black" <dblack@...> 2005/08/04

Hi --

[#150715] Re: ruby-dev summary 26468-26661 — Jamis Buck <jamis@37signals.com> 2005/08/04

On Aug 4, 2005, at 7:31 AM, David A. Black wrote:

[#150717] Re: ruby-dev summary 26468-26661 — Brian Schrer <ruby.brian@...> 2005/08/04

On 04/08/05, Jamis Buck <jamis@37signals.com> wrote:

[#150740] Re: ruby-dev summary 26468-26661 — Christian Neukirchen <chneukirchen@...> 2005/08/04

Jamis Buck <jamis@37signals.com> writes:

[#150742] Re: ruby-dev summary 26468-26661 — Yukihiro Matsumoto <matz@...> 2005/08/04

Hi,

[#150608] interesting test tool... looking for opinions. — Jeff Wood <jeff.darklight@...>

There is wonderful java-based testing unit framework called TestNG.

24 messages 2005/08/03
[#150646] Re: interesting test tool... looking for opinions. — "Ryan Leavengood" <mrcode@...> 2005/08/03

Jeff Wood said:

[#150648] Re: interesting test tool... looking for opinions. — Austin Ziegler <halostatue@...> 2005/08/03

On 8/3/05, Ryan Leavengood <mrcode@netrox.net> wrote:

[#150653] Re: interesting test tool... looking for opinions. — Alexandru Popescu <the_mindstorm@...> 2005/08/04

#: Austin Ziegler changed the world a bit at a time by saying on 8/4/2005 1:16 AM :#

[#150659] Re: interesting test tool... looking for opinions. — Jeff Wood <jeff.darklight@...> 2005/08/04

well, first we'll need to get matz input on adding attributes @ the

[#150662] Re: interesting test tool... looking for opinions. — Austin Ziegler <halostatue@...> 2005/08/04

On 8/3/05, Jeff Wood <jeff.darklight@gmail.com> wrote:

[#150666] Re: interesting test tool... looking for opinions. — Jeff Wood <jeff.darklight@...> 2005/08/04

I like your second one better ... my only question would then be your

[#150674] Re: interesting test tool... looking for opinions. — Austin Ziegler <halostatue@...> 2005/08/04

On 8/3/05, Jeff Wood <jeff.darklight@gmail.com> wrote:

[#150709] new block notation (was: Re: ruby-dev summary 26468-26661) — "Martin Elzen" <martinelzen@...>

>Now ruby(HEAD) accepts the notation '->(...){...}'

155 messages 2005/08/04
[#150767] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Brian Wisti <brian.wisti@...> 2005/08/04

On 8/4/05, Martin Elzen <martinelzen@hotmail.com> wrote:

[#150799] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Yukihiro Matsumoto <matz@...> 2005/08/04

Hi,

[#150801] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Eric Mahurin <eric_mahurin@...> 2005/08/04

--- Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

[#150802] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Yukihiro Matsumoto <matz@...> 2005/08/04

Hi,

[#150817] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Florian Gro<florgro@...> 2005/08/05

Yukihiro Matsumoto wrote about new lambda syntaxes:

[#150822] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Yukihiro Matsumoto <matz@...> 2005/08/05

Hi,

[#150836] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Florian Groß <florgro@...> 2005/08/05

Yukihiro Matsumoto wrote:

[#150843] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Yukihiro Matsumoto <matz@...> 2005/08/05

Hi,

[#150901] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Florian Gro<florgro@...> 2005/08/05

Yukihiro Matsumoto wrote:

[#150980] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Yukihiro Matsumoto <matz@...> 2005/08/06

Hi,

[#151018] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Florian Gro<florgro@...> 2005/08/06

Yukihiro Matsumoto wrote:

[#150872] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Gavin Kistner <gavin@...> 2005/08/05

On Aug 4, 2005, at 11:58 PM, Yukihiro Matsumoto wrote:

[#150978] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Yukihiro Matsumoto <matz@...> 2005/08/06

Hi,

[#150995] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Gavin Kistner <gavin@...> 2005/08/06

On Aug 6, 2005, at 1:57 AM, Yukihiro Matsumoto wrote:

[#150866] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — "James F. Hranicky" <jfh@...> 2005/08/05

On Fri, 5 Aug 2005 09:49:28 +0900

[#150870] Re: new block notation (was: Re: ruby-dev summary 26468-26661) — Jason Foreman <threeve.org@...> 2005/08/05

I hadn't seen this particular variant posted in this thread yet.

[#150842] Re: new block notation — Martin DeMello <martindemello@...> 2005/08/05

Eric Mahurin <eric_mahurin@yahoo.com> wrote:

[#150855] Re: new block notation — "Trans" <transfire@...> 2005/08/05

> That's rather drastic. All it needs is a new symbol for literal hashes.

[#151008] Re: new block notation — Daniel Brockman <daniel@...> 2005/08/06

"David A. Black" <dblack@wobblini.net> writes:

[#150881] Please help make CodeZoo truly useful — Curt Hibbs <curt@...>

I just posted this on my blog (http://blog.curthibbs.us/), but I thought

14 messages 2005/08/05

[#151017] OSCON videos, medias — why the lucky stiff <ruby-talk@...>

My friends, I've got my act together now and a BitTorrent tracker up

18 messages 2005/08/06

[#151080] cartesian product — "walter a kehowski" <wkehowski@...>

Hello,

26 messages 2005/08/07

[#151096] Adding yet another Array.new form — Nikolai Weibull <mailing-lists.ruby-talk@...>

How about adding a fifth way of constructing new arrays?:

18 messages 2005/08/07

[#151147] sending an email with an attachment in ruby — Matthew Margolis <mrmargolis@...>

I would like to send email from a server running FreeBSD(TextDrive) to

12 messages 2005/08/07

[#151162] String#to_ary and Test::Unit — "Trans" <transfire@...>

In Facets I offer:

14 messages 2005/08/08

[#151202] FXRuby or wxRuby? — baalbek <rcs@...>

I know wxWindows for C++ rather well, and have started to use wxRuby.

29 messages 2005/08/08

[#151224] Re: polymorphism and/or named parameters: the ruby way? — "Berger, Daniel" <Daniel.Berger@...>

> -----Original Message-----

14 messages 2005/08/08
[#151235] Re: polymorphism and/or named parameters: the ruby way? — Eric Mahurin <eric_mahurin@...> 2005/08/08

--- "Berger, Daniel" <Daniel.Berger@qwest.com> wrote:

[#151377] event driven framework for ruby — snacktime <snacktime@...>

Is there an event driven framework for ruby? Something similar to POE

30 messages 2005/08/09
[#151381] Re: event driven framework for ruby — zedshaw@... 2005/08/09

Actually, yes. I'm working on the Ruby/Event library. It's a C extension

[#151384] Re: event driven framework for ruby — James Edward Gray II <james@...> 2005/08/09

On Aug 9, 2005, at 12:23 PM, zedshaw@zedshaw.com wrote:

[#151389] Re: event driven framework for ruby — Yohanes Santoso <ysantoso-rubytalk@...> 2005/08/09

James Edward Gray II <james@grayproductions.net> writes:

[#151394] Re: event driven framework for ruby — James Edward Gray II <james@...> 2005/08/09

On Aug 9, 2005, at 12:57 PM, Yohanes Santoso wrote:

[#151400] Re: event driven framework for ruby — Yohanes Santoso <ysantoso-rubytalk@...> 2005/08/09

James Edward Gray II <james@grayproductions.net> writes:

[#151405] Re: event driven framework for ruby — James Edward Gray II <james@...> 2005/08/09

On Aug 9, 2005, at 2:22 PM, Yohanes Santoso wrote:

[#151445] Re: event driven framework for ruby — Tanaka Akira <akr@...17n.org> 2005/08/10

In article <84D5D729-3674-4084-A092-2359932E2FF4@grayproductions.net>,

[#151414] NitroHQ been vandalised? — John Carter <john.carter@...>

I went looking for the Nitro homepage to give it a mention to our

13 messages 2005/08/09

[#151441] NEWBIE QUESTION: pattern with nil — "basi" <basi_lio@...>

Hello,

33 messages 2005/08/10
[#151465] Re: NEWBIE QUESTION: pattern with nil — BearItAll <bearitall@...> 2005/08/10

On Wed, 10 Aug 2005 14:44:15 +0900, John Carter wrote:

[#151480] Re: NEWBIE QUESTION: pattern with nil — Austin Ziegler <halostatue@...> 2005/08/10

On 8/10/05, BearItAll <bearitall@rassler.co.uk> wrote:

[#151605] Re: NEWBIE QUESTION: pattern with nil — John Carter <john.carter@...> 2005/08/10

On Wed, 10 Aug 2005, Austin Ziegler wrote:

[#151517] Threading on Win32 - at an impasse — Bill Atkins <batkins57@...>

I'm working on a project that would have to run several TCPServer's in

15 messages 2005/08/10
[#151526] Re: Threading on Win32 - at an impasse — david@... 2005/08/10

Cit疸 Bill Atkins <batkins57@gmail.com>:

[#151627] Ruby report generation tool — "Greg Brown" <greg7224@...>

For as long as I can remember the end of the summer meant slaving over

20 messages 2005/08/11

[#151653] cartesian product - next to last version — "walter a kehowski" <wkehowski@...>

Hello,

12 messages 2005/08/11

[#151657] Performance Ruby — "Goel" <spam@...>

Hi,

26 messages 2005/08/11

[#151692] Re: Ruby report generation tool — "Berger, Daniel" <Daniel.Berger@...>

> -----Original Message-----

14 messages 2005/08/11

[#151723] Problems with Net::HTTP.get — Marek Kubica <pythonmailing@...>

Hello!

13 messages 2005/08/11

[#151735] Dear RubyGems: Perhaps a better way to override require... — "Trans" <transfire@...>

I may have found a much better way to override Kernel#require. Here's

16 messages 2005/08/11
[#151743] Re: Dear RubyGems: Perhaps a better way to override require... — Chad Fowler <chadfowler@...> 2005/08/11

On 8/11/05, Trans <transfire@gmail.com> wrote:

[#151768] Re: Dear RubyGems: Perhaps a better way to override require... — "Trans" <transfire@...> 2005/08/11

Hi Chad,

[#151774] Re: Dear RubyGems: Perhaps a better way to override require... — Chad Fowler <chadfowler@...> 2005/08/11

On 8/11/05, Trans <transfire@gmail.com> wrote:

[#151783] Re: Dear RubyGems: Perhaps a better way to override require... — "Ryan Leavengood" <mrcode@...> 2005/08/11

Chad Fowler said:

[#151758] Setting up Eclipse for Ruby — "francisrammeloo@..." <francisrammeloo@...>

Hi all,

14 messages 2005/08/11

[#151877] Another newbie question — "len" <lsumnler@...>

I am trying to write a small little program that will currently run in

20 messages 2005/08/12

[#151897] Ruby Performance — Bradley Kite <bradley.kite@...>

Hi all,

88 messages 2005/08/12
[#151909] Re: Ruby Performance — "Robert Klemme" <bob.news@...> 2005/08/12

Bradley Kite wrote:

[#151914] Re: Ruby Performance — Bradley Kite <bradley.kite@...> 2005/08/12

Those idioms are around 21 seconds each in Ruby.

[#152316] Re: Ruby Performance — "Isaac Gouy" <igouy@...> 2005/08/16

Austin Ziegler wrote:

[#152149] RubyGems or any HTTP on XP NOT working — mycallidus@...

I tried to start learning Ruby by installing Ruby & Rails on XP, and it

13 messages 2005/08/14

[#152151] hacker logo — "walter a kehowski" <wkehowski@...>

http://paulgraham.com/index.html -> http://reddit.com/ ->

15 messages 2005/08/14
[#152155] Re: hacker logo — Nikolai Weibull <mailing-lists.ruby-talk@...> 2005/08/15

walter a kehowski wrote:

[#152186] Troubles with the installation of RAILS — Jan Meskens <janmeskens@...>

Hello,

16 messages 2005/08/15

[#152208] Building a REPL for Ruby — Shalev NessAiver <shalev@...>

Yes, I know ruby already has irb, but I have a friend who keeps

19 messages 2005/08/15

[#152290] New site built using Ruby on Rails — David Teare <dteare@...>

Hi all,

23 messages 2005/08/15

[#152375] Ruby for my new business? — Jared Nuzzolillo <onceuponapriori@...>

Hello list. I am in the process of starting a new business venture in South

30 messages 2005/08/16

[#152434] Ruby on Unix vs. Windows — Rick Nooner <rick@...>

Yesterday at work we took an analysis program written in ruby that we had been

13 messages 2005/08/16

[#152451] Generic Parsing Library — "Adam Sanderson" <netghost@...>

I was wondering if anyone would be interested in, or knows of a generic

16 messages 2005/08/16

[#152535] Newbie question — "len" <lsumnler@...>

Is there some difference in the code I'm not seeing or is one better

18 messages 2005/08/17

[#152556] Prototype-based / Ruby question — "zimba.tm@..." <zimba.tm@...>

I just stumbled across this page[1] on RubyGarden. The writer tells

20 messages 2005/08/17
[#152578] Re: Prototype-based / Ruby question — Gavin Kistner <gavin@...> 2005/08/17

On Aug 17, 2005, at 2:21 AM, zimba.tm@gmail.com wrote:

[#152585] Re: Prototype-based / Ruby question — Lyndon Samson <lyndon.samson@...> 2005/08/17

I'd say prototype means no classes, that is create an Object from another (

[#152666] Novice Q: What's the difference between /\s*/ and /(\s)*/? — "Mike Meng" <meng.yan@...>

Hi,

13 messages 2005/08/18

[#152723] Idiomatic ruby version of this code? — Brock Weaver <brockweaver@...>

Showing off ruby to a coworker, and I want to emphasize how succinct yet

17 messages 2005/08/18

[#152740] Ruby Specifications — Brian Mitchell <binary42@...>

Over the past few days I've been working on implementing my own (yet

14 messages 2005/08/18

[#152772] Protecting commercial ruby code with public/private key encryption — "John Wells" <lists@...>

I was speaking with a co-worker today about the disappointment we feel

30 messages 2005/08/18

[#152776] Python vs Ruby! — Joe Van Dyk <joevandyk@...>

Which is better, Python or Ruby?

45 messages 2005/08/18
[#152828] Re: Python vs Ruby! — Jamey Cribbs <jcribbs@...> 2005/08/19

Joe Van Dyk wrote:

[#152777] New to Ruby! — Seth Thomas Rasmussen <sethrasmussen@...>

Hi all,

16 messages 2005/08/18

[#152780] AIX and Ruby issues (still) — ober <ober@...>

I know this is a thorn to bring up every so often.

15 messages 2005/08/18

[#152843] RedCloth .... PILES of warnings when I require it ... — Jeff Wood <jeff.darklight@...>

I've downloaded and have the Gem for RedCloth 3.0.3 installed.

11 messages 2005/08/19

[#152892] Sodoku Solver (#43) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

43 messages 2005/08/19
[#153016] Re: [QUIZ] Sodoku Solver (#43) — Karl von Laudermann <karlvonl@...> 2005/08/20

In article

[#153292] Re: [QUIZ] Sodoku Solver (#43) — Adam Shelly <adam.shelly@...> 2005/08/23

Hi. This is my first attempt at a ruby quiz, and my first post to ruby-talk.

[#153297] Re: [QUIZ] Sodoku Solver (#43) — James Edward Gray II <james@...> 2005/08/23

On Aug 22, 2005, at 9:08 PM, Adam Shelly wrote:

[#153314] Re: [QUIZ] Sodoku Solver (#43) — Adam Shelly <adam.shelly@...> 2005/08/23

Ok, I've updated my version to resort to guessing when it can't deduce

[#153348] Re: [QUIZ] Sodoku Solver (#43) — "Dominik Bathon" <dbatml@...> 2005/08/23

On Tue, 23 Aug 2005 13:54:25 +0200, Adam Shelly <adam.shelly@gmail.com>

[#153353] Re: [QUIZ] Sodoku Solver (#43) — Adam Shelly <adam.shelly@...> 2005/08/23

On 8/23/05, Dominik Bathon <dbatml@gmx.de> wrote:

[#153374] Re: [QUIZ] Sodoku Solver (#43) — David Brady <ruby_talk@...> 2005/08/24

Adam Shelly wrote:

[#153067] Still looking for a Ruby MUD client — Sy <sy1234@...>

I'm still looking for a Ruby-scriptable Telnet/MUD client. Does

52 messages 2005/08/20
[#154216] Re: Still looking for a Ruby MUD client — "Dave Burt" <dave@...> 2005/08/30

Jon wrote:

[#154219] Re: Still looking for a Ruby MUD client — Reyn Vlietstra <reyn.vlietstra@...> 2005/08/30

Have a look at my mud,

[#154246] Re: Still looking for a Ruby MUD client — Sy <sy1234@...> 2005/08/30

I look for months for a ruby mud client or at least something that can

[#154258] Re: Still looking for a Ruby MUD client — James Edward Gray II <james@...> 2005/08/30

On Aug 30, 2005, at 7:47 AM, Sy wrote:

[#154293] Re: Still looking for a Ruby MUD client — Sy <sy1234@...> 2005/08/30

On 8/30/05, James Edward Gray II <james@grayproductions.net> wrote:

[#154514] Re: Still looking for a Ruby MUD client — <agemoagemo@...> 2005/08/31

--- Sy <sy1234@gmail.com> wrote:

[#154535] Re: Still looking for a Ruby MUD client — Sy <sy1234@...> 2005/08/31

On 8/31/05, agemoagemo@yahoo.com <agemoagemo@yahoo.com> wrote:

[#154541] Re: Still looking for a Ruby MUD client — Greg Millam <ruby-talk@...> 2005/08/31

> > The main reason that I, at least, am using net/telnet

[#154579] Re: Still looking for a Ruby MUD client — <agemoagemo@...> 2005/09/01

--- Greg Millam <ruby-talk@lethalcode.net> wrote:

[#153101] www.ruby.net — Daniel Schierbeck <daniel.schierbeck@...>

I don't know if this has been discussed before (didn't find any messages

46 messages 2005/08/21
[#153110] Re: www.ruby.net — nobu.nokada@... 2005/08/21

Hi,

[#153112] Re: www.ruby.net — Daniel Schierbeck <daniel.schierbeck@...> 2005/08/21

nobu.nokada@softhome.net wrote:

[#153113] Re: www.ruby.net — Paul van Tilburg <paul@...> 2005/08/21

On Sun, Aug 21, 2005 at 09:36:17PM +0900, Daniel Schierbeck wrote:

[#153380] The Chainsaw Infanticide Logger Manuever — "Zed A. Shaw" <zedshaw@...>

One of the things that's really great about agile languages is they give you the power to do anything. One of the most horrible things about agile languages is they give every other idiot the same power to stab you in the back with a rusty pitchfork.

37 messages 2005/08/24
[#153439] Re: The Chainsaw Infanticide Logger Manuever — "Bill Kelly" <billk@...> 2005/08/24

From: "Zed A. Shaw" <zedshaw@zedshaw.com>

[#153445] Re: The Chainsaw Infanticide Logger Manuever — Jeff Wood <jeff.darklight@...> 2005/08/24

My feelings are in-line with the review of Dave's session as OSCON @

[#153414] determining the attribute names of an object — Mark Volkmann <r.mark.volkmann@...>

The way to determine the names of the attributes of objects created

16 messages 2005/08/24
[#153417] Re: determining the attribute names of an object — "David A. Black" <dblack@...> 2005/08/24

Hi --

[#153419] Re: determining the attribute names of an object — Mark Volkmann <r.mark.volkmann@...> 2005/08/24

On 8/24/05, David A. Black <dblack@wobblini.net> wrote:

[#153422] Good cross-platform IDE / multiple document text editor for ruby / rails? — Brock Weaver <brockweaver@...>

I apologize for the cross-post, but I thought it would spur a good

55 messages 2005/08/24
[#153426] Re: Good cross-platform IDE / multiple document text editor for ruby / rails? — Aaron Kulbe <akulbe@...> 2005/08/24

What about vim?

[#153548] Re: Good cross-platform IDE / multiple document text editor for ruby / rails? — tony summerfelt <snowzone5@...> 2005/08/25

Brock Weaver wrote on 8/24/2005 10:51 AM:

[#153570] Re: Good cross-platform IDE / multiple document text editor for ruby / rails? — Randy Kramer <rhkramer@...> 2005/08/25

On Thursday 25 August 2005 08:15 am, tony summerfelt wrote:

[#153793] Re: Good cross-platform IDE / multiple document text editor for ruby / rails? — Lothar Scholz <mailinglists@...> 2005/08/26

Hello Randy,

[#153842] Re: Good cross-platform IDE / multiple document text editor for ruby / rails? — Randy Kramer <rhkramer@...> 2005/08/27

On Friday 26 August 2005 07:56 pm, Lothar Scholz wrote:

[#153869] Re: Good cross-platform IDE / multiple document text editor for ruby / rails? — Lothar Scholz <mailinglists@...> 2005/08/28

Hello Randy,

[#153456] ruby way for piece of code — Alexandru Popescu <the.mindstorm.mailinglist@...>

Hi!

10 messages 2005/08/24

[#153513] Bokeo 0.25 - The initial release of an FXRuby interface to RubyGems — Richard Lyman <lymans@...>

I'm pleased to announce the initial release of Bokeo, an FXRuby

9 messages 2005/08/24

[#153562] idea: klass.from_s(str) — Eric Mahurin <eric_mahurin@...>

I was thinking how in seems a little asymmetric that many

18 messages 2005/08/25
[#153574] Re: idea: klass.from_s(str) — "David A. Black" <dblack@...> 2005/08/25

Hi --

[#153566] EventLoop 0.0.20050825.1600 — Daniel Brockman <daniel@...>

Hi list,

40 messages 2005/08/25

[#153656] rmagick question — Joe Van Dyk <joevandyk@...>

I'm trying to set the pixels of an image:

31 messages 2005/08/26
[#153673] Re: rmagick question — Brian Schrer <ruby.brian@...> 2005/08/26

On 26/08/05, Joe Van Dyk <joevandyk@gmail.com> wrote:

[#153714] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/26

On 8/26/05, Brian Schrer <ruby.brian@gmail.com> wrote:

[#153746] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/26

On 8/26/05, Joe Van Dyk <joevandyk@gmail.com> wrote:

[#153747] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/26

On 8/26/05, Joe Van Dyk <joevandyk@gmail.com> wrote:

[#153750] Re: rmagick question — "Ara.T.Howard" <Ara.T.Howard@...> 2005/08/26

On Sat, 27 Aug 2005, Joe Van Dyk wrote:

[#153752] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/26

On 8/26/05, Ara.T.Howard <Ara.T.Howard@noaa.gov> wrote:

[#153942] Re: rmagick question — Timothy Hunter <cyclists@...> 2005/08/28

Joe Van Dyk wrote:

[#153947] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/28

On 8/28/05, Timothy Hunter <cyclists@nc.rr.com> wrote:

[#153971] Re: rmagick question — Timothy Hunter <cyclists@...> 2005/08/29

Joe Van Dyk wrote:

[#154011] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/29

On 8/28/05, Timothy Hunter <cyclists@nc.rr.com> wrote:

[#154034] Re: rmagick question — Timothy Hunter <cyclists@...> 2005/08/29

Joe Van Dyk wrote:

[#154163] Re: rmagick question — Joe Van Dyk <joevandyk@...> 2005/08/29

On 8/29/05, Timothy Hunter <cyclists@nc.rr.com> wrote:

[#153662] DRb functions disappearing? — Kevin Brown <blargity@...>

I will start by admitting I'm new to Ruby, but am generally a quick learner.

18 messages 2005/08/26
[#153667] Re: DRb functions disappearing? — Eric Hodel <drbrain@...7.net> 2005/08/26

On 25 Aug 2005, at 21:49, Kevin Brown wrote:

[#153668] Re: DRb functions disappearing? — Kevin Brown <blargity@...> 2005/08/26

On Friday 26 August 2005 01:14, Eric Hodel wrote:

[#153670] Re: DRb functions disappearing? — Eric Hodel <drbrain@...7.net> 2005/08/26

On 26 Aug 2005, at 00:32, Kevin Brown wrote:

[#153671] Re: DRb functions disappearing? — Kevin Brown <blargity@...> 2005/08/26

On Friday 26 August 2005 02:08, Eric Hodel wrote:

[#153672] Method behaves differently when called using #send — Ron M <rm_rails@...>

I'm having difficulty using #send to call methods in

117 messages 2005/08/26
[#153723] Re: Method behaves differently when called using #send — calamitas@... 2005/08/26

On Fri, 26 Aug 2005, Ron M wrote:

[#153828] Re: Method behaves differently when called using #send — Yukihiro Matsumoto <matz@...> 2005/08/27

Hi,

[#153833] Re: Method behaves differently when called using #send — "David A. Black" <dblack@...> 2005/08/27

Hi --

[#153938] Re: Method behaves differently when called using #send — "daz" <dooby@...10.karoo.co.uk> 2005/08/28

[#153963] Re: Method behaves differently when called using #send — "David A. Black" <dblack@...> 2005/08/28

Hi --

[#154105] Re: Method behaves differently when called using #send — Yukihiro Matsumoto <matz@...> 2005/08/29

Hi,

[#154107] Re: Method behaves differently when called using #send — "David A. Black" <dblack@...> 2005/08/29

Hi --

[#154110] Re: Method behaves differently when called using #send — Yukihiro Matsumoto <matz@...> 2005/08/29

Hi,

[#154204] Re: Method behaves differently when called using #send — Yukihiro Matsumoto <matz@...> 2005/08/30

Hi,

[#154210] Re: Method behaves differently when called using #send — "Trans" <transfire@...> 2005/08/30

[#154213] Re: Method behaves differently when called using #send — Yukihiro Matsumoto <matz@...> 2005/08/30

Hi,

[#154247] Re: Method behaves differently when called using #send — Eric Mahurin <eric_mahurin@...> 2005/08/30

--- Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

[#154151] Re: Method behaves differently when called using #send — Daryl Richter <daryl@...> 2005/08/29

Yukihiro Matsumoto wrote:

[#154161] Re: Method behaves differently when called using #send — "David A. Black" <dblack@...> 2005/08/29

Hi --

[#153695] Word Chains (#44) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

40 messages 2005/08/26

[#153722] vim user switch to emacs? — Joe Van Dyk <joevandyk@...>

Hi,

38 messages 2005/08/26

[#153780] Introducing ruSH — Reyn Vlietstra <reyn.vlietstra@...>

Hi,

15 messages 2005/08/26
[#153788] Re: Introducing ruSH — Sy <sy1234@...> 2005/08/26

I've been waiting for something like this to come along.. but I'm

[#153789] Re: Introducing ruSH — Reyn Vlietstra <reyn.vlietstra@...> 2005/08/26

You have to have

[#153863] how do you describe '#!' in written english? — "SHIGETOMI, Takuhiko" <tshiget1@...>

quick question.

16 messages 2005/08/28

[#153927] Help needed with rexml — Michael <invalid@...>

I've been struggling to properly parse some XML with rexml. I will fully

15 messages 2005/08/28

[#153979] catching segmentation faults from Ruby — Iain Dooley <idoo4002@...>

hello, i've got ruby embedded into an application, and i've built a code

14 messages 2005/08/29
[#154028] Re: catching segmentation faults from Ruby — ts <decoux@...> 2005/08/29

>>>>> "I" == Iain Dooley <idoo4002@mail.usyd.edu.au> writes:

[#153980] how to unflatten a flat-array — "SHIGETOMI, Takuhiko" <tshiget1@...>

dear guys,

38 messages 2005/08/29
[#154014] Re: [Q] how to unflatten a flat-array — Robert Klemme <shortcutter@...> 2005/08/29

2005/8/29, SHIGETOMI, Takuhiko <tshiget1@gw.nsw.co.jp>:

[#154025] Re: [Q] how to unflatten a flat-array — "SHIGETOMI, Takuhiko" <tshiget1@...> 2005/08/29

greetings, Robert. thank you, it does make sense to me.

[#154056] Re: [Q] how to unflatten a flat-array — "Robert Klemme" <bob.news@...> 2005/08/29

SHIGETOMI, Takuhiko wrote:

[#154013] I think that French verb conjugation is as simple as, if not simpler than, that of English (no kidding!) - see www.sixpourcent.com — pan6pourcent@163.com

Dear friends,

11 messages 2005/08/29

[#154108] Thread.list confusion — "Andrew S. Townley" <andrew.townley@...>

12 messages 2005/08/29
[#154132] Re: Thread.list confusion — Eric Hodel <drbrain@...7.net> 2005/08/29

On 29 Aug 2005, at 08:57, Andrew S. Townley wrote:

[#154238] ThreadPool (was: Re: Thread.list confusion) — "Andrew S. Townley" <andrew.townley@...> 2005/08/30

[#154143] New to Ruby — "Steve" <sdouglas949@...>

I'm new to ruby and programming (although I did dabble in BASIC with my

15 messages 2005/08/29

[#154188] Aesthetics of while ... do ... end versus while ...: ... end — Nikolai Weibull <mailing-lists.ruby-talk@...>

OK, this is really quite lame, but what do you people prefer:

10 messages 2005/08/29

[#154344] MInimal Ruby Distribution with app — bww00amdahl@...

I'm looking for a minimal distribution of Ruby to distribute my app

12 messages 2005/08/30

[#154363] Nano Methods & Mega Modules — "Trans" <transfire@...>

19 messages 2005/08/30

[#154380] Ruby on Linux & Windows — Tim Ferrell <Tim.Ferrell@...0nspark.com>

I'm not trying to start anything here but I'd like some feedback from those of

18 messages 2005/08/30

[#154542] nano & mega — Jeff Wood <jeff.darklight@...>

What's up with the funky names ... AND, is there an easy way to just require

30 messages 2005/08/31
[#154592] Re: nano & mega — "Dave Burt" <dave@...> 2005/09/01

Jeff Wood wrote:

[#154624] Re: nano & mega — =?ISO-8859-15?Q?Florian_Gro=DF?= <florgro@...> 2005/09/01

Dave Burt wrote:

[#154626] Re: nano & mega — James Edward Gray II <james@...> 2005/09/01

On Sep 1, 2005, at 8:59 AM, Florian Growrote:

[SUMMARY] Sodoku Solver (#43)

From: Ruby Quiz <james@...>
Date: 2005-08-25 14:49:12 UTC
List: ruby-talk #153561
What's the deal?  Is it Sodoku, Sudoku, Su Doku, or what?

I wasn't aware of all the name variations when I wrote this quiz.  It looks like
the actual number puzzle is usually called Sudoko, now that I've looked into it.
However, some seem to consider Sodoku a slightly different form of the game
which can have multiple solutions, while "true" Sudoku should have exactly one. 
This fact complicated solutions a little, so I thought it was worth bringing up
before we dig into them.

The solutions to this quiz are quite varied and interesting.  We have raw speed,
clever algorithms, java ports, and even not-quite-correct approaches.  I learned
a lot digging trough the code and I encourage others to do the same.

I would say the overriding theme this time though was the sheer amount of code
that came in.  Most of the solutions were over two hundred lines, a few even
over three hundred.  This probably tells us that the problem was tricky, but I
also found some plenty wordy expressions in there.  Let's look at some of those,
since I believe that rethinking code can be very instructive.  Here's a method
from the first submission of David Brady's solution:

	# Loads the @board array from a string matching the example above.
	def load(str)
	  line_num = 0
	  str.each_line do |line|
	    line.gsub! '+', ''
	    line.gsub! '-', ''
	    line.gsub! '|', ''
	    line.gsub! '  ', ' '
	    line.gsub! '_', '0'
	    line.strip!
	    if line.length > 0
	      l = line.split
	      fail "Line length was #{l.length}" unless l.length == 9
	      @board[line_num] = l.collect {|x| x.to_i}
	      line_num += 1
	    end
	  end

	  fail "Board is not valid." unless self.valid?
	end

This code parses the puzzle input format and uses it to load the initial @board,
which is just and Array (rows) of Arrays (columns).  It's currently doing this
by cleaning up the lines and reading each integer.  Can we smooth that out a
little?

Often with Ruby, having to use an index is a sign that you're not attacking the
problem in the easiest way.  Each index is being used to completely replace a
line, so let's see if we can just append them directly:

	# Loads the @board array from a string matching the example above.
	def load(str)
	  @board = Array.new
	
	  str.each_line do |line|
	    line.gsub! '+', ''
	    line.gsub! '-', ''
	    line.gsub! '|', ''
	    line.gsub! '  ', ' '
	    line.gsub! '_', '0'
	    line.strip!
	    if line.length > 0
	      l = line.split
	      fail "Line length was #{l.length}" unless l.length == 9
	      @board << l.collect {|x| x.to_i}
	    end
	  end

	  fail "Board is not valid." unless self.valid?
	end

That only saved one line I guess, but conceptually it's getting easier for me to
follow already.  That's always a win, I think.

Let's tackle the text processing.  My first instinct was:

	# Loads the @board array from a string matching the example above.
	def load(str)
	  @board = Array.new

	  str.each_line do |line|
	    line.delete! '|+-'
	    line.tr! '_', '0'
	    line.squeeze!
	    line.strip!
	    if line.length > 0
	      l = line.split
	      fail "Line length was #{l.length}" unless l.length == 9
	      @board << l.collect {|x| x.to_i}
	    end
	  end

	  fail "Board is not valid." unless self.valid?
	end

Again, only two lines trimmed, but I'm actually helping myself to understand
what exactly this code is doing and that's far more important to me.

I now see that we're stripping non-digit or underscore characters.  We're
leaving the spaces however, so we can later split() on whitespace to get each
cell.  That gets me thinking:  We don't have to split() on whitespace.  If I can
get it down to just what I'm after, we can split() on characters:

	# Loads the @board array from a string matching the example above.
	def load(str)
	  @board = Array.new

	  str.each_line do |line|
	    line.delete! '^0-9_'
	    if line.length > 0
	      l = line.split('')
	      fail "Line length was #{l.length}" unless l.length == 9
	      @board << l.collect {|n| Integet(n) rescue 0 }
	    end
	  end

	  fail "Board is not valid." unless self.valid?
	end

Note that I did change the collect() to be more obvious, since I removed
translation of '_' to '0'.  This isn't strictly needed, as String.to_i() will
return 0 if it can't form a number, but I'm trying not to damage the readability
of this code with my changes.

We're getting close, I can tell, but there's another trick or two left.  We have
to check the line length to see if it's one of the lines that contains cells or
just a border row.  If we skip border rows altogether, we could the switch our
focus from deleting the unwanted data to grabbing wanted data.  (Gavin Kistner
originally pointed this out on Ruby Talk.)  Let's see what that does for us:

	# Loads the @board array from a string matching the example above.
	def load(str)
	  @board = Array.new

	  str.each_line do |line|
	    next unless line =~ /\d|_/
	    @board << line.scan(/[\d_]/).collect {|n| Integet(n) rescue 0 }
	    fail "Length was #{@board.last.length}" unless @board.last.length == 9
	  end

	  fail "Board is not valid." unless self.valid?
	end

Moving the line verification to after I load @board also allowed me to do away
with the extra variable, as you can see.

To me, that removes a lot of the wordiness of the original code, without
sacrificing clarity or functionality.  It's probably a touch more efficient too,
since we trimmed quite a few operations.

I believe Adam Shelly's parse routine could benefit from similar simplifications
if you want to try your own hand at a little refactoring.

Here's another chunk of code (from Horndude77's solution) just crying out for
some help:

	def solve
		#is there a better way to do this? it seems messy
		# and redundant.
		changed = true
		while(changed && @unknown.length>0)
			changed = false
			changed = eliminateall ? true : changed
			changed = checkallrows ? true : changed
			changed = eliminateall ? true : changed
			changed = checkallcols ? true : changed
			changed = eliminateall ? true : changed
			changed = checkallboxes ? true : changed
		end
		puts self
		if(@unknown.length>0)
			puts "I can't solve this one"
		end
	end

I told myself that was too easy and had the following knee-jerk reaction:

	def solve
		changed = true
		while(changed && @unknown.length>0)
			changed = eliminateall || checkallrows || eliminateall ||
			          checkallcols || eliminateall || checkallboxes
		end
		puts self
		if(@unknown.length>0)
			puts "I can't solve this one"
		end
	end

That's cute, and may even work if the underlying algorithms aren't sensitive to
the call order, but it is not identical in function to the original code.  The
original method calls all of those methods and just tracks to see if any one of
them returned true.  The second version will short-circuit the call chain as
soon as a method returns true.  We'll have to be a bit more clever to avoid
that:

	def solve
		changed = true
		while(changed && @unknown.length>0)
			changed = %w{ eliminateall checkallrows eliminateall
			              checkallcols eliminateall checkallboxes }.map do |m|
				send(m)
			end.include?(true)
		end
		puts self
		if(@unknown.length>0)
			puts "I can't solve this one"
		end
	end

That should be equivalent to the original, I believe, minus some repetition.

My point in showing the above examples wasn't to pick on anyone and I apologize
if I gave any offense.  I just wanted to explore a little idiomatic Ruby through
some examples.

Back to Sudoku itself.  Let's look at a solution.  Here's the beginning of
Dominik Bathon's solver class:

	class SudokuSolver

	    # sudoku is an array of arrays, containing the rows, which contain the
	    # cells (all non valid entries are interpreted as open)
	    def initialize(sudoku)
	        # determine @n / @sqrt_n
	        @n = sudoku.size
	        @sqrt_n = Math.sqrt(@n).to_i
	        raise "wrong sudoku size" unless @sqrt_n * @sqrt_n == @n

	        # populate internal representation
	        @arr = sudoku.collect { |row|
	            # ensure correct width for all rows
	            (0...@n).collect { |i|
	                # fixed cell or all values possible for open cell
	                ((1..@n) === row[i]) ? [row[i]] : (1..@n).to_a
	            }
	        }

	        # initialize fix arrays
	        # they will contain all fixed cells for all rows, cols and boxes
	        @rfix=Array.new(@n) { [] }
	        @cfix=Array.new(@n) { [] }
	        @bfix=Array.new(@n) { [] }
	        @n.times { |r| @n.times { |c| update_fix(r, c) } }

	        # check for non-unique numbers
	        [@rfix, @cfix, @bfix].each { |fix| fix.each { |x|
	            unless x.size == x.uniq.size
	                raise "non-unique numbers in row, col or box"
	            end
	        } }
	    end
		
		# ...

This constructor takes an Array of Arrays, which is simply the board setup read
from the input file.  After finding the board size, you can see the method
builds its internal Array (rows) of Arrays (columns) of Arrays (possible numbers
for that cell).  Known cells are set to a one element member with the known
value, while other cells are set to an Array of all the possible numbers.

Next, we see that the code also builds representations for rows, columns, and
boxes and repeatedly calls update_fix(), we assume to populate them.

The method ends with a puzzle validation check, ensuring that there are no
duplicate numbers in rows, columns or boxes.

Jumping a little out of order now, let's examine the private methods used by the
constructor:

		# ...
		
		private

		# returns the box index of row r and col c
		def rc2box(r, c)
		     (r - (r % @sqrt_n)) + (c / @sqrt_n)
		end

		# if row r, col c contains a fixed cell, it is added to the fixed arrays
		def update_fix(r, c)
		    if @arr[r][c].size == 1
		        @rfix[r] << @arr[r][c][0]
		        @cfix[c] << @arr[r][c][0]
		        @bfix[rc2box(r, c)] << @arr[r][c][0]
		    end
		end
		
		# ...

From here we can see that the rows, columns, and boxes tracking variables only
receive a number that has been narrowed down to a single possibility.  Because
of that simplification, these are just two dimensional Arrays.  Note that each
new-found number is just appended to the Array.  These will not be in the same
order as they really appear in the puzzle, but since they're just used to verify
uniqueness it doesn't matter.

The first method, rc2box() just uses math to locate which box we're in, given a
row and column.

Back to the public methods:

		# ...
		
		public

		# returns the internal representation as array of arrays
		def to_a
		    @arr.collect { |row| row.collect { |x|
		        (x.size == 1) ? x[0] : nil
		    } }
		end
		
		# returns a simple string representation
		def to_s
		    fw = @n.to_s.size
		    to_a.collect { |row| row.collect { |x|
		        (x ? x.to_s : "_").rjust(fw)
		    }.join " " }.join "\n"
		end
		
		# returns whether the puzzle is solved
		def finished?
		    @arr.each { |row| row.each { |x| return false if x.size > 1 } }
		    true
		end
		
		# ...

The above methods allow you to query the solver for an Array representation, a
String representation, or just to find out if it is finished being solved yet. 
Starting with to_a(), you can see that it basically just flattens the third
dimension of Arrays either into a known number choice, or nil for unknowns.  The
next method, to_s(), calls to_a(), stringifies, and join()s the results.

On to the actual solving code:

		# ...
		
		# for each cell remove the possibilities, that are already used in the
		# cell's row, col or box
		# return if successful
		def reduce
		    success = false
		    @n.times { |r| @n.times { |c|
		        if (sz = @arr[r][c].size) > 1
		            @arr[r][c] = @arr[r][c] -
		                (@rfix[r] | @cfix[c] | @bfix[rc2box(r, c)])
		            raise "impossible to solve" if @arr[r][c].empty?
		            # have we been successful
		            if @arr[r][c].size < sz
		                success = true
		                update_fix(r, c)
		            end
		        end
		    } }
		    success
		end
		
		# ...

This method is a simple, but important, piece of the solving task.  It simply
walks cell by cell reducing the possibilities by what we already know.  It uses
the Array union operator (|) to combine all known numbers for the row, column
and box of this cell.  All of those numbers are then removed from the
possibilities using the Array difference operator (-).  When any cell shrinks in
choices, update_fix() is called again to notify row, column, and box of the
change.  As long as a single cell lost a single possibility this method returns
true to report progress.

Here's another solving method:

		# ...
		
		# find open cells with unique elements in their row, col or box
		# return if successful
		# reduce must return false when this method is called (if the
		# possibilities aren't reduced, bad things may happen...)
		def deduce
		    success = false
		    [:col_each, :row_each, :box_each].each { |meth|
		        @n.times { |i|
		            u = uniqs_in(meth, i)
		            unless u.empty?
		                send(meth, i) { |x|
		                    if x.size > 1 && ((u2 = u & x).size == 1)
		                        success = true
		                        u2
		                    else
		                        nil
		                    end
		                }
		                # change only one row/col/box at a time
		                return success if success
		            end
		        }
		    }
		    success
		end
		
		# ...

Another way to be sure of a cell is to find a unique possibility in the row,
column, or box.  In other words, if two is a possibility in the fifth cell of a
row, but not a possibility in any other cell of the row, we know it belongs in
the fifth cell and we can place it.

This code hunts for that using iterators to get all the cells in a row, column,
or box and the helper method uniqs_in(), which performs the search I just
explained.  When a unique option is found, the code places it and returns true
to indicate progress.

Here are all four private helper methods:

		# ...
		
	    private

	    # yields each cell of row r and assigns the result of the yield unless
	    # it is nil
	    def row_each(r)
	        @n.times { |c|
	            if (res = yield(@arr[r][c]))
	                @arr[r][c] = res
	                update_fix(r, c)
	            end
	        }
	    end
	    # yields each cell of col c and assigns the result of the yield unless
	    # it is nil
	    def col_each(c)
	        @n.times { |r|
	            if (res = yield(@arr[r][c]))
	                @arr[r][c] = res
	                update_fix(r, c)
	            end
	        }
	    end
	    # yields each cell of box b and assigns the result of the yield unless
	    # it is nil
	    def box_each(b)
	        off_r, off_c = (b - (b % @sqrt_n)), (b % @sqrt_n) * @sqrt_n
	        @n.times { |i|
	            r, c = off_r + (i / @sqrt_n), off_c + (i % @sqrt_n)
	            if (res = yield(@arr[r][c]))
	                @arr[r][c] = res
	                update_fix(r, c)
	            end
	        }
	    end

	    # find unique numbers in possibility lists of a row, col or box
	    # each_meth must be :row_each, :col_each or :box_each
	    def uniqs_in(each_meth, index)
	        h = Hash.new(0)
	        send(each_meth, index) { |x|
	            x.each { |n| h[n] += 1 } if x.size > 1
	            nil # we didn't change anything
	        }
	        h.select { |k, v| v == 1 }.collect { |k, v| k }
	    end
	
		# ...

The iterators are pretty obvious.  The only gotcha to their use is that the
block is expected to return true or false, indicating if the cell was updated. 
This allows the iterator to call update_fix() and keep the internal
representations in sync.

The uniqs_in() method just uses those iterators to fill a Hash with seen counts
and then returns all keys that were only seen once.

Finally, we start to see it all come together with the next method:

		# ...
		
		public
		
		# tries to solve the sudoku with reduce and deduce
		# returns one of :impossible, :solved, :unknown
		def solve
		    begin
		        until finished?
		            progress = false
		            while reduce
		                progress = true
		            end
		            progress = true if deduce
		            return :unknown unless progress
		        end
		        :solved
		    rescue
		        :impossible
		    end
		end
		
		# ...

This method just combines calls to to the previously seen reduce() and deduce()
to see if it can use process of elimination to solve the problem.  It loops as
long as either method reports some progress.  It will eventually return :solved,
if finished?() declares the puzzle done, or :unknown if it runs out of
reductions and deductions.  :impossible is returned in the event of a problem.

The above can solve some puzzles quickly and efficiently, but it's not a
complete solution.  When it won't go any father, it's time for some guess work:

		# ...
		
	    # solves the sudoku using solve and if that fails, it tries to guess
	    # returns one of :impossible, :solved, :multiple_solutions
	    def backtrack_solve
	        if (res = solve) == :unknown
	            # find first open cell
	            r, c = 0, 0
	            @rfix.each_with_index { |rf, r|
	                break if rf.size < @n
	            }
	            @arr[r].each_with_index { |x, c|
	                break if x.size > 1
	            }
	            partial = to_a
	            solutions = []
	            # try all possibilities for the open cell
	            @arr[r][c].each { |guess|
	                partial[r][c] = guess
	                rsolver = SudokuSolver.new(partial)
	                case rsolver.backtrack_solve
	                when :multiple_solutions
	                    initialize(rsolver.to_a)
	                    return :multiple_solutions
	                when :solved
	                    solutions << rsolver
	                end
	            }
	            if solutions.empty?
	                return :impossible
	            else
	                initialize(solutions[0].to_a)
	                return solutions.size > 1 ? :multiple_solutions : :solved
	            end
	        end
	        res
	    end

	end
	
	# ...

Note that this method begins by calling solve().  If it yields a complete
solution, the rest of the work can be skipped.  Even if it doesn't though, it
should have reduced the possibilities, making the coming job easier.

The next bit of code locates a cell to start guessing with.  Rows are scanned to
find one that hasn't been completely filled in, then columns are scanned to find
a cell with more than one possibility.  Note how those two iterations
purposefully clobber the local variables (r and c), so they will hold the final
address of the cell when scanning is done.

Finally, we're to the guess work.  An Array is prepared to hold solutions and
the current known cells are retrieved with a call to to_a().  Then, each
possibility for the selected cell is inserted and a new solver is built and run.
This amounts to recursion of the entire process.  The results of these guesses
are examined by a case statement and added to the solutions Array when found. 
The case statement ignores :impossible returns, since these are just wrong
guesses.

Finally the method checks to see if any solutions were found, and returns the
proper Symbol for the results.

The last little chunk of code handles input and output for the solution:

	# ...

	if $0 == __FILE__
	    # read a sudoku from stdin
	    sudoku = []
	    while sudoku.size < 9
	        row = gets.scan(/\d|_/).map { |s| s.to_i }
	        sudoku << row if row.size == 9
	    end
	    # solve
	    begin
	        solver = SudokuSolver.new(sudoku)
	        puts "Input:", solver
	        case solver.backtrack_solve
	        when :solved
	            puts "Solution:"
	        when :multiple_solutions
	            puts "There are multiple solutions!", "One solution:"
	        else
	            puts "Impossible:"
	        end
	        puts solver
	    rescue => e
	        puts "Error: #{e.message}"
	    end
	end

Look at that four line input read up there.  Its similar to what we reduced the
other code to at the beginning of this summary.  The output is very straight
forward.  It just makes good use of to_s() in the solver object to print the
board before and after.

My thanks to all who sent in their solutions, sometimes many, many times.  ;)

Next week's Ruby Quiz is shamelessly stolen from another source of Ruby
challenges.  Stay tuned to see the kind of problems Dave Thomas cooks up...

In This Thread

Prev Next