Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#generate_scoring(num) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
# File 'lib/generate_scoring.rb', line 1

def generate_scoring(num)
    letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    scoring = {}
    if num == 1
        i = 1
        letters.each { |char| scoring[char] = i; i += 1 }
    elsif num == 2
        i = 26
        letters.each { |char| scoring[char] = i; i -= 1 }
    end
    return scoring
end

#parse_word(score1, score2, words, word) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/parse_word.rb', line 1

def parse_word(score1, score2, words, word)
    begin
        word_val1 = 1
        word_val2 = 1
        word.downcase.each_char do |char|
            word_val1 *= score1[char]
            word_val2 *= score2[char]
        end
        result = (1000000-word_val1).abs + (1000000-word_val2).abs
        words[word.downcase] = result if result <= 300000
    rescue TypeError
        # do nothing
        # the word contains some invalid char 
    end
end

#thread_counterObject



1
2
3
# File 'lib/thread_counter.rb', line 1

def thread_counter
    puts "Threads: #{Thread.list.select {|thread| thread.status == "run"}.count}"
end