Created
October 26, 2014 09:10
-
-
Save mh-github/91fae2524f503289fd7e to your computer and use it in GitHub Desktop.
sorting words with Ruby using struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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