Skip to content

Instantly share code, notes, and snippets.

require 'chunky_png'
require 'backports' unless RUBY_VERSION >= "1.8.7"
include ChunkyPNG
image = Image.from_file('input.png')
xslices = (0...image.width).each_slice(10).to_a
yslices = (0...image.height).each_slice(10).to_a
xslices.product(yslices) do |xslice, yslice|
tots = [0, 0, 0, 0]
Alphabet = ('a'..'z').to_a
NWORDS = begin
words = Hash.new(0)
File.read('big.txt').downcase.scan(/[a-z]+/).each { |w| words[w] += 1 }
words
end
def correct(word)
(known([word]) || known(edits1(word)) || known_edits2(word) || [word]).max{|a,b| NWORDS[a] <=> NWORDS[b]}