Checking My Work On Eight Tone Scales

My calculations on Eight Tone Scales was way too manually intensive for me to trust that I got it right. I should check my work.

  • generate the set of all strings of intervals of length 8.
    1. Generate an array of length 8 and populate it with all 1’s except the first value, which gets a 0.
    2. increment each digit. If the digit goes over five, overflow to the next digit. If the last digit overflows, we are done.
    3. Sum the digits. If they don’t add up to 8, throw it out
  • Convert them to a canonical form. We can make an array of 8 digits into an eight digit integer. Take the highest valued integer for each mode of the scale.
    1. Convert the digits into a single eight digit integer.
    2. Rotate the array by one and convert it to an 8 digit number.
    3. Compare the results of the previous two steps and keep the higher value.
    4. Repeat until we’ve rotated through all values in the array.
  • Put them into a Set which will only contain unique values to remove duplicates.
  • Sort the set
  •  

    Since I am moving on to a Python Project, I figured I’d code it up in python.

    #!/usr/bin/python
    
    
    def increment(intervals, index):
        if index >= len(intervals):
            return False
        intervals[index] += 1
        if intervals[index] > 5:
            intervals[index] = 1
            return increment(intervals, index + 1)
        return True
    
    def sums_to(intervals, sum):
        total = 0
        for val in intervals:
            total += val
        return sum == total
            
    def int_form(intervals):
        value = 0
        for digit in intervals:
            value *= 10
            value += digit
        return value
    
    def rotate(intervals):
        l = intervals[:]
        n = len(l) - 1
        head = l[:n]
        l[:n] = []
        l.extend(head)
        return l
    
        
    def max_int_form(intervals):
        copy_of = intervals[:]
        max = 0
        for digit in intervals:
            next_int_form = int_form(copy_of)
            if next_int_form > max:
                max = next_int_form
            copy_of = rotate(copy_of)
        return max
    
    
    
    
    intervals = [ 0, 1, 1, 1, 1, 1, 1, 1]
    scale_set = set()
    count = 0
    while increment (intervals,0):
        if sums_to(intervals, 12):
            scale_set.add(max_int_form(intervals))
    scales = list(scale_set)
    scales.sort()
    
    for scale in scales:
        count += 1
        print scale
    print count ," Scales generated"
    
    

    And the Output:

    [ayoung@ayoung python]$ ./eightone.py 
    21212121
    22112121
    22112211
    22121121
    22121211
    22122111
    22211121
    22211211
    22212111
    22221111
    31111122
    31111212
    31111221
    31112112
    31112121
    31112211
    31113111
    31121112
    31121121
    31121211
    31122111
    31131111
    31211112
    31211121
    31211211
    31212111
    31221111
    31311111
    32111112
    32111121
    32111211
    32112111
    32121111
    32211111
    33111111
    41111112
    41111121
    41111211
    41112111
    41121111
    41211111
    42111111
    51111111
    43  Scales generated
    

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.