mil3 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f77e16ab4e9546df14138e7df5ee41ab916a691
4
+ data.tar.gz: 999e5c615a73a177caa821bc143f852788005f06
5
+ SHA512:
6
+ metadata.gz: c837ff48df4007244a565f88f4ca8fea40c91b4f267fb713ac47828238bf7a5250a09a8e891a4aed80a698f8b34032cfde3e3fc00fff171132e82a0a238e0afb
7
+ data.tar.gz: f68bb7695acdd6ad1a255404e49c3009f887f3a57800da091e1eeb0f2d94d1461ad0b1563149b1778fb960d92510dcc9d58bc36f8c977b046acc9cd4959be587
@@ -0,0 +1,12 @@
1
+ def generate_scoring(num)
2
+ 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']
3
+ scoring = {}
4
+ if num == 1
5
+ i = 1
6
+ letters.each { |char| scoring[char] = i; i += 1 }
7
+ elsif num == 2
8
+ i = 26
9
+ letters.each { |char| scoring[char] = i; i -= 1 }
10
+ end
11
+ return scoring
12
+ end
data/lib/mil3.rb ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'open-uri'
4
+ require_relative 'parse_word'
5
+ require_relative 'thread_counter'
6
+ require_relative 'generate_scoring'
7
+
8
+ if ARGV.include? '-h'
9
+ puts "
10
+ Usage: #{$0} [options]\n
11
+ -v verbose: running thread count
12
+ -o oxford verification: use oed.com to verify output
13
+ "
14
+ exit
15
+ end
16
+
17
+ mil1 = generate_scoring(1)
18
+ mil2 = generate_scoring(2)
19
+
20
+ words = {}
21
+
22
+ # dictionary definition
23
+ puts "What dictionary would you like to use?\nEnter 'brute force' for the brute force approach... (this will take a lot of time)"
24
+ dictionary = STDIN.gets.chomp
25
+ if dictionary == 'brute force'
26
+ dictionary = ('a'...'zzzzzzzzzzz').to_a
27
+ else
28
+ dictionary = open(dictionary).read.split
29
+ end
30
+
31
+ threads = []
32
+ dictionary.each_slice(10000) do |batch|
33
+ threads.push(Thread.new do
34
+ batch.each { |word| parse_word(mil1, mil2, words, word) }
35
+ thread_counter if ARGV.include? '-v'
36
+ end)
37
+ end
38
+
39
+ threads.each { |thread| thread.join }
40
+
41
+ if ARGV.include? '-o'
42
+ loop do
43
+ print "lowest valued word - #{words.key(words.values.min)}: #{words.values.min}"
44
+ if open("http://www.oed.com/search?searchType=dictionary&q=#{words.key(words.values.min)}&_searchBtn=Search").read =~ /.+No dictionary entries found.+/
45
+ print ' - NOT A WORD'
46
+ words.delete(words.key(words.values.min))
47
+ else
48
+ puts
49
+ break
50
+ end
51
+ puts
52
+ end
53
+
54
+ puts '--------------------------------------'
55
+ puts "Winner of the given set..... #{words.key(words.values.min)}: #{words.values.min}"
56
+ puts '#oxfordverified'
57
+ puts '--------------------------------------'
58
+ else
59
+ puts "#{words.key(words.values.min)}: #{words.values.min}"
60
+ end
61
+
data/lib/parse_word.rb ADDED
@@ -0,0 +1,16 @@
1
+ def parse_word(score1, score2, words, word)
2
+ begin
3
+ word_val1 = 1
4
+ word_val2 = 1
5
+ word.downcase.each_char do |char|
6
+ word_val1 *= score1[char]
7
+ word_val2 *= score2[char]
8
+ end
9
+ result = (1000000-word_val1).abs + (1000000-word_val2).abs
10
+ words[word.downcase] = result if result <= 300000
11
+ rescue TypeError
12
+ # do nothing
13
+ # the word contains some invalid char
14
+ end
15
+ end
16
+
@@ -0,0 +1,4 @@
1
+ def thread_counter
2
+ puts "Threads: #{Thread.list.select {|thread| thread.status == "run"}.count}"
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mil3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Logan Bond
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A first attempt at gems with the millionaire3 puzzle
14
+ email: bon56277@obu.edu
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/generate_scoring.rb
20
+ - lib/mil3.rb
21
+ - lib/parse_word.rb
22
+ - lib/thread_counter.rb
23
+ homepage:
24
+ licenses:
25
+ - ''
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Millionair3 puzzle solver
47
+ test_files: []