Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The following solution defines a function to transpose each scale taking advantage of the mathematical properties of notes:

    def notes_name(numbers):
        notes = "C C# D D# E F F# G G# A A# B".split()
        return [notes[(number % 12)] for number in numbers]
    
    def transposition(notes, start):
        index = start - notes[0]
        return [(n + index) % 12 for n in notes]
    
    def gen_scales():
        c_scale = [0, 2, 4, 5, 7, 9, 11]
        return [notes_name(transposition(c_scale, note)) for note in range(0, 12)]
    
    for scale in gen_scales():
        print " ".join(scale)
EDIT: make the code prettier


A trick to generate a cycle of fourths or fifths is to multiply a chromatic scale by 5 or 7, respectively:

    notes_name([n*7 for n in range(0, 12)])


This is rad, thanks for that.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: