[#313454] Request for Block local methods, and Proc syntax — Patrick Li <patrickli_2001@...>

So after using Ruby for a little over two months, I've made the complete

20 messages 2008/09/01

[#313477] Looking for a regular pattern — Zhao Yi <youhaodeyi@...>

Which pattern represents any characters including space, \t \n?

23 messages 2008/09/01
[#313486] Re: Looking for a regular pattern — "Thomas Wieczorek" <wieczo.yo@...> 2008/09/01

On Mon, Sep 1, 2008 at 10:20 AM, Zhao Yi <youhaodeyi@gmail.com> wrote:

[#313489] Re: Looking for a regular pattern — Sebastian Hungerecker <sepp2k@...> 2008/09/01

Thomas Wieczorek wrote:

[#313490] Re: Looking for a regular pattern — Zhao Yi <youhaodeyi@...> 2008/09/01

Sebastian Hungerecker wrote:

[#313493] Re: Looking for a regular pattern — Sebastian Hungerecker <sepp2k@...> 2008/09/01

Zhao Yi wrote:

[#313496] Re: Looking for a regular pattern — Zhao Yi <youhaodeyi@...> 2008/09/01

Sebastian Hungerecker wrote:

[#313516] Parsing a CSV file column-wise — Chris Lowis <chris.lowis@...>

Is there a short-cut to parsing a CSV file column-wise using any of

14 messages 2008/09/01

[#313724] Hash optimization question — Roger Pack <rogerpack2005@...>

Are there any libraries that overcome this problem:

11 messages 2008/09/03

[#313890] How do I quickly search the end of a huge text file? — Brian Green <gallagherjb@...>

I am trying to create a ruby script that will search a maya ascii file

11 messages 2008/09/05

[#313897] Need a 40 LOC (ignoring comments) to be shorter -- suggestions wanted — RichardOnRails <RichardDummyMailbox58407@...>

Hi All,

12 messages 2008/09/05

[#313946] Who's Charles angry at? — Joshua Ballanco <jballanc@...>

Well, I just came across this in my feed reader:

17 messages 2008/09/05

[#314002] Is Ruby good at GUI develop? — Zhao Yi <youhaodeyi@...>

I want to choose a script to develop a GUI program. I want to know more

18 messages 2008/09/06
[#314011] Re: Is Ruby good at GUI develop? — James Britt <james.britt@...> 2008/09/06

Zhao Yi wrote:

[#314395] Re: Is Ruby good at GUI develop? — Jason Cameron <cameronjc2000@...> 2008/09/10

James Britt wrote:

[#314061] any way to write it in one line ? — Erwin <yves_dufour@...>

works = Array.new

17 messages 2008/09/06

[#314083] json for extjs (without rails) — Gurpal 2000 <gurpal@...>

Hi

14 messages 2008/09/07

[#314090] find a button using mechanize — Li Chen <chen_li3@...>

Hi all,

21 messages 2008/09/07
[#314116] Re: find a button using mechanize — Lex Williams <etaern@...> 2008/09/07

Li Chen wrote:

[#314117] Re: find a button using mechanize — Lex Williams <etaern@...> 2008/09/07

Lex Williams wrote:

[#314126] Re: find a button using mechanize — Li Chen <chen_li3@...> 2008/09/07

Lex Williams wrote:

[#314164] Re: find a button using mechanize — Lex Williams <etaern@...> 2008/09/07

Li Chen wrote:

[#314167] Re: find a button using mechanize — Li Chen <chen_li3@...> 2008/09/07

Lex Williams wrote:

[#314185] Re: find a button using mechanize — Lex Williams <etaern@...> 2008/09/08

Li , I wouldn't try to find a form by searching after it's button .

[#314233] Re: find a button using mechanize — Li Chen <chen_li3@...> 2008/09/08

Hi Lex,

[#314253] Re: find a button using mechanize — Lex Williams <etaern@...> 2008/09/08

Li , please post examples . What is it you want to extract ? From what

[#314133] regular expression match and exclude — Azalar --- <pteale@...>

I am parsing a web page full of image links that also contain links to

13 messages 2008/09/07

[#314199] FileUtils.chdir thread safety — Mr_Tibs <tiberiu.motoc@...>

Hi,

20 messages 2008/09/08
[#314285] Re: FileUtils.chdir thread safety — Mr_Tibs <tiberiu.motoc@...> 2008/09/08

Darn it! It would seem like a good idea.

[#314328] Re: FileUtils.chdir thread safety — "Robert Klemme" <shortcutter@...> 2008/09/09

2008/9/9 Mr_Tibs <tiberiu.motoc@gmail.com>:

[#314360] Re: FileUtils.chdir thread safety — Charles Oliver Nutter <charles.nutter@...> 2008/09/09

Robert Klemme wrote:

[#314299] Drake: Distributed Rake — quixoticsycophant@...

= DRAKE -- Distributed Rake

43 messages 2008/09/09

[#314470] How to operate on 2 arrays simultaneously? — "Patrick Doyle" <wpdster@...>

There has got to be a more elegant solution than this. Suppose I have

19 messages 2008/09/10

[#314529] How to check if a webpage exists — Davide Benini <nutsmuggler@...>

This probably is trivial, but I have been googling for almost 2hs

22 messages 2008/09/10
[#314533] Re: How to check if a webpage exists — "Todd Benson" <caduceass@...> 2008/09/10

On Wed, Sep 10, 2008 at 4:38 PM, Davide Benini <nutsmuggler@hotmail.com> wrote:

[#314534] Re: How to check if a webpage exists — "Axel Etzold" <AEtzold@...> 2008/09/10

[#314572] Re: How to check if a webpage exists — Davide Benini <nutsmuggler@...> 2008/09/11

[#314575] Re: How to check if a webpage exists — Peña, Botp <botp@...> 2008/09/11

RnJvbTogRGF2aWRlIEJlbmluaSBbbWFpbHRvOm51dHNtdWdnbGVyQGhvdG1haWwuY29tXSANCiMg

[#314577] Re: How to check if a webpage exists — Davide Benini <nutsmuggler@...> 2008/09/11

Thanks for your super-fast answer :)

[#314584] Re: How to check if a webpage exists — "Axel Etzold" <AEtzold@...> 2008/09/11

-------- Original-Nachricht --------

[#314585] Re: How to check if a webpage exists — Davide Benini <nutsmuggler@...> 2008/09/11

Hi Axel,

[#314586] Re: How to check if a webpage exists — Peña, Botp <botp@...> 2008/09/11

RnJvbTogRGF2aWRlIEJlbmluaSBbbWFpbHRvOm51dHNtdWdnbGVyQGhvdG1haWwuY29tXSANCiMg

[#314538] pass by reference in each loop — Xiong Chiamiov <xiong.chiamiov+ruby_forum@...>

I have a list of variables that I need to pass through a modifying

19 messages 2008/09/10
[#314574] Re: pass by reference in each loop — Pedro Silva <ei04065@...> 2008/09/11

Hi,

[#314659] Re: pass by reference in each loop — Xiong Chiamiov <xiong.chiamiov+ruby_forum@...> 2008/09/11

Pedro Silva wrote:

[#314660] Re: pass by reference in each loop — Robert Klemme <shortcutter@...> 2008/09/11

On 11.09.2008 23:12, Xiong Chiamiov wrote:

[#314663] Re: pass by reference in each loop — Xiong Chiamiov <xiong.chiamiov+ruby_forum@...> 2008/09/11

Robert Klemme wrote:

[#314563] How to detect blocking? — David Masover <ninja@...>

I've been (barely, occasionally) writing an Actor system for Ruby.

16 messages 2008/09/11
[#314567] Re: How to detect blocking? — Robert Klemme <shortcutter@...> 2008/09/11

On 11.09.2008 06:48, David Masover wrote:

[#314677] Re: How to detect blocking? — David Masover <ninja@...> 2008/09/12

On Thursday 11 September 2008 01:33:25 Robert Klemme wrote:

[#314843] Garbage collecting threads? (was: How to detect blocking?) — David Masover <ninja@...> 2008/09/13

Suppose I start a worker thread, like so:

[#314869] Re: Garbage collecting threads? — Robert Klemme <shortcutter@...> 2008/09/14

On 13.09.2008 22:59, David Masover wrote:

[#314898] Re: Garbage collecting threads? — David Masover <ninja@...> 2008/09/14

On Sunday 14 September 2008 03:24:53 Robert Klemme wrote:

[#314566] How to use this Combinatorial testing technique — Surya <surya5kn@...>

Hi Friends,

13 messages 2008/09/11

[#314590] Advanced conditionals — "Alain m. Lafon" <preek.aml@...>

Hi there,

14 messages 2008/09/11

[#314776] Beginner User having issue with converting char to ASCII — Nick Bo <bornemann1@...>

I am working on this assignment and this is the first class I have used

9 messages 2008/09/12

[#314826] RubyConf hotel: Only single-bed rooms available at group rate? — James Britt <james.britt@...>

Yesterday, the day or the day after I got the RubyConf E-mail giving me

14 messages 2008/09/13
[#314835] Re: RubyConf hotel: Only single-bed rooms available at group rate? — "Gregory Brown" <gregory.t.brown@...> 2008/09/13

On Sat, Sep 13, 2008 at 12:32 PM, James Britt <james.britt@gmail.com> wrote:

[#314838] Re: RubyConf hotel: Only single-bed rooms available at group rate? — James Britt <james.britt@...> 2008/09/13

Gregory Brown wrote:

[#314842] Re: RubyConf hotel: Only single-bed rooms available at group rate? — "Craig Demyanovich" <cdemyanovich@...> 2008/09/13

My partners and I were only able to book a non-smoking room with 1 king bed

[#314856] Re: RubyConf hotel: Only single-bed rooms available at group rate? — James Britt <james.britt@...> 2008/09/14

Craig Demyanovich wrote:

[#314861] A new database access framework for any Ruby (Iron or J) — Post-no-reply Tudbc <post-no-reply@...>

I would like to introduce my new exciting research in TUDBC (Truly

10 messages 2008/09/14

[#314877] how do deal with huge numbers and keep them accurate? — Tomi Zzzz <tomi_z@...>

Hello all, I wrote the following code:

10 messages 2008/09/14

[#314984] how to stream or write data into a tar.gz file as if the data were from files? — bwv549 <jtprince@...>

I have a gazillion little files in memory (each is really just a chunk

13 messages 2008/09/15

[#314989] Getting Employer to Pay for RubyConf — "Clinton D. Judy" <cdj@...>

So I'm just finishing my first year at a real job, and thinking about

15 messages 2008/09/15

[#315083] ANTLR Target for Ruby — arcadio <arcadiorubiogarcia@...>

Hi everyone,

29 messages 2008/09/16
[#315595] Re: ANTLR Target for Ruby — Clifford Heath <no@...> 2008/09/21

arcadio wrote:

[#315598] Re: ANTLR Target for Ruby — "Eric Mahurin" <eric.mahurin@...> 2008/09/21

On Sun, Sep 21, 2008 at 7:56 AM, Clifford Heath <no@spam.please.net> wrote:

[#315110] Gem program -- cannot install libxslt-ruby-0.3.6.gem — Robert Heller <heller@...>

I am trying to install some version of libxslt-ruby on my CentOS 4.7

9 messages 2008/09/17

[#315124] How to clean an xml files from non-utf-8 chars? — Krzysieq <krzysieq@...>

Hi,

19 messages 2008/09/17

[#315125] Threads preventing garbage collection? — Brian Candler <b.candler@...>

I wondered if someone can explain the following behaviour to me.

12 messages 2008/09/17

[#315203] Reseach paper on Ruby. Need references. — Suneel Suneel <suneelgv@...>

Hi,

12 messages 2008/09/18

[#315221] Suggestion for string parsing — Me Me <emanuelef@...>

Hi all,

18 messages 2008/09/18
[#315223] Re: Suggestion for string parsing — Chris Lowis <chris.lowis@...> 2008/09/18

> But I'm sure there's a better way, even considering that the number of

[#315224] Re: Suggestion for string parsing — Me Me <emanuelef@...> 2008/09/18

Thans for answering,

[#315227] Re: Suggestion for string parsing — Peña, Botp <botp@...> 2008/09/18

RnJvbTogTWUgTWUgW21haWx0bzplbWFudWVsZWZAdGlzY2FsaS5pdF0gDQojIEkgd2FzIHRoaW5r

[#315226] Preserve insert order in a Hash — Me Me <emanuelef@...>

Hi,

20 messages 2008/09/18
[#315228] Re: Preserve insert order in a Hash — Peña, Botp <botp@...> 2008/09/18

RnJvbTogTWUgTWUgW21haWx0bzplbWFudWVsZWZAdGlzY2FsaS5pdF0gDQojIEkgd291bGQgbGlr

[#315249] at_exit handler *except* for fatal runtime error — synergism <synergism@...>

How do we execute a handler (I assume via at_exit) when a program

16 messages 2008/09/18

[#315250] why one array continues to grow after repeated call — Li Chen <chen_li3@...>

Hi all,

21 messages 2008/09/18
[#315259] Re: why one array continues to grow after repeated call — "Rick DeNatale" <rick.denatale@...> 2008/09/18

On Thu, Sep 18, 2008 at 8:41 AM, Li Chen <chen_li3@yahoo.com> wrote:

[#315311] Re: why one array continues to grow after repeated call — Randy Kramer <rhkramer@...> 2008/09/18

On Thursday 18 September 2008 09:01 am, Rick DeNatale wrote:

[#315326] Re: why one array continues to grow after repeated call — Brian Candler <b.candler@...> 2008/09/18

> The statement "Line 4 might look like an assignment to the variable a,

[#315342] Re: why one array continues to grow after repeated call — Randy Kramer <rhkramer@...> 2008/09/18

On Thursday 18 September 2008 02:52 pm, Brian Candler wrote:

[#315287] short regexp question — Fritzek <fritz.thielemann@...>

Hi folks

19 messages 2008/09/18

[#315458] RDoc 2.2.0 released — Tony Strauss <tony.strauss@...>

RDoc 2.2.0 now is available!

20 messages 2008/09/19

[#315460] One-Liners Mashup (#177 again) — Matthew Moss <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

46 messages 2008/09/19
[#315474] Re: [QUIZ] One-Liners Mashup (#177 again) — "Bill Kelly" <billk@...> 2008/09/20

[#315478] Re: [QUIZ] One-Liners Mashup (#177 again) — James Gray <james@...> 2008/09/20

On Sep 19, 2008, at 9:32 PM, Bill Kelly wrote:

[#315476] update a field in CSV file using fastercsv — Li Chen <chen_li3@...>

Hello everyone,

11 messages 2008/09/20

[#315527] for or each? — tekwiz <twarlick@...>

I just used the new roodi gem to check out some of my code that has a

38 messages 2008/09/20
[#315532] Re: for or each? — Phlip <phlip2005@...> 2008/09/20

Phlip wrote:

[#315553] Re: for or each? — Joe Wfel <joe@...> 2008/09/20

It's interesting that array access using 'each' seems to be much

[#315750] Protecting Ruby code — Sasha Bee <rubyman77@...>

We are just starting a new project and it is going to be a commercial

13 messages 2008/09/23

[#315818] Small, simple Ruby applications and sample code? — Double Minus <nathan.wisman@...>

Hi all,

16 messages 2008/09/24

[#315867] Rake dependencies unknown prior to running tasks — Joe Wfel <joe@...>

Say I don't know what all the dependencies are until I've already

13 messages 2008/09/24
[#315872] Re: Rake dependencies unknown prior to running tasks — Mike Gold <mike.gold.4433@...> 2008/09/24

Joe W旦lfel wrote:

[#315873] Re: Rake dependencies unknown prior to running tasks — Mike Gold <mike.gold.4433@...> 2008/09/24

Mike Gold wrote:

[#315912] Getting the right class with inheritance and super() — "Kyle Schmitt" <kyleaschmitt@...>

I'm wondering what the _right_ way is to go about getting the right

12 messages 2008/09/24
[#315941] Re: Getting the right class with inheritance and super() — David Masover <ninja@...> 2008/09/25

On Wednesday 24 September 2008 15:45:13 Kyle Schmitt wrote:

[#315920] Guy Decoux. — "Jean-Fran輟is Tr穗" <jftran@...>

Hello,

32 messages 2008/09/24

[#315954] Gem update on Windows is broken? — Charles Roper <reachme@...>

When I issue the "gem update" command on Windows, whenever it gets to a

17 messages 2008/09/25
[#316019] Re: Gem update on Windows is broken? — Eric Hodel <drbrain@...7.net> 2008/09/25

On Sep 25, 2008, at 01:22 AM, Charles Roper wrote:

[#316027] How to get terminal dimensions without using curses or ncurses? — Kenneth McDonald <kenneth.m.mcdonald@...>

I'd like to be able to print to terminal and do some reasonable

9 messages 2008/09/25

[#316033] How to make Ruby _THE_ scripting language of choice, fold in SQLite — John Carter <john.carter@...>

Much has been written about the OOP / RDBMS impedance mismatch....

20 messages 2008/09/25
[#316046] Re: How to make Ruby _THE_ scripting language of choice, fold in SQLite — David Masover <ninja@...> 2008/09/26

On Thursday 25 September 2008 18:43:31 John Carter wrote:

[#316051] Re: How to make Ruby _THE_ scripting language of choice, fold in SQLite — Clifford Heath <no@...> 2008/09/26

David Masover wrote:

[#316068] my ears are burning... ;) — parrt@...

Hi Gang, sorry I seem to have pissed off the ruby gang. :) Never

13 messages 2008/09/26

[#316106] Cookie Monster (#178) — "Matthew Moss" <matthew.moss@...>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

17 messages 2008/09/26

[#316144] RubyGems 1.3.0 — Eric Hodel <drbrain@...7.net>

Note! Some versions of RubyGems have a bug that will prevent

15 messages 2008/09/26

[#316316] ruby1.9 block scope — Daniel DeLorme <dan-ml@...42.com>

I could have sworn that one of the firm changes in ruby 1.9 was that

45 messages 2008/09/29
[#316321] Re: ruby1.9 block scope — Yukihiro Matsumoto <matz@...> 2008/09/29

Hi,

[#316323] Re: ruby1.9 block scope — Daniel DeLorme <dan-ml@...42.com> 2008/09/29

Yukihiro Matsumoto wrote:

[#316325] Re: ruby1.9 block scope — Yukihiro Matsumoto <matz@...> 2008/09/29

Hi,

[#316347] Re: ruby1.9 block scope — Daniel DeLorme <dan-ml@...42.com> 2008/09/29

Yukihiro Matsumoto wrote:

[#316365] Re: ruby1.9 block scope — Nobuyoshi Nakada <nobu@...> 2008/09/29

Hi,

[#316386] Re: ruby1.9 block scope — Daniel DeLorme <dan-ml@...42.com> 2008/09/30

Nobuyoshi Nakada wrote:

[#316401] Re: ruby1.9 block scope — Yukihiro Matsumoto <matz@...> 2008/09/30

Hi,

[#316430] Re: ruby1.9 block scope — "David A. Black" <dblack@...> 2008/09/30

Hi --

[#316470] Re: ruby1.9 block scope — Daniel DeLorme <dan-ml@...42.com> 2008/09/30

David A. Black wrote:

[#316486] Re: ruby1.9 block scope — Mike Gold <mike.gold.4433@...> 2008/09/30

[#316495] Re: ruby1.9 block scope — Yukihiro Matsumoto <matz@...> 2008/09/30

Hi,

[#316499] Re: ruby1.9 block scope — Mike Gold <mike.gold.4433@...> 2008/09/30

Yukihiro Matsumoto wrote:

[#316392] Revision control for Ruby — thiagobrandam <thiagobrandam@...>

Does anyone know any good revision control tool/software for Ruby?

25 messages 2008/09/30

[#316450] Real world ruby programs to learn from — Fernando Perez <pedrolito@...>

Hi,

12 messages 2008/09/30

[#316526] Mode method for Array — Glenn <glenn_ritz@...>

Hi,

21 messages 2008/09/30
[#316533] Re: Mode method for Array — Trans <transfire@...> 2008/09/30

[#316536] Re: Mode method for Array — Erik Veenstra <erikveen@...> 2008/10/01

[#316552] Re: Mode method for Array — Brian Candler <b.candler@...> 2008/10/01

Shame that the standard Hash#invert doesn't handle duplicate values

[#316564] Re: Mode method for Array — Erik Veenstra <erikveen@...> 2008/10/01

And since we all love speed, we tend to avoid inject. (For

[SUMMARY] One-Liners Mashup (#177)

From: "Matthew Moss" <matthew.moss@...>
Date: 2008-09-26 02:17:53 UTC
List: ruby-talk #316050
Thanks to everyone who joined in on the one-liners mashup. I think
part of the challenge to the mashup was coming up with new problems.
It seems that, unless you've already solved the problem, it takes a
bit of intuition to come up with a problem that isn't trivial, but
also that can be done within a typical line or two. All the problems
presented seemed to fit right in.

I'm not going to do a regular summary here: the discussion on Ruby
Talk pretty much _is_ the summary. I will run through all the problems
very quickly, just pulling out the solution that appealed to me the
most in each case.

The problem:

    Write a single line method for Array that does this:
      > [:one, "two", 4].repeat(3)
      => [:one, :one, :one, "two", "two", "two", 4, 4, 4]

"The Nice" solution (I agree):

    def repeat(n)
      inject([]) { |a,e| a.concat [e]*n }
    end

The problem:

    Print out a Sierpinski carpet.

The shorter (but still kinda long) solution:

    def carpet(n)
      n==0?"#\n":carpet(n-1).map{|l| ['\0\0\0','\0
\0','\0\0\0'].map{|c| l.gsub(/#| /,c)}}.join
    end

The problem:

    Given the class:

      class Data2D
        def initialize
          @data = [ ]  # in row major form
        end

        def add_row(*row)
          @data << row
        end
      end

    And this setup for an object:

      data = Data2D.new
      data.add_row(1, 2, 3, 4)
      data.add_row(5, 6, 7, 8)

    define a [] method that makes this form of access possible:
      data[2][1]  # => 7

The tricksy call-you-later solution:

    class Data2D
      def [](x) lambda { |y| @data[y][x] }
    end

The problem:

    Write an []= method to solve the following:
      obj = YourClass.new
      obj['answer'] = 42
      obj.answer  # => 42

The what-the-heck-with-all-the-eval solution:

    class YourClass
      def []=(f, v)
        class << self; self end.instance_eval{ attr_accessor f };
instance_eval "@#{f}=v"
      end
    end

The problem:

    Given one or more input filenames on the command line, report the
number of unique IP addresses
    found in all the data.

The command-line solution:

    ruby -e 'p ARGF.read.scan(/\d{1,3}(\.\d{1,3}){3}/).uniq.size'

The problem:

    Here's something simple: define method roll(n, s) to roll a s-sided
    die n times and display a bar graph of the results. So roll(20, 4)
    might look like this:
     1|#####
     2|#####
     3|######
     4|####

A random solution:

    def roll(n,s)
      (1..n).map { |x| "#{x}|#{'#' * (1 + rand(s))}" } * "\n"
    end

The problem:

    Provide a one-liner that can wrap a body of text at a requested
maximum length.

The "Didn't we do this before?" solution:

    text.gsub(/(.{1,80})\s|(\w{80})/, "\\1\\2\n")

The problem:

    Sort an array of words by the words' values where a word's value is the
    sum of the values of its letters and a letter's value is its position in
    the alphabet. So the value of "Hello" is 8+5+12+12+15.

The "I mutated two solutions into one I like the bestest" solution:

    class Array
      def sortval()
        sort_by { |x| x.upcase.sum - x.length * ?@ }
      end
    end

The problem:

    Write a function per(n) which returns the periodicity of 1/n, i.e.
      per(3) => 1
      per(4) => 0
      per(7) => 6
      per(11) => 2

The "Ummm... yeah... how do these work?" solution:

    def per(n, b=10)
      i=1;x=b;h={};loop {x=x%n*b;break 0 if x==0;h[x]?(break
i-h[x]):h[x]=i; i+=1}
    end

The problem:

    Return the power set of an Array's elements.

The "Don't get up, I'll take care of it" solution:

    class Array
      def powerset
        inject([[]]) { |a,e| a + a.map { |b| b+[e] } }
      end
    end

The problem:

    Assuming you have an array of numeric data, write a method that
returns an array of progressive
    sums. That is:
      prog_sum( [1, 5, 13, -6, 20] ) =>  [1, 6, 19, 13, 33]

The obligatory inject solution:

    def prog_sum(ary)
      ary.inject([0, []]) {|(s, a), i| [s+i, a<<(s+i)]}.last
    end

The problem:

    Given an s-expression, print it out as a tree, where [:a,
    :b, :c, :d] is the node with parent a and children b, c and d

    [:foo, [:bar, [:baz, :quux], :hello, :world], :done] #=>

    foo
    | -- bar
    |    | -- baz
    |    |    | -- quux
    |    | -- hello
    |    | -- world
    | -- done

The last solution of the summary... solution:

    class Array
      def to_s
        collect{|x| x.to_s.gsub(/\n/,"\n|   ")}.join("\n|-- ")
      end
    end


Any unsolved problems? You bet! Here are the problems that didn't get
answered, in case you've got an itch for more.

    1. Given a text from STDIN and a regexp, print each line which (in part)
    matches regexp with two preceding and two successional lines. Do not output
    a line more than once.

    2. Starting with an array, find the first permutation of the elements of
    that array that is lexicographically greater than (i.e. sorts after)
    the given array.

    3. Write a oneliner next_fib(n) which gives the smallest Fibonacci number
    greater than n.

    4. Given an epsilon, compute PI to that precision.




-- 
Matthew Moss <matthew.moss@gmail.com>

In This Thread

Prev Next