diff --git a/.github/workflows/exercise-tests.yml b/.github/workflows/exercise-tests.yml index 6606205733..1ecb3d4178 100644 --- a/.github/workflows/exercise-tests.yml +++ b/.github/workflows/exercise-tests.yml @@ -16,7 +16,7 @@ jobs: matrix: os: - ubuntu-24.04 - ruby-version: [3.2, 3.3] + ruby-version: [3.3, 3.4] steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 diff --git a/README.md b/README.md index 3f1eb170c5..d758a4e2d5 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,11 @@ Exercism Exercises in Ruby ## Setup -You'll need a recent (2.6+) version of Ruby, but that's it. +You will want a recent (3.4+) version of Ruby, but that's it. Minitest ships with the language, so you're all set. +Older versions of Ruby may work, but are not officially supported. + ## Anatomy of an Exercise The files for an exercise live in `exercises/`. diff --git a/exercises/practice/parallel-letter-frequency/.meta/example.rb b/exercises/practice/parallel-letter-frequency/.meta/example.rb index 2c3039eb77..3416b86c6e 100644 --- a/exercises/practice/parallel-letter-frequency/.meta/example.rb +++ b/exercises/practice/parallel-letter-frequency/.meta/example.rb @@ -1,10 +1,34 @@ 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 + return {} if texts.empty? + + ractor_count = [texts.length, 8].min + batch_size = (texts.length.to_f / ractor_count).ceil + ractors = texts.each_slice(batch_size).map do |batch| + Ractor.new(batch) do |batch_texts| + ascii_counts = Array.new(26, 0) + tally = Hash.new(0) + + batch_texts.each do |text| + if text.ascii_only? + text.each_byte do |byte| + case byte + when 65..90 then ascii_counts[byte - 65] += 1 + when 97..122 then ascii_counts[byte - 97] += 1 + end + end + else + text.downcase.each_grapheme_cluster do |cluster| + tally[cluster] += 1 if cluster.match?(/\p{Alpha}/) + end + end + end + + ascii_counts.each_with_index do |count, index| + tally[(index + 97).chr] += count unless count.zero? + end + + tally end end