Skip to content

Commit af83e81

Browse files
committed
2024-09-25 v. 6.6.8: added "204. Count Primes"
1 parent ac2d89f commit af83e81

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
44

55
gem 'minitest', '5.18.0'
66
gem 'open-uri', '0.3.0'
7+
gem 'prime', '0.1.2'
78
gem 'rake', '12.3.3'
89
gem 'rubocop', '1.7.0'
910
gem 'simplecov', '0.22.0'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
533533
| 189. Rotate Array | [Link](https://leetcode.com/problems/rotate-array/) | [Link](./lib/medium/189_rotate_array.rb) | [Link](./test/medium/test_189_rotate_array.rb) |
534534
| 199. Binary Tree Right Side View | [Link](https://leetcode.com/problems/binary-tree-right-side-view/) | [Link](./lib/medium/199_binary_tree_right_side_view.rb) | [Link](./test/medium/test_199_binary_tree_right_side_view.rb) |
535535
| 200. Number of Islands | [Link](https://leetcode.com/problems/number-of-islands/) | [Link](./lib/medium/200_number_of_islands.rb) | [Link](./test/medium/test_200_number_of_islands.rb) |
536+
| 204. Count Primes | [Link](https://leetcode.com/problems/count-primes/) | [Link](./lib/medium/204_count_primes.rb) | [Link](./test/medium/test_204_count_primes.rb) |

leetcode-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '6.6.7'
8+
s.version = '6.6.8'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'

lib/medium/204_count_primes.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require 'prime'
4+
5+
# https://leetcode.com/problems/count-primes/
6+
# @param {Integer} n
7+
# @return {Integer}
8+
def count_primes(n) = ::Prime.each(n - 1).count
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/204_count_primes'
5+
require 'minitest/autorun'
6+
7+
class CountPrimesTest < ::Minitest::Test
8+
def test_default_one = assert_equal(4, count_primes(10))
9+
10+
def test_default_two = assert_equal(0, count_primes(0))
11+
12+
def test_default_three = assert_equal(0, count_primes(1))
13+
end

0 commit comments

Comments
 (0)