diff --git a/exercises/practice/parallel-letter-frequency/.meta/example.rb b/exercises/practice/parallel-letter-frequency/.meta/example.rb index e69de29bb2..2c3039eb77 100644 --- a/exercises/practice/parallel-letter-frequency/.meta/example.rb +++ b/exercises/practice/parallel-letter-frequency/.meta/example.rb @@ -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 diff --git a/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.rb b/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.rb index 18abc3db41..9d7ed0a47f 100644 --- a/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.rb +++ b/exercises/practice/parallel-letter-frequency/parallel_letter_frequency.rb @@ -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 +