Skip to content

Instantly share code, notes, and snippets.

@mh-github
Created October 26, 2014 09:10
Show Gist options
  • Select an option

  • Save mh-github/91fae2524f503289fd7e to your computer and use it in GitHub Desktop.

Select an option

Save mh-github/91fae2524f503289fd7e to your computer and use it in GitHub Desktop.
sorting words with Ruby using struct
#! /usr/bin/env ruby
require "./mh_util"
txt = 'but soft what light in yonder window breaks'
words = txt.split()
t = []
words.each {|word| t << MH_util::Tuple.new(word.size, word)}
t.sort!.reverse!
res = []
t.each {|pair| res << pair.second}
res.each {|word| print word + "\t"}
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment