4 kyu

Spinning Rings - Fidget Spinner Edition

105 of 263Voile

Description:

This is the performance version of this kata.


Imagine two rings with numbers on them. The inner ring spins clockwise and the outer ring spins anti-clockwise. We start with both rings aligned on 0 at the top, and on each move we spin each ring by 1. How many moves will it take before both rings show the same number at the top again?

The inner ring has integers from 0 to innerMax and the outer ring has integers from 0 to outerMax, where innerMax and outerMax are integers >= 1.

e.g. if innerMax is 2 and outerMax is 3 then after
1 move: inner = 2, outer = 1
2 moves: inner = 1, outer = 2
3 moves: inner = 0, outer = 3
4 moves: inner = 2, outer = 0
5 moves: inner = 1, outer = 1
Therefore it takes 5 moves for the two rings to reach the same number
Therefore spinningRings(2, 3) = 5
e.g. if innerMax is 3 and outerMax is 2 then after
1 move: inner = 3, outer = 1
2 moves: inner = 2, outer = 2
Therefore it takes 2 moves for the two rings to reach the same number
spinningRings(3, 2) = 2

Test input range:

  • 100 tests with 1 <= innerMax, outerMax <= 10000
  • 400 tests with 1 <= innerMax, outerMax <= 2^48
Performance

Similar Kata:

Stats:

CreatedSep 7, 2017
PublishedSep 7, 2017
Warriors Trained2998
Total Skips746
Total Code Submissions5245
Total Times Completed263
Python Completions105
Ruby Completions14
JavaScript Completions81
COBOL Completions8
D Completions6
Rust Completions14
Go Completions11
C++ Completions20
C# Completions13
C Completions51
Total Stars144
% of votes with a positive feedback rating90% of 63
Total "Very Satisfied" Votes54
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes3
Total Rank Assessments3
Average Assessed Rank
4 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • Voile Avatar
  • ZED.CWT Avatar
  • hobovsky Avatar
  • akar-0 Avatar
  • dfhwze Avatar
Ad