Skip to content

Instantly share code, notes, and snippets.

@tormaroe
Created March 28, 2013 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tormaroe/5261088 to your computer and use it in GitHub Desktop.
Save tormaroe/5261088 to your computer and use it in GitHub Desktop.
A small script to parse a text file and produce output for Wordle.
# Encoding: UTF-8
Encoding.default_external = "UTF-8"
require 'benchmark'
BLACKLIST = %w(på og er om fra med i to det å
ditt til ved fra for av en din
du at vi har vil nå det som dere
kan vår så)
$words = {}
def parse_words file
puts "Parsing words.."
File.readlines(file).each do |line|
line.split.each do |word|
word = word.strip.gsub /[\,\.\!\:]$/, ""
next if word == ""
next if BLACKLIST.include? word.downcase
if $words.include? word
$words[word] += 1
else
$words[word] = 1
end
end
end
end
def trim_rare_words
puts "Trimming rare words.."
$words.select! {|word, count| count > 1000 }
end
def wordle_output stream
puts "Outputing.."
$words.each do |word, count|
stream.puts "#{word}:#{count}"
end
end
puts Benchmark.measure {
parse_words ARGV.shift
trim_rare_words
File.open("out.txt", "w") {|f| wordle_output f }
puts "DONE"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment