Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/exercise-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<slug>`.
Expand Down
34 changes: 29 additions & 5 deletions exercises/practice/parallel-letter-frequency/.meta/example.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down