From: "David A. Black" Date: 2008-03-26T07:58:16+09:00 Subject: Re: golf: tabs to bullets Hi -- On Wed, 26 Mar 2008, ara howard wrote: > > On Mar 25, 2008, at 3:02 PM, Martin DeMello wrote: > >> Given: >> an outline list, with each line indented by a series of tabs >> a list of bullets (assume a circular list, for simplicity) >> >> Write a function that replaces every tab with two spaces, except for >> the last one, which is replaced by a bullet. >> >> example: >> >> input file: >> foo >> \t bar >> \t \t baz >> \t \t \t hello >> \t \t world >> >> bullets: %w(* - o x) > > cfp2:~ > cat a.rb > DATA.read.gsub(%r/(?:\t\ ?)+/){|s|' '*(n=s.count("\t")-1)+%w(* - o x)[n]+' > '}.display I don't think that does the two-space thing: david-blacks-macbook:hacking dblack$ cat ara.rb <