Skip to content

Commit

Permalink
Add example implementation of parallel_letter_frequency exercise
Browse files Browse the repository at this point in the history
Co-authored-by: KOTP <[email protected]>
  • Loading branch information
ccadden and kotp committed Mar 4, 2024
1 parent 9e83dda commit cd69c6a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions exercises/practice/parallel-letter-frequency/.meta/example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class ParallelLetterFrequency
def self.count(texts)
ractors = (0...texts.length).map do |i|
Ractor.new(texts[i]) do |text|
text.downcase.each_grapheme_cluster.select do |cluster|
cluster.match?(/\p{Alpha}/)
end.tally
end
end

tally = Hash.new(0)

until ractors.empty?
ractor, result = Ractor.select(*ractors)
ractors.delete ractor
result.each do |key, value|
tally[key] += value
end
end

tally
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
=begin
Write your code for the 'Parallel Letter Frequency' exercise in this file. Make the tests in
`parallel_letter_frequency_test.rb` pass.
Write your code for the 'Parallel Letter Frequency' exercise in this file. Make
the tests in `parallel_letter_frequency_test.rb` pass.
To get started with TDD, see the `README.md` file in your
`ruby/parallel_letter_frequency` directory.
=end

0 comments on commit cd69c6a

Please sign in to comment.