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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2540. Minimum Common Value | [Link](https://leetcode.com/problems/minimum-common-value/) | [Link](./lib/easy/2540_minimum_common_value.rb) | [Link](./test/easy/test_2540_minimum_common_value.rb) |
| 2544. Alternating Digit Sum | [Link](https://leetcode.com/problems/alternating-digit-sum/) | [Link](./lib/easy/2544_alternating_digit_sum.rb) | [Link](./test/easy/test_2544_alternating_digit_sum.rb) |
| 2549. Count Distinct Numbers on Board | [Link](https://leetcode.com/problems/count-distinct-numbers-on-board/) | [Link](./lib/easy/2549_count_distinct_numbers_on_board.rb) | [Link](./test/easy/test_2549_count_distinct_numbers_on_board.rb) |
| 2652. Sum Multiples | [Link](https://leetcode.com/problems/sum-multiples/) | [Link](./lib/easy/2652_sum_multiples.rb) | [Link](./test/easy/test_2652_sum_multiples.rb) |
| 3110. Score of a String | [Link](https://leetcode.com/problems/score-of-a-string/) | [Link](./lib/easy/3110_score_of_a_string.rb) | [Link](./test/easy/test_3110_score_of_a_string.rb) |
| 3151. Special Array I | [Link](https://leetcode.com/problems/special-array-i/) | [Link](./lib/easy/3151_special_array_i.rb) | [Link](./test/easy/test_3151_special_array_i.rb) |
| 3498. Reverse Degree of a String | [Link](https://leetcode.com/problems/reverse-degree-of-a-string/) | [Link](./lib/easy/3498_reverse_degree_of_a_string.rb) | [Link](./test/easy/test_3498_reverse_degree_of_a_string.rb) |
Expand Down
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '9.2.4'
s.version = '9.2.5'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
16 changes: 16 additions & 0 deletions lib/easy/2652_sum_multiples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# https://leetcode.com/problems/sum-multiples/
# @param {Integer} n
# @return {Integer}
def sum_of_multiples(n)
result = 0

(1..n).each do |i|
next if !(i % 3).zero? && !(i % 5).zero? && !(i % 7).zero?

result += i
end

result
end
28 changes: 28 additions & 0 deletions test/easy/test_2652_sum_multiples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2652_sum_multiples'
require 'minitest/autorun'

class SumMultiplesTest < ::Minitest::Test
def test_default_one
assert_equal(
21,
sum_of_multiples(7)
)
end

def test_default_two
assert_equal(
40,
sum_of_multiples(10)
)
end

def test_default_three
assert_equal(
30,
sum_of_multiples(9)
)
end
end