-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.rb
executable file
·46 lines (38 loc) · 1.06 KB
/
run.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env ruby
require_relative './anagram'
# Driver
if ARGV.size == 1
if File.exists?(ARGV.first.to_s)
puts "Processing ...\n\n"
Anagram.filename = ARGV.first.to_s
anagram_set = Anagram.extract_anagrams
anagram_set.each do |key, words|
output = ''
words.each do |word|
output += word + ' '
end
output += "\n"
puts output
end
puts "\n\nThe longest words that are anagrams are: \n"
output = ''
max_anagrams_lengths = Anagram.max_anagrams_lengths
max_anagrams_lengths.last.each do |word|
output += word + ' '
end
output += "\nwith #{max_anagrams_lengths.first.length} characters."
puts output
puts "\n\nThe set of anagrams the contain most words are: \n"
output = ''
max_anagrams_counter = Anagram.max_anagrams_count
max_anagrams_counter.last.each do |word|
output += word + ' '
end
output += "\nwith #{max_anagrams_counter.last.count} occurences.\n"
puts output
else
puts 'File not found'
end
else
puts "Usage:\n run.rb FILENAME"
end