■ code golf - String of alphanumeric characters to a sorted list of comma-separated ranges このRubyの解なんだけど、与えられた文字以外を改行($/)に変換するという発想がすばらしい。 puts [*?0..?Z].join.tr('^ABC321STPpJqZZr0'.upcase,' ').gsub(/\B\w+\B/,?-).scan(/\S+/)*', ' puts [*?0..?Z].join.tr('^ABC321STPpJqZZr0'.upcase,$/).gsub(/\B\w+\B/,?-).scan(/.+/)*', ' puts [*?0..?Z].join.tr('^ABC321STPpJqZZr0'.upcase,$/).gsub(/\B.+\B/,?-).scan(/.+/