-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkoombea.rb
More file actions
50 lines (41 loc) · 839 Bytes
/
koombea.rb
File metadata and controls
50 lines (41 loc) · 839 Bytes
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
47
48
49
50
t_initial = Time.now
file_name = ARGV.first
f = File.open(file_name)
input = []
result = []
f.each_line {|l| input << l.chomp}
input.each do |i|
temp_array = []
input.each do |j|
temp_array.push(j) if i.downcase.split('').sort.join('') == j.downcase.split('').sort.join('')
end
result.push(temp_array)
end
result = result.uniq
anagrams = []
n_anagrams = []
result.each do |r|
if r.count > 1 then
anagrams.push(r)
else
n_anagrams.push(r.join(""))
end
end
f1 = File.open("n_anagrams.txt","r+")
f1.truncate(0)
n_anagrams.each do |w|
f1.write(w)
f1.write("\n")
end
f1.close()
f2 = File.open("anagrams.txt","r+")
f2.truncate(0)
anagrams.each do |w|
str1 = w.join(",")
f2.write(str1)
f2.write("\n")
end
f2.close()
f.close()
#puts result.uniq
puts "Total Time Taken: #{(Time.now - t_initial)} seconds"