On Mar 25, 2008, at 4: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 I didn't really golf it, but my answer is: #!/usr/bin/env ruby -wKU input = <<END_INPUT foo \t bar \t \t baz \t \t \t hello \t \t world END_INPUT bullets = %w[* - o x] input.gsub!(/^(\t ?)+/) do |indent| tabs = indent.count("\t") - 1 " " * tabs + bullets[tabs] + " " end puts input __END__ James Edward Gray II