forked from JClutch/Test-Bank
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
juan's coding challenge prompts added; solutions to follow
- Loading branch information
1 parent
5c108ae
commit dfa79c7
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Strange Sequence | ||
|
||
## Prompt 1 | ||
|
||
Write a function that determines the minimum number of rotations needed to unlock a a basic number combination lock | ||
|
||
A rotation is defined as each time you increment/decrement a number by one. | ||
For example, to get from 2 to 4, you would perform 2 rotations: | ||
2 -> 3, and 3 -> 4 | ||
|
||
Furthermore, the lock can wrap around the numbers, so that it would only take 3 rotations to get from 9 to 2 | ||
9 -> 0, 0 -> 1, and 1 ->2 | ||
|
||
Your function takes two arguments: | ||
1. the current state of the lock, which is shown as an array of single digits representing each bit of the lock | ||
2. An array showing the unlocking position | ||
Both arrays will made up of single digits and they will be the same length, though they can be of any size | ||
|
||
Example: | ||
current lock state: [0, 0, 0] | ||
unlocking combination: [3, 1, 8] | ||
|
||
first: 0 -> 1 -> 2 -> 3 ____ 3 rotations | ||
Second: 0 -> 2 ___ 1 rotation | ||
third: 0 -> 9 -> 8 ____ 2 rotations | ||
Total: 6 rotations | ||
|
||
|
||
## Prompt 2 | ||
|
||
Update your answer to the previous prompt to account for locks with arbitrary characters instead of numbers 0-9. | ||
They will be accepted as a third character set array, and will contain at least two strings. | ||
The character set is ordered and will contain only unique values. | ||
Similarly, you are able to wrap around the lock from one end of the array to the other. | ||
Your first two array arguments will only contains values that appear in the character set of locks | ||
|
||
Example: | ||
starting point: ['*', '#', '+'] | ||
unlocking combination: ['+', 'i', '{\}'] | ||
Character set: ['!', '+', '*', ')', 'i', '=', '{\}', '#'] | ||
|
||
The result would be the following: | ||
'*' -> '+ ____ 1 rotation | ||
'#' -> '{\}' -> '=' -> 'i' ____ 3 rotations | ||
'+' -> '!' -> '#' -> '{\}' ___ 3 rotations | ||
Total: 7 rotations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Strange Sequence | ||
|
||
## Prompt | ||
|
||
Imagine a sequence of numbers x0, x1, x2,..., xn where a given element is equal to the sum of the squared digits of the previous element. | ||
|
||
The sequence ends once you reach an element that has already been in the sequence appears again. | ||
|
||
For example, for x0 = 2 our answer would be 10 after the following sequence: | ||
|
||
x0 = 2 | ||
x1 = 2^2 = 4 | ||
x2 = 4^2 = 16 | ||
x3 = 1^2 + 6^2 = 37 | ||
x4 = 3^2 + 7^2 = 58 | ||
x5 = 5^2 + 8^2 = 89 | ||
x6 = 8^2 + 9^2 = 145 | ||
x7 = 1^2 + 4^2 + 5^2 = 42 | ||
x8 = 4^2 + 2^2 = 20 | ||
x9 = 2^2 + 0^2 = 4 | ||
Since we have already seen 4 in the sequence, we return the length of the sequence | ||
|
||
Write a function that accepts one argument (the first element)and returns the length of sequence |