From 67e63cbecae87169aaa627cbc39c433a324edc25 Mon Sep 17 00:00:00 2001 From: fartem Date: Thu, 6 Mar 2025 07:28:06 +0300 Subject: [PATCH] 2025-03-06 v. 8.8.4: added "1823. Find the Winner of the Circular Game" --- README.md | 1 + leetcode-ruby.gemspec | 2 +- .../1823_find_the_winner_of_the_circular_game.rb | 11 +++++++++++ .../test_1823_find_the_winner_of_the_circular_game.rb | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 lib/medium/1823_find_the_winner_of_the_circular_game.rb create mode 100644 test/medium/test_1823_find_the_winner_of_the_circular_game.rb diff --git a/README.md b/README.md index f27b7c7f..c211be5a 100644 --- a/README.md +++ b/README.md @@ -717,6 +717,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 1780. Check if Number is a Sum of Powers of Three | [Link](https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/) | [Link](./lib/medium/1780_check_if_number_is_a_sum_of_powers_of_three.rb) | [Link](./test/medium/test_1780_check_if_number_is_a_sum_of_powers_of_three.rb) | | 1797. Design Authentication Manager | [Link](https://leetcode.com/problems/design-authentication-manager/) | [Link](./lib/medium/1797_design_authentication_manager.rb) | [Link](./test/medium/test_1797_design_authentication_manager.rb) | | 1814. Count Nice Pairs in an Array | [Link](https://leetcode.com/problems/count-nice-pairs-in-an-array/) | [Link](./lib/medium/1814_count_nice_pairs_in_an_array.rb) | [Link](./test/medium/test_1814_count_nice_pairs_in_an_array.rb) | +| 1823. Find the Winner of the Circular Game | [Link](https://leetcode.com/problems/find-the-winner-of-the-circular-game/) | [Link](./lib/medium/1823_find_the_winner_of_the_circular_game.rb) | [Link](./test/medium/test_1823_find_the_winner_of_the_circular_game.rb) | | 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) | | 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) | | 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index da3251a8..831d9ecd 100644 --- a/leetcode-ruby.gemspec +++ b/leetcode-ruby.gemspec @@ -5,7 +5,7 @@ require 'English' ::Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0' s.name = 'leetcode-ruby' - s.version = '8.8.3' + s.version = '8.8.4' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/medium/1823_find_the_winner_of_the_circular_game.rb b/lib/medium/1823_find_the_winner_of_the_circular_game.rb new file mode 100644 index 00000000..a0e8de23 --- /dev/null +++ b/lib/medium/1823_find_the_winner_of_the_circular_game.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +# https://leetcode.com/problems/find-the-winner-of-the-circular-game/ +# @param {Integer} n +# @param {Integer} k +# @return {Integer} +def find_the_winner(n, k) + return 1 if n == 1 + + (find_the_winner(n - 1, k) + k - 1) % n + 1 +end diff --git a/test/medium/test_1823_find_the_winner_of_the_circular_game.rb b/test/medium/test_1823_find_the_winner_of_the_circular_game.rb new file mode 100644 index 00000000..db03ec84 --- /dev/null +++ b/test/medium/test_1823_find_the_winner_of_the_circular_game.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require_relative '../../lib/medium/1823_find_the_winner_of_the_circular_game' +require 'minitest/autorun' + +class FindTheWinnerOfTheCircularGameTest < ::Minitest::Test + def test_default_one = assert_equal(3, find_the_winner(5, 2)) + + def test_default_two = assert_equal(1, find_the_winner(6, 5)) +end