Skip to content

Instantly share code, notes, and snippets.

@tsnow
Created December 27, 2013 16:03
Show Gist options
  • Save tsnow/8149013 to your computer and use it in GitHub Desktop.
Save tsnow/8149013 to your computer and use it in GitHub Desktop.
live vs alive
words = File.read('/usr/share/dict/words').lines.to_a.map(&:chomp);
a_words = words.select{|i| i =~ /^a.*/};
a_sub_words = words.select{|i| a_words.any?{|j| j[i]}};
a_sub_words.length
a_sub_words -= a_words
ad_words = a_sub_words.select{|i| a_words.include?("a#{i}")}; ad_words.length
def pretty(a);
cols=a.sort_by(&:length).group_by(&:length).to_a.sort.map(&:last);
tot=cols.max{|i| i.length}.length;
cols.each do |j|
j[tot]=nil;
end;
cols.first.zip(*cols[1..-1]).map{|k| k.join(' ')}.join("\n");
end
pretty(ad_words).split(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment