Write a function that takes a list of 12 UNIQUE numbers, ranging from 0 to 11. Find the interval difference of each step, and reverse the interval in the new set.
If the number is less than 0, it should wrap around. For example, if -1, then 11. If -2, then 10.
Also if the number is greater than 11, the number should be subtracted by 12.
The first number in the new set should be the same as the original set.
For example:
[7, 6, 4, 3, 1, 11, 10, 0, 9, 8, 2, 5] should return [7, 8, 10, 11, 1, 3, 4, 2, 5, 6, 0, 9]
(I'm having a hard time putting the description into words that make this seem completely independent to music. Knowing and understand music theory would make this a lot easier to understand)
def invert(testset):
base12 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
invset = [(testset[0])]
for s in range(len(testset)-1):
interval = testset[s] - testset[s+1]
if s == 0:
inv_val = testset[s] + interval
if inv_val > 11:
inv_val = inv_val - 12
else:
inv_val += interval
if inv_val > 11:
inv_val = inv_val - 12
if inv_val < 0:
inv_abs = base12[inv_val]
else:
inv_abs = inv_val
invset.append(inv_abs)
return(invset)
# TODO: Replace examples and use TDD development by writing your own tests
# These are some of the methods available:
# test.expect(boolean, [optional] message)
# test.assert_equals(actual, expected, [optional] message)
# test.assert_not_equals(actual, expected, [optional] message)
# You can use Test.describe and Test.it to write BDD style test groupings
test.assert_equals(invert([7, 6, 4, 3, 1, 11, 10, 0, 9, 8, 2, 5]), [7, 8, 10, 11, 1, 3, 4, 2, 5, 6, 0, 9])
test.assert_equals(invert([0, 2, 4, 1, 3, 7, 8, 11, 10, 5, 6, 9]), [0, 10, 8, 11, 9, 5, 4, 1, 2, 7, 6, 3])
test.assert_equals(invert([9, 4, 5, 11, 3, 10, 8, 0, 7, 2, 6, 1]), [9, 2, 1, 7, 3, 8, 10, 6, 11, 4, 0, 5])
test.assert_equals(invert([1, 6, 10, 4, 11, 3, 8, 7, 2, 0, 5, 9]), [1, 8, 4, 10, 3, 11, 6, 7, 0, 2, 9 ,5])
test.assert_equals(invert([8, 4, 6, 2, 7, 10, 11, 1, 9, 5, 3, 0]), [8, 0, 10, 2, 9, 6, 5, 3, 7, 11, 1, 4])
test.assert_equals(invert([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]), [0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1])
test.assert_equals(invert([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]), [11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])