7 kyu

Jumps in a cycle #1

228 of 323Donvito-911

Description:

Jumps in a cycle

A cycle [a1,,an][a_1, \dots, a_n] can be written in a extended form with a jump rate equal to 1 as a1a2...ana1...an...a_1 \rightarrow a_2\rightarrow ... \rightarrow a_n\rightarrow a_1 \rightarrow ... \rightarrow a_n ...

Given a jump rate k and starting in the first element, you must find the number of jumps you have to take in order to reach the same element.

ASSUMPTION: The elements in the cycle are distinguishable.

Examples

[1, 5, 7, 8, 9] and jump rate 1, then 1578911 \rightarrow 5\rightarrow 7\rightarrow 8\rightarrow 9 \rightarrow 1. That is, 5 jumps.

[1, 5, 7, 8, 9] and jump rate 2, then 1795811 \rightarrow 7\rightarrow 9\rightarrow 5 \rightarrow 8 \rightarrow 1. That is, 5 jumps.

[1, 5, 1] and jump rate 2, then 11511 \rightarrow 1\rightarrow 5\rightarrow 1. That is, 3 jumps.

Input

  • cl: (list) the list with the cycle. 2cl2302\leq cl\leq2^{30}
  • k: (int) the jump rate. 1k2401\leq k\leq2^{40}

Output

(int) The number of jumps in order to reach the same first element in the cycle.

Mathematics
Puzzles
Performance

More By Author:

Check out these other kata created by Donvito-911

Stats:

CreatedFeb 24, 2023
PublishedFeb 26, 2023
Warriors Trained1287
Total Skips26
Total Code Submissions3583
Total Times Completed323
Python Completions228
C++ Completions77
Rust Completions40
Factor Completions7
Total Stars22
% of votes with a positive feedback rating81% of 68
Total "Very Satisfied" Votes48
Total "Somewhat Satisfied" Votes14
Total "Not Satisfied" Votes6
Total Rank Assessments11
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Donvito-911 Avatar
  • Kacarott Avatar
  • dfhwze Avatar
  • 66  Avatar
  • python000 Avatar
Ad