5 kyu
Ways from one number to another
Description:
In this kata you are given two integers: initial number
, target number
two arrays and fixed set of instructions:
1. Add 3 to the number
2. Add the sum of its digits to a number, if number is not 0
3. Add the number reduced modulo 4 to the number, if the modulus is not 0
Your task is to find amount of ways you can get from the initial number
to the target number
, performing these instructions
Also, there's some limitations, which are must include
and must avoid
arrays. Both should be set to None
by default
must include
: A list of numbers that must be included in the sequence of transformations from the initial number to the target number.must avoid
: A list of numbers that must be avoided in this sequence.
For example, you're given 1 as initial number
and 7 as target number
,
There are 5 ways to get from 1 to 7. You can perform instructions in following orders:
- 1, 1 (1 -> 4 -> 7)
- 2, 2, 1 (1 -> 2 -> 4 -> 7)
- 2, 3, 1 (1 -> 2 -> 4 -> 7)
- 3, 2, 1 (1 -> 2 -> 4 -> 7)
- 3, 3, 1 (1 -> 2 -> 4 -> 7)
However, if there will be 2 in must avoid
there is only 2 (first) way left
Or if there will be 2 in must include
we can perform any of these, except first
Notes:
initial number
andtarget number
may be negativetarget number
always greater thaninsital number
- If there isn't any numbers that should be included or avoided, corresponding argument may be set to empty list, None or not passed at all
- Values in
must include
andmust avoid
in tests are always valid (beetweeninitial number
andtarget number
) - Ranges for
initial number
andtarget number
are [-10; 28] and [initial_num + 1; 30] must include
andmust avoid
arrays never intersect in tests
Algorithms
Mathematics
Similar Kata:
Stats:
Created | Nov 27, 2023 |
Published | Nov 27, 2023 |
Warriors Trained | 221 |
Total Skips | 5 |
Total Code Submissions | 456 |
Total Times Completed | 54 |
Python Completions | 54 |
Total Stars | 6 |
% of votes with a positive feedback rating | 93% of 21 |
Total "Very Satisfied" Votes | 18 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 13 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |