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 and target number may be negative
  • target number always greater than insital 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 and must avoid in tests are always valid (beetween initial number and target number)
  • Ranges for initial number and target number are [-10; 28] and [initial_num + 1; 30]
  • must include and must avoid arrays never intersect in tests
Algorithms
Mathematics

Stats:

CreatedNov 27, 2023
PublishedNov 27, 2023
Warriors Trained221
Total Skips5
Total Code Submissions456
Total Times Completed54
Python Completions54
Total Stars6
% of votes with a positive feedback rating93% of 21
Total "Very Satisfied" Votes18
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments13
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • ZolotarevAlexandr Avatar
  • dfhwze Avatar
Ad