Skip to content

Instantly share code, notes, and snippets.

@zudochkin
Created March 24, 2012 22:06
Show Gist options
  • Save zudochkin/2188449 to your computer and use it in GitHub Desktop.
Save zudochkin/2188449 to your computer and use it in GitHub Desktop.
Just for fun (Slovomania game)
# encoding: utf-8
require 'mongo'
require 'mongo_mapper'
MongoMapper.database = 'words'
class Word
include MongoMapper::Document
key :word
end
#p Word.first(:word => 'жоjjпа')
#abort 's'
COMBINATIONS_FILE = './game.dat'
#alphabet = 'ежетучврщоетредь'
#alphabet = 'нотерыокеатакирб'
#Alphabet = alphabet.split
#=begin
Alphabet = %w{
ё ж е т
у ч е р
к о ю т
р м п ь
}
#=end
start = Time.now
counter = 0
combinations = []
File.open(COMBINATIONS_FILE, 'r') do |f|
#SimpleProgressbar.new.show("Installing stuff") do
while (line = f.gets)
#f.readlines.each do |line|
counter += 1
#progress counter / 12_000_000
line = line.split(',')
if (3..9).include? line.size
word = line.map{ |l| Alphabet[l.to_i - 1] }.join
begin
w = Word.first(:word => word)
#w = w.word
combinations << w.word #unless combinations.include? w
rescue
next
end
end
if counter % 100_000 == 0
#begin
#p combinations.uniq.join(' ')
p combinations.join ' '
#rescue
#end
p "#{Time.now - start} - #{counter}"
start = Time.now
end
#start = Time.now if counter % 100 == 0
end
#end
end
p (Time.now - start)
p counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment