[#253828] Getting the last N bytes of a string: — Brian Candler <B.Candler@...>

What's the simplest way to get only the last 10 bytes of a string?

21 messages 2007/06/01

[#253837] FizzBuzz (#126) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

177 messages 2007/06/01
[#253853] Re: [QUIZ] FizzBuzz (#126) — Hans Fugal <fugalh@...> 2007/06/01

Ruby Quiz wrote:

[#253854] Re: FizzBuzz (#126) — Paul Novak <novakps@...> 2007/06/01

On Jun 1, 9:51 am, Hans Fugal <fug...@zianet.com> wrote:

[#253885] Re: [QUIZ] FizzBuzz (#126) — Daniel Martin <martin@...> 2007/06/01

Hans Fugal <fugalh@zianet.com> writes:

[#253945] Re: [QUIZ] FizzBuzz (#126) — Morton Goldberg <m_goldberg@...> 2007/06/02

On Jun 1, 2007, at 8:28 AM, Ruby Quiz wrote:

[#254215] Re: [QUIZ] FizzBuzz (#126) — James Edward Gray II <james@...> 2007/06/04

On Jun 1, 2007, at 10:37 PM, Morton Goldberg wrote:

[#253969] Re: [QUIZ] FizzBuzz (#126) — Daniel Martin <martin@...> 2007/06/02

Ruby Quiz <james@grayproductions.net> writes:

[#254095] Re: [QUIZ] FizzBuzz (#126) — Michael Glaesemann <grzm@...> 2007/06/03

My first Ruby Quiz submission.

[#254096] Re: FizzBuzz (#126) — Joshua Ballanco <jballanc@...> 2007/06/03

So, I've got to lay claim to the 56 byte solution:

[#254097] Re: FizzBuzz (#126) — "Robert Dober" <robert.dober@...> 2007/06/03

On 6/3/07, Joshua Ballanco <jballanc@gmail.com> wrote:

[#254104] Re: FizzBuzz (#126) — Joshua Ballanco <jballanc@...> 2007/06/03

Robert Dober wrote:

[#253838] nested methods don't really exist?! — Artur Merke <am@...>

Hi,

28 messages 2007/06/01
[#253906] Re: nested methods don't really exist?! — Robert Klemme <shortcutter@...> 2007/06/01

On 01.06.2007 14:36, Artur Merke wrote:

[#253919] Re: nested methods don't really exist?! — Trans <transfire@...> 2007/06/01

[#253961] Re: nested methods don't really exist?! — Robert Klemme <shortcutter@...> 2007/06/02

On 01.06.2007 23:14, Trans wrote:

[#253967] Re: nested methods don't really exist?! — "Robert Dober" <robert.dober@...> 2007/06/02

On 6/2/07, Robert Klemme <shortcutter@googlemail.com> wrote:

[#253893] Help with emailing attachments with Ruby... — grooveska <ryangs@...>

I am working on a script that will send an email with a .csv file

11 messages 2007/06/01

[#254054] No way of looking for a regrexp match starting from a particular point in a string? — Kenneth McDonald <kenneth.m.mcdonald@...>

I'm probably just missing something obvious, but I haven't found a way

26 messages 2007/06/03
[#254056] Re: No way of looking for a regrexp match starting from a particular point in a string? — Nobuyoshi Nakada <nobu@...> 2007/06/03

Hi,

[#254059] Re: No way of looking for a regrexp match starting from a particular point in a string? — "Patrick Hurley" <phurley@...> 2007/06/03

On 6/3/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:

[#254063] Re: No way of looking for a regrexp match starting from a particular point in a string? — Nobuyoshi Nakada <nobu@...> 2007/06/03

Hi,

[#254235] Re: No way of looking for a regrexp match starting from a particular point in a string? — "Robert Dober" <robert.dober@...> 2007/06/04

On 6/3/07, Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net> wrote:

[#254132] FizzBuzz (#126) — "Christian Roese" <croese@...>

Great quiz, really got me thinking about other ways to solve this

16 messages 2007/06/03
[#254277] Re: [QUIZ] FizzBuzz (#126) — "Mike Moore" <blowmage@...> 2007/06/04

I didn't spend any time golfing this quiz, so I don't have anything crazy to

[#254217] code problems — "david karapetyan" <dkarapetyan@...>

why is the following code not valid

18 messages 2007/06/04
[#254218] Re: code problems — Nobuyoshi Nakada <nobu@...> 2007/06/04

Hi,

[#254219] Re: code problems — "david karapetyan" <dkarapetyan@...> 2007/06/04

thanks. i didn't realize i had to provide the block as well when i was

[#254223] Re: code problems — Nobuyoshi Nakada <nobu@...> 2007/06/04

Hi,

[#254291] Re: code problems — fREW <frioux@...> 2007/06/04

On 6/3/07, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:

[#254250] Deleting a file - is there a less clumsy way to do this? — "Ronald Fischer" <ronald.fischer@...>

In my application, I often have blocks of code, where during preparation

13 messages 2007/06/04

[#254332] Reverse-range alternatives? — Kenneth McDonald <kenneth.m.mcdonald@...>

Since a reverse range (eg. 4...1) is functionally almost the same as an

11 messages 2007/06/04

[#254452] David Black's book _Ruby for Rails — finetan@...

Hi all

16 messages 2007/06/05

[#254459] [QUIZ] FizzBuzz (#126) [solution #1] — MenTaLguY <mental@...>

I've got two solutions this go-round. First, the solution I would present were I asked to do this in an actual job interview:

13 messages 2007/06/05

[#254467] Gecode/R - Request for syntax feedback — Andreas Launila <ruby-talk@...>

Hello, I'm working on Gecode/R, a Ruby interface to Gecode[0], allowing

24 messages 2007/06/05
[#254477] Re: Gecode/R - Request for syntax feedback — James Edward Gray II <james@...> 2007/06/05

On Jun 5, 2007, at 2:43 PM, Andreas Launila wrote:

[#254526] Re: Gecode/R - Request for syntax feedback — Andreas Launila <ruby-talk@...> 2007/06/06

James Edward Gray II wrote:

[#254544] Re: Gecode/R - Request for syntax feedback — James Edward Gray II <james@...> 2007/06/06

On Jun 6, 2007, at 5:21 AM, Andreas Launila wrote:

[#254561] Re: Gecode/R - Request for syntax feedback — Andreas Launila <ruby-talk@...> 2007/06/06

James Edward Gray II wrote:

[#254583] Re: Gecode/R - Request for syntax feedback — Andreas Launila <ruby-talk@...> 2007/06/06

Andreas Launila wrote:

[#254639] Globals not incrementing inside block — "Todd A. Jacobs" <tjacobs-sndr-019fdb@...>

I have the following snippet:

13 messages 2007/06/07
[#254642] Re: Globals not incrementing inside block — "Harry Kakueki" <list.push@...> 2007/06/07

On 6/7/07, Todd A. Jacobs <tjacobs-sndr-019fdb@codegnome.org> wrote:

[#254661] Mutually-Recursive Functions — Revence Kalibwani <revence27@...>

Ruby doesn't seem to do mutually-recursive functions. Or is it some

15 messages 2007/06/07
[#254664] Re: Mutually-Recursive Functions — Dan Zwell <dzwell@...> 2007/06/07

Revence Kalibwani wrote:

[#254665] Re: Mutually-Recursive Functions — Revence Kalibwani <revence27@...> 2007/06/07

Dan Zwell wrote:

[#254673] What about a 'series' type? — Peter Marsh <evil_grunger@...>

I'm sure everyone is fimilar with ranges:

17 messages 2007/06/07
[#254685] Re: What about a 'series' type? — seebs@... (Peter Seebach) 2007/06/07

In message <cd08f63ca2ad51e567d4288410f593da@ruby-forum.com>, Peter Marsh writes:

[#254686] Re: What about a 'series' type? — SonOfLilit <sonoflilit@...> 2007/06/07

Actually, the syntax:

[#254717] Problem with getting info from several websites — "Tom Bombadil" <bombadil.tom@...>

Hi there,

14 messages 2007/06/07
[#254741] Re: Problem with getting info from several websites — George Malamidis <george@...> 2007/06/07

Hi,

[#254799] Re: Problem with getting info from several websites — "Tom Bombadil" <bombadil.tom@...> 2007/06/08

George,

[#254743] Installing Curb Was: Re: ruby libcurl maintainer? — "Jano Svitok" <jan.svitok@...>

On 6/7/07, Md.elme focruzzaman Shuvo <shuvo.razi@gmail.com> wrote:

11 messages 2007/06/07
[#254816] Installing Curb Was: Re: ruby libcurl maintainer? — "Md.elme focruzzaman Shuvo" <shuvo.razi@...> 2007/06/08

Jano Svitok wrote:

[#254808] newbie question about Ri — Grehom <grehom@...>

I just installed the latest Windows version from Activestate (having

13 messages 2007/06/08

[#254812] practical ruby console on windows? — =?iso-8859-2?q?Kiripolszky_K=E1roly?= <karoly.kiripolszky@...>

Ehlo,

5 messages 2007/06/08

[#254831] Mexican Blanket (#127) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

16 messages 2007/06/08

[#254863] Synchronized attr_accessor — Nasir Khan <rubylearner@...>

I have a fairly repetitive use case of having to define attributes and

23 messages 2007/06/08
[#254865] Re: Synchronized attr_accessor — MenTaLguY <mental@...> 2007/06/08

On Sat, 9 Jun 2007 04:34:42 +0900, Nasir Khan <rubylearner@gmail.com> wrote:

[#254867] Re: Synchronized attr_accessor — Nasir Khan <rubylearner@...> 2007/06/08

This is about having a instance variable always accessed under a lock,

[#254879] Re: Synchronized attr_accessor — MenTaLguY <mental@...> 2007/06/08

On Sat, 9 Jun 2007 04:55:24 +0900, Nasir Khan <rubylearner@gmail.com> wrote:

[#254886] Re: Synchronized attr_accessor — Nasir Khan <rubylearner@...> 2007/06/08

There is no big picture.

[#254890] Re: Synchronized attr_accessor — MenTaLguY <mental@...> 2007/06/08

On Sat, 9 Jun 2007 06:54:04 +0900, Nasir Khan <rubylearner@gmail.com> wrote:

[#254900] Re: Synchronized attr_accessor — "Nasir Khan" <rubylearner@...> 2007/06/09

Yeah I see what you guys mean...I was a little delusional. Now I

[#254915] Re: Synchronized attr_accessor — "Nasir Khan" <rubylearner@...> 2007/06/09

Actually facets/more/synchash.rb does what I was looking for hash.

[#254943] Re: Synchronized attr_accessor — "Nasir Khan" <rubylearner@...> 2007/06/09

Prodding it further I could come up with a method synchronizer.

[#255049] Re: Synchronized attr_accessor — "Caleb Clausen" <vikkous@...> 2007/06/10

Nasir Khan wrote:

[#255073] Re: Synchronized attr_accessor — "Nasir Khan" <rubylearner@...> 2007/06/11

Thanks for the feedback. Here is a refinement -

[#255093] Re: Synchronized attr_accessor — "Caleb Clausen" <vikkous@...> 2007/06/11

On 6/10/07, Nasir Khan <rubylearner@gmail.com> wrote:

[#254864] trouble running ruby programs — Hydro_Flame XZ18 <hydroflame@...>

I'm a newbie programmer and I just downloaded ruby today. I must say I'm

14 messages 2007/06/08
[#254866] Re: trouble running ruby programs — Peter Szinek <peter@...> 2007/06/08

> Can anyone help? I'm running Windows XP if that helps at all.

[#254870] Re: trouble running ruby programs — Jacob Gillie <hydroflame@...> 2007/06/08

I tried going to the command prompt, making sure the file was in the

[#254871] Re: trouble running ruby programs — "Michael W. Ryder" <_mwryder@...> 2007/06/08

Jacob Gillie wrote:

[#254917] Ruby wildcard command line argument auto expansion — Michael Jia <z_jia@...>

I want to pass in wildcard file names, and use it to match file names

14 messages 2007/06/09

[#254974] Passing block to Proc#call — "Erwin Abbott" <erwin.abbott@...>

I'd like to do something like:

13 messages 2007/06/10

[#254975] Overloading Array Subtraction operator — Nicko <anko.com@...>

Hi,

15 messages 2007/06/10
[#254978] Re: Overloading Array Subtraction operator — "Erwin Abbott" <erwin.abbott@...> 2007/06/10

The - operator compares objects by their ID, so they aren't removed

[#254986] JRuby 1.0 Released — Thomas Enebo <Thomas.Enebo@...>

The JRuby community is pleased to announce the release of JRuby 1.0!

14 messages 2007/06/10

[#254989] fun with "case" — Robert Klemme <shortcutter@...>

16 messages 2007/06/10

[#255013] Serious danger of being impressed — Mark Carter <me@...>

I'm mostly into Python, and decided to have a go at writing a little

34 messages 2007/06/10
[#255038] Re: Serious danger of being impressed — Chad Perrin <perrin@...> 2007/06/10

On Mon, Jun 11, 2007 at 12:20:12AM +0900, Mark Carter wrote:

[#255096] Re: Serious danger of being impressed — John Joyce <dangerwillrobinsondanger@...> 2007/06/11

[#255103] Re: Serious danger of being impressed — Chad Perrin <perrin@...> 2007/06/11

On Mon, Jun 11, 2007 at 03:42:03PM +0900, John Joyce wrote:

[#255044] Requiring more than one file? — Marc Heiler <shevegen@...>

require does accept ony word, which should be the name that has

13 messages 2007/06/10

[#255142] Custom Mutex methods undefined by fastthread — Alex Young <alex@...>

At the risk of asking an FAQ, I've run into the following problem:

12 messages 2007/06/11

[#255181] a matter of style — Bas van Gils <bas@...>

22 messages 2007/06/11
[#255188] Re: a matter of style — Anthony Martinez <pi@...> 2007/06/11

On Tue, Jun 12, 2007 at 03:10:49AM +0900, Bas van Gils wrote:

[#255299] Re: a matter of style — dblack@... 2007/06/12

Hi --

[#255202] Ruby way to update a file in place — Li Chen <chen_li3@...>

Hi all,

12 messages 2007/06/11

[#255258] how to make a[2][2][3]=4 work? — gz zz <gpygood@126.com>

a=Hash.new{|h,k|

16 messages 2007/06/12

[#255289] Generate a grid of cells, and give characteristics — Joop Van den tillaart <tillaart36@...>

Hi you all I am new to this forum and also quite new to ruby...I have

12 messages 2007/06/12
[#255303] Re: Generate a grid of cells, and give characteristics — "Harry Kakueki" <list.push@...> 2007/06/12

On 6/12/07, Joop Van den tillaart <tillaart36@hotmail.com> wrote:

[#255306] Re: Generate a grid of cells, and give characteristics — Joop Van den tillaart <tillaart36@...> 2007/06/12

Harry Kakueki wrote:

[#255315] Re: Generate a grid of cells, and give characteristics — "Harry Kakueki" <list.push@...> 2007/06/12

On 6/12/07, Joop Van den tillaart <tillaart36@hotmail.com> wrote:

[#255373] Quick sed replacemnt — yitzhakbg <yitzhakbg@...>

I need a quicky which I can't do in sed and I did it very clumsily.

14 messages 2007/06/12

[#255651] Changing registry values with Win32::Registry — Collin Miller <collintmiller@...>

I'm trying to change a registry value for an IPTV SDK

12 messages 2007/06/14
[#255699] Re: Changing registry values with Win32::Registry — "Jano Svitok" <jan.svitok@...> 2007/06/15

On 6/14/07, Collin Miller <collintmiller@gmail.com> wrote:> I'm trying to change a registry value for an IPTV SDK>> This code:>> Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\PATH_TO_KEY\> \").write("IgnoreTinyIFrames",Win32::Registry::REG_DWORD,0)>> Returns this error:>> Win32::Registry::Error: Access is denied.> from c:/ruby/lib/ruby/1.8/win32/registry.rb:743:in `write'> from (irb):150> from ⊂:0>> Anybody know how I can ensure access to this key?

[#255664] Reasonable practice? — Trans <transfire@...>

It the following reasonable? How thread safe is it?

14 messages 2007/06/14

[#255672] Re: class destruction (evil genius metaprogramming) — "Rick DeNatale" <rick.denatale@...>

On 6/14/07, Giles Bowkett <gilesb@gmail.com> wrote:

12 messages 2007/06/15

[#255737] Verbal Arithmetic (#128) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

29 messages 2007/06/15

[#255760] Using extend for initialization settings? — Trans <transfire@...>

It's not uncommon to see initialize method take a hash or a setting

16 messages 2007/06/15
[#255784] Re: Using extend for initialization settings? — Robert Klemme <shortcutter@...> 2007/06/15

On 15.06.2007 16:44, Trans wrote:

[#255797] Re: Using extend for initialization settings? — Trans <transfire@...> 2007/06/15

[#255864] Adding new value (in array) to existing key in a hash — Gilbert Lau <gilbertlsk@...>

Hi all,

12 messages 2007/06/16
[#255866] Re: Adding new value (in array) to existing key in a hash — "Harry Kakueki" <list.push@...> 2007/06/16

On 6/16/07, Gilbert Lau <gilbertlsk@gmail.com> wrote:

[#255873] Re: Adding new value (in array) to existing key in a hash — Gilbert Lau <gilbertlsk@...> 2007/06/16

Harry Kakueki wrote:

[#255871] Error in ancestor? — "Robert Dober" <robert.dober@...>

Hi list

39 messages 2007/06/16
[#256036] Re: Error in ancestor? — Sylvain Joyeux <sylvain.joyeux@...> 2007/06/18

I launched a discussion about this on Ruby-core. I think there were no

[#256193] Re: Error in ancestor? — "Robert Dober" <robert.dober@...> 2007/06/19

On 6/18/07, Sylvain Joyeux <sylvain.joyeux@polytechnique.org> wrote:

[#256204] Re: Error in ancestor? — "Rick DeNatale" <rick.denatale@...> 2007/06/19

On 6/19/07, Robert Dober <robert.dober@gmail.com> wrote:

[#256236] Re: Error in ancestor? — dblack@... 2007/06/19

Hi --

[#256486] Re: Error in ancestor? — "Rick DeNatale" <rick.denatale@...> 2007/06/21

On 6/19/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

[#256492] Re: Error in ancestor? — dblack@... 2007/06/21

Hi --

[#256594] Re: Error in ancestor? — "Rick DeNatale" <rick.denatale@...> 2007/06/22

On 6/21/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

[#256595] Re: Error in ancestor? — dblack@... 2007/06/22

Hi --

[#256598] Re: Error in ancestor? — "Gregory Brown" <gregory.t.brown@...> 2007/06/22

On 6/22/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

[#256700] Re: Error in ancestor? — "Rick DeNatale" <rick.denatale@...> 2007/06/23

On 6/22/07, Gregory Brown <gregory.t.brown@gmail.com> wrote:

[#255911] Chris Pine Program Challenges — danielj@...

puts 'Type in as many words as you want'

13 messages 2007/06/16

[#255980] Parsing strings — NB88 <germans88@...>

Quick question, is there a method for deleting substrings from within a

15 messages 2007/06/18

[#256062] Another Easy Beginner Question — danielj <danielj@...>

17 messages 2007/06/18

[#256131] local vars clobbered by un-run code — Trans <transfire@...>

Err...

13 messages 2007/06/19

[#256243] Ruby MVC — poopdeville@...

Hi Everybody,

14 messages 2007/06/20

[#256299] Behaviour of Enumerables reject vs. select mixed into Hash — Alexander Presber <aljoscha@...>

Hello everybody,

55 messages 2007/06/20
[#256311] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Trans <transfire@...> 2007/06/20

[#256357] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Alexander Presber <aljoscha@...> 2007/06/21

>> Hello everybody,

[#256361] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Robert Klemme <shortcutter@...> 2007/06/21

On 21.06.2007 11:06, Alexander Presber wrote:

[#256364] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Alexander Presber <aljoscha@...> 2007/06/21

Am 21.06.2007 um 11:20 schrieb Robert Klemme:

[#256365] Re: Behaviour of Enumerables reject vs. select mixed into Hash — dblack@... 2007/06/21

Hi --

[#256367] Re: Behaviour of Enumerables reject vs. select mixed into Hash — "Robert Dober" <robert.dober@...> 2007/06/21

On 6/21/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

[#256370] Re: Behaviour of Enumerables reject vs. select mixed into Hash — dblack@... 2007/06/21

Hi --

[#256498] Re: Behaviour of Enumerables reject vs. select mixed into Hash — "Rick DeNatale" <rick.denatale@...> 2007/06/21

On 6/21/07, dblack@wobblini.net <dblack@wobblini.net> wrote:

[#256369] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Alexander Presber <aljoscha@...> 2007/06/21

[#256374] Re: Behaviour of Enumerables reject vs. select mixed into Hash — dblack@... 2007/06/21

Hi --

[#256377] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Alexander Presber <aljoscha@...> 2007/06/21

[#256385] Re: Behaviour of Enumerables reject vs. select mixed into Hash — "Robert Dober" <robert.dober@...> 2007/06/21

On 6/21/07, Alexander Presber <aljoscha@weisshuhn.de> wrote:

[#256401] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Trans <transfire@...> 2007/06/21

[#256414] Re: Behaviour of Enumerables reject vs. select mixed into Hash — "Robert Dober" <robert.dober@...> 2007/06/21

On 6/21/07, Trans <transfire@gmail.com> wrote:

[#256423] Re: Behaviour of Enumerables reject vs. select mixed into Hash — Alexander Presber <aljoscha@...> 2007/06/21

>> module Enumerable

[#256310] Do You Understand Regular Expressions? — growlatoe@...

Hi all.

20 messages 2007/06/20
[#256317] Re: Do You Understand Regular Expressions? — "Axel Etzold" <AEtzold@...> 2007/06/20

> irb(main):001:0> "hello".scan(/.*/)

[#256324] Re: Do You Understand Regular Expressions? — Daniel DeLorme <dan-ml@...42.com> 2007/06/20

Axel Etzold wrote:

[#256386] Re: Do You Understand Regular Expressions? — "Stephen Ball" <sdball@...> 2007/06/21

On 6/20/07, Daniel DeLorme <dan-ml@dan42.com> wrote:

[#256426] Ruby extensions question.. — Aaron Smith <beingthexemplary@...>

So I'm getting slightly confused with writing ruby extensions and what

17 messages 2007/06/21
[#256430] Re: Ruby extensions question.. — james.d.masters@... 2007/06/21

On Jun 21, 10:22 am, Aaron Smith <beingthexempl...@gmail.com> wrote:

[#256442] Re: Ruby extensions question.. — Aaron Smith <beingthexemplary@...> 2007/06/21

unknown wrote:

[#256450] Re: Ruby extensions question.. — MenTaLguY <mental@...> 2007/06/21

On Fri, 22 Jun 2007 03:55:11 +0900, Aaron Smith <beingthexemplary@gmail.com> wrote:

[#256469] Re: Ruby extensions question.. — Aaron Smith <beingthexemplary@...> 2007/06/21

MenTaLguY wrote:

[#256473] Re: Ruby extensions question.. — MenTaLguY <mental@...> 2007/06/21

On Fri, 22 Jun 2007 05:28:17 +0900, Aaron Smith <beingthexemplary@gmail.com> wrote:

[#256447] Ruby doesn't know how to multiply — "rjprado@..." <rjprado@...>

Hello,

45 messages 2007/06/21
[#256462] Re: Ruby doesn't know how to multiply — "rjprado@..." <rjprado@...> 2007/06/21

On Jun 21, 3:21 pm, "rjpr...@gmail.com" <rjpr...@gmail.com> wrote:

[#256484] Re: Ruby doesn't know how to multiply — Lloyd Linklater <lloyd@2live4.com> 2007/06/21

> Yes, you are all right. It's a common problem. I have confirmed this

[#256509] Re: Ruby doesn't know how to multiply — Yukihiro Matsumoto <matz@...> 2007/06/22

Hi,

[#256512] Re: Ruby doesn't know how to multiply — "Michael W. Ryder" <_mwryder@...> 2007/06/22

Yukihiro Matsumoto wrote:

[#256514] Re: Ruby doesn't know how to multiply — "Gregory Brown" <gregory.t.brown@...> 2007/06/22

On 6/21/07, Michael W. Ryder <_mwryder@worldnet.att.net> wrote:

[#256517] Re: Ruby doesn't know how to multiply — Rob Biedenharn <Rob@...> 2007/06/22

On Jun 21, 2007, at 8:48 PM, Gregory Brown wrote:

[#256519] Re: Ruby doesn't know how to multiply — "Michael W. Ryder" <_mwryder@...> 2007/06/22

Rob Biedenharn wrote:

[#256556] avoiding nil.methodcalls short and cheap — Thorsten Rossner <rossnet@...>

Hi,

17 messages 2007/06/22

[#256675] Regexp to split name? — Alex MacCaw <maccman@...>

Does anyone have an example of splitting a name into first and last

15 messages 2007/06/23
[#256676] Re: Regexp to split name? — darren kirby <bulliver@...> 2007/06/23

quoth the Alex MacCaw:

[#256713] Named/positional method args — darren kirby <bulliver@...>

I have a method here that takes two arguments. Both are optional, with

19 messages 2007/06/23

[#256748] LSRC Name Picker (#129) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

44 messages 2007/06/24
[#256749] Re: [QUIZ] LSRC Name Picker (#129) — James Edward Gray II <james@...> 2007/06/24

Sorry the quiz was late this week.

[#256811] Helper to create multi-dimensional arrays — Anthony Martinez <pi@...>

I came up with this method really quick to create x*y arrays in Ruby. It

21 messages 2007/06/24
[#256816] Ruby Debugger — Dick Summerfield <ds@...> 2007/06/24

Hello everybody,

[#257017] Probably an FAQ, but... — David Rush <kumoyuki@...>

Hi all,

13 messages 2007/06/26
[#257023] Re: Probably an FAQ, but... — Morton Goldberg <m_goldberg@...> 2007/06/26

On Jun 26, 2007, at 5:00 AM, David Rush wrote:

[#257033] how much to charge for a freelance project in ruby in the states — urielka <uriel.katz@...>

i work in Israel and i wanted to know how much should i charge per

9 messages 2007/06/26

[#257207] ActiveRecord (not necessarily rails) — "shawn bright" <nephish@...>

Hello all,

11 messages 2007/06/27

[#257228] Ajax with Ruby problem — Gale CC <galecho@...>

I'm a newbie to both Ruby and Ajax. I'm trying to use Ruby to handle the

13 messages 2007/06/27

[#257246] Array Problem, sort Array — Cool Wong <coolwong85@...>

[code]

23 messages 2007/06/28
[#257248] Re: Array Problem, sort Array — "list. rb" <list.rb@...> 2007/06/28

["a", "a", "a", "b", "b", "c", "c", "c","d", "d", "e"].uniq.sort

[#257342] Help with regular expression — "toulax@..." <toulax@...>

How can I make a regular expression that will match everything, unless

17 messages 2007/06/28
[#257343] Re: Help with regular expression — Philip Hallstrom <ruby@...> 2007/06/28

> How can I make a regular expression that will match everything, unless

[#257346] Re: Help with regular expression — "toulax@..." <toulax@...> 2007/06/28

On Jun 28, 4:00 pm, Philip Hallstrom <r...@philip.pjkh.com> wrote:

[#257353] Re: Help with regular expression — "Axel Etzold" <AEtzold@...> 2007/06/28

I think what you want is what's called negative lookahead.

[#257383] newby non/programmer trying to understand classes — "weathercoach@..." <weathercoach@...>

Hello.

15 messages 2007/06/28

[#257428] Where to start in parsing? — "Hakusa@..." <Hakusa@...>

I haven't programmed in a while, but I want to get back with doing

10 messages 2007/06/29

[#257454] Feature Request: Special file '-' denoting stdin/stdout — "Ronald Fischer" <ronald.fischer@...>

I would like to propose a feature for Ruby which can be

12 messages 2007/06/29
[#257471] Re: Feature Request: Special file '-' denoting stdin/stdout — Erik Veenstra <erikveen@...> 2007/06/29

It should be mentioned that both File.new and File.open are

[#257746] Re: Feature Request: Special file '-' denoting stdin/stdout — "Ronald Fischer" <ronald.fischer@...> 2007/07/02

[#257573] is it bug? for — Chung Chung <bkeh12@...>

[root@home1 ~]# ruby -v

16 messages 2007/06/30

[#257601] de-camelcase a filename — Aaron Smith <beingthexemplary@...>

how can a take a string file name like MyTestCase.rb and change it to

15 messages 2007/06/30

[#257609] apt-get installs 1.8.5 on ubuntu 7.0.4 — "D. Krmpotic" <david.krmpotic@...>

hi!

11 messages 2007/06/30

Re: [SOLUTION] Verbal Arithmetic (#128)

From: "Eric I." <rubytraining@...>
Date: 2007-06-17 19:30:24 UTC
List: ruby-talk #255970
This program solves addition problems with any number of terms.  It
finds and displays all solutions to the problem.

The solving process is broken up into a sequence of simple steps all
derived from class Step.  A Step can be something such as 1) choosing
an available digit for a given letter or 2) summing up a column and
seeing if the result matches an already-assigned letter.  As steps
succeed the process continues with the following steps.  But if a step
fails (i.e., there's a contradiction) then the system backs up to a
point where another choice can be made.  This is handled by recursing
through the sequence of steps.  In fact, even when a solution is
found, the program still backtracks to find other solutions.

The expectation is that by testing for contradictions as early as
possible in the process we'll tend to avoid dead ends and the result
will be much better than an exhaustive search.

For example, here are the steps for a sample equation:

   send
  +more
  -----
  money

1. Choose a digit for "d".
2. Choose a digit for "e".
3. Sum the column using letters "d", "e" (and include carry).
4. Set the digit for "y" based on last column summed.
5. Choose a digit for "n".
6. Choose a digit for "r".
7. Sum the column using letters "n", "r" (and include carry).
8. Verify that last column summed matches current digit for "e".
9. Choose a digit for "o".
10. Sum the column using letters "e", "o" (and include carry).
11. Verify that last column summed matches current digit for "n".
12. Choose a digit for "s".
13. Verify that "s" has not been assigned to zero.
14. Choose a digit for "m".
15. Verify that "m" has not been assigned to zero.
16. Sum the column using letters "s", "m" (and include carry).
17. Verify that last column summed matches current digit for "o".
18. Sum the column using letters  (and include carry).
19. Verify that last column summed matches current digit for "m".
20. Display a solution (provided carry is zero)!

Eric
----
Are you interested in on-site Ruby training that's been highly
reviewed by former students?  http://LearnRuby.com

====

# This is a solution to Ruby Quiz #128.  As input it takes a "word
# equation" such as "send+more=money" and determines all possible
# mappings of letters to digits that yield a correct result.
#
# The constraints are: 1) a given digit can only be mapped to a single
# letter, 2) the first digit in any term cannot be zero.
#
# The solving process is broken up into a sequence of simple steps all
# derived from class Step.  A Step can be something such as 1)
# choosing an available digit for a given letter or 2) summing up a
# column and seeing if the result matches an already-assigned letter.
# As steps succeed the process continues with the following steps.
# But if a step fails (i.e., there's a contradiction) then the system
# backs up to a point where another choice can be made.  This is
# handled by recursing through the sequence of steps.  In fact, even
# when a solution is found, the program still backtracks to find other
# solutions.


require 'set'


# State represents the stage of a partially solved word equation.  It
# keeps track of what digits letters map to, which digits have not yet
# been assigned to letters, and the results of the last summed column,
# including the resulting digit and any carry if there is one.
class State
  attr_accessor :sum, :carry
  attr_reader :letters

  def initialize()
    @available_digits = Set.new(0..9)
    @letters = Hash.new
    @sum, @carry = 0, 0
  end

  # Return digit for letter.
  def [](letter)
    @letters[letter]
  end

  # The the digit for a letter.
  def []=(letter, digit)
    # if the letter is currently assigned, return its digit to the
    # available set
    @available_digits.add @letters[letter] if @letters[letter]

    @letters[letter] = digit
    @available_digits.delete digit
  end

  # Clear the digit for a letter.
  def clear(letter)
    @available_digits.add @letters[letter]
    @letters[letter] = nil
  end

  # Return the available digits as an array copied from the set.
  def available_digits
    @available_digits.to_a
  end

  # Tests whether a given digit is still available.
  def available?(digit)
    @available_digits.member? digit
  end

  # Receives the total for a column and keeps track of it as the
  # summed-to digit and any carry.
  def column_total=(total)
    @sum = total % 10
    @carry = total / 10
  end
end


# Step is an "abstract" base level class from which all the "concrete"
# steps can be deriveds.  It simply handles the storage of the next
# step in the sequence.  Subclasses should provide 1) a to_s method to
# describe the step being performed and 2) a perform method to
# actually perform the step.
class Step
  attr_writer :next_step
end


# This step tries assigning each available digit to a given letter and
# continuing from there.
class ChooseStep < Step
  def initialize(letter)
    @letter = letter
  end

  def to_s
    "Choose a digit for \"#{@letter}\"."
  end

  def perform(state)
    state.available_digits.each do |v|
      state[@letter] = v
      @next_step.perform(state)
    end
    state.clear(@letter)
  end
end


# This step sums up the given letters and changes to state to reflect
# the sum.  Because we may have to backtrack, it stores the previous
# saved sum and carry for later restoration.
class SumColumnStep < Step
  def initialize(letters)
    @letters = letters
  end

  def to_s
    list = @letters.map { |l| "\"#{l}\"" }.join(', ')
    "Sum the column using letters #{list} (and include carry)."
  end

  def perform(state)
    # save sum and carry
    saved_sum, saved_carry = state.sum, state.carry

    state.column_total =
      state.carry +
      @letters.inject(0) { |sum, letter| sum + state[letter] }
    @next_step.perform(state)

    # restore sum and carry
    state.sum, state.carry = saved_sum, saved_carry
  end
end


# This step determines the digit for a letter given the last column
# summed.  If the digit is not available, then we cannot continue.
class AssignOnSumStep < Step
  def initialize(letter)
    @letter = letter
  end

  def to_s
    "Set the digit for \"#{@letter}\" based on last column summed."
  end

  def perform(state)
    if state.available? state.sum
      state[@letter] = state.sum
      @next_step.perform(state)
      state.clear(@letter)
    end
  end
end


# This step will occur after a column is summed, and the result must
# match a letter that's already been assigned.
class CheckOnSumStep < Step
  def initialize(letter)
    @letter = letter
  end

  def to_s
    "Verify that last column summed matches current " +
      "digit for \"#{@letter}\"."
  end

  def perform(state)
    @next_step.perform(state) if state[@letter] == state.sum
  end
end


# This step will occur after a letter is assigned to a digit if the
# letter is not allowed to be a zero, because one or more terms begins
# with that letter.
class CheckNotZeroStep < Step
  def initialize(letter)
    @letter = letter
  end

  def to_s
    "Verify that \"#{@letter}\" has not been assigned to zero."
  end

  def perform(state)
    @next_step.perform(state) unless state[@letter] == 0
  end
end


# This step represents finishing the equation.  The carry must be zero
# for the perform to have found an actual result, so check that and
# display a digit -> letter conversion table and dispaly the equation
# with the digits substituted in for the letters.
class FinishStep < Step
  def initialize(equation)
    @equation = equation
  end

  def to_s
    "Display a solution (provided carry is zero)!"
  end

  def perform(state)
    # we're supposedly done, so there can't be anything left in carry
    return unless state.carry == 0

    # display a letter to digit table on a single line
    table = state.letters.invert
    puts
    puts table.keys.sort.map { |k| "#{table[k]}=#{k}" }.join('    ')

    # display the equation with digits substituted for the letters
    equation = @equation.dup
    state.letters.each { |k, v| equation.gsub!(k, v.to_s) }
    puts
    puts equation
  end
end


# Do a basic test for the command-line arguments validity.
unless ARGV[0] =~ Regexp.new('^[a-z]+(\+[a-z]+)*=[a-z]+$')
  STDERR.puts "invalid argument"
  exit 1
end


# Split the command-line argument into terms and figure out how many
# columns we're dealing with.
terms = ARGV[0].split(/\+|=/)
column_count = terms.map { |e| e.size }.max


# Build the display of the equation a line at a time.  The line
# containing the final term of the sum has to have room for the plus
# sign.
display_columns = [column_count, terms[-2].size + 1].max
display  = []
terms[0..-3].each do |term|
  display << term.rjust(display_columns)
end
display << "+" + terms[-2].rjust(display_columns - 1)
display << "-" * display_columns
display << terms[-1].rjust(display_columns)
display = display.join("\n")
puts display


# AssignOnSumStep which letters cannot be zero since they're the first
# letter of a term.
nonzero_letters = Set.new
terms.each { |e| nonzero_letters.add(e[0, 1]) }


# A place to keep track of which letters have so-far been assigned.
chosen_letters = Set.new


# Build up the steps needed to solve the equation.
steps = []
column_count.times do |column|
  index = -column - 1
  letters = []                 # letters for this column to be added

  terms[0..-2].each do |term|  # for each term that's being added...
    letter = term[index, 1]
    next if letter.nil?        # skip term if no letter in column
    letters << letter          # note that this letter is part of sum

    # if the letter does not have a digit, create a ChooseStep
    unless chosen_letters.member? letter
      steps << ChooseStep.new(letter)
      chosen_letters.add(letter)
      steps << CheckNotZeroStep.new(letter) if
        nonzero_letters.member? letter
    end
  end

  # create a SumColumnStep for the column
  steps << SumColumnStep.new(letters)

  summed_letter = terms[-1][index, 1]  # the letter being summed to

  # check whether the summed to letter should already have a digit
  if chosen_letters.member? summed_letter
    # should already have a digit, check that summed digit matches it
    steps << CheckOnSumStep.new(summed_letter)
  else
    # doesn't already have digit, so create a AssignOnSumStep for
    # letter
    steps << AssignOnSumStep.new(summed_letter)
    chosen_letters.add(summed_letter)

    # check whether this letter cannot be zero and if so add a
    # CheckNotZeroStep
    steps << CheckNotZeroStep.new(summed_letter) if
      nonzero_letters.member? summed_letter
  end
end

# should be done, so add a FinishStep
steps << FinishStep.new(display)

# print out all the steps
# steps.each_with_index { |step, i| puts "#{i + 1}. #{step}" }

# let each step know about the one that follows it.
steps.each_with_index { |step, i| step.next_step = steps[i + 1] }

# start performing with the first step.
steps.first.perform(State.new)


In This Thread