$names = File.read("friends.txt").split("\n")def first_frequencies first = $names.map {|line| line.split(" ")[0]} first_freq = (first.map {|name| [name, first.count(name)]}).uniq return first_freqenddef last_frequencies last = $names.map {|line| line.split(" ")[-1]} last_freq = (last.map {|name| [name, last.count(name)]}).uniq return last_freqenddef matches(search) $names.select {|el| match?(el, search)}enddef match?(name, search) name.downcase.split(" ").inject(false) {|bool, n| bool or n.include?(search.downcase)}enddef strings(length) if length <= 0 or length.to_i != length return [""] end ret = [] for str in strings(length-1) for ch in "a".."z" ret << str + ch end end return retenddef unique_generators_for_name(name)enddef unique_generators_by_length(length) print "mapping... " $stdout.flush list = strings(length).map {|str| [[str], matches(str)]} puts "mapped" $stdout.flush print "selecting..." $stdout.flush list = list.select {|el| el[1].length == 1} puts "selected" $stdout.flush return listenddef consolidate_bad(generators) # takes a list of [search, name] pairs and consolidates searches that lead # to the same name names = generators.map {|el| el[1]}.uniq searches = generators.map {|el| el[0]} ret = names.map {|name| [searches.select {|el| generators.include?([el, name])}, name]} return retenddef consolidate(generators) hash = Hash.new {|h, k| h[k] = 0} for name in generators.map {|el| el[1]} hash[name] += 1 end ret = [] for pair in generators puts "working on #{pair.inspect}" next if pair == nil if hash[pair[1]] == 1 ret << pair else searches = [] for i in 0...generators.length next if generators[i] == nil if generators[i][1] == pair[1] searches << generators[i][0][0] generators[i] = nil end end ret << [searches, pair[1]] end end return retendi = 0count = 0for str in strings(5) for name in $names if name.downcase.include?(str) count += 1 break end end i += 1 if i % 194069 == 0 temp = 100 * i.to_f / (26 ** 5) puts "#{"%.1f" % temp}% done" endendputs count#temp = unique_generators_by_length(4)#$stdout.flush#ls = consolidate(temp)#for el in ls# puts "#{el[0].inspect.gsub(/[\[\]]/,"")}:\t#{el[1].inspect}"#end#puts ls.length