From: William James Date: 2008-03-26T10:54:58+09:00 Subject: Re: golf: tabs to bullets On Mar 25, 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) > > output (view in fixed width): > foo > * bar > - baz > o hello > - world > > martin bullets = %w(. * - o x) "foo \t bar \t \t baz \t \t \t hello \t \t world ".each{|x| puts x.reverse.sub("\t",bullets[x.count("\t")]). reverse.gsub("\t"," ") }