6 kyu

Integer to Musical Pitch Classes

43 of 114craecke

Description:

(First in this series: http://www.codewars.com/kata/musical-pitch-classes)

This kata is the inverse of the previous one: you must write a method to_pitch_class that, when given an integer representing a musical pitch class, returns an array of every name for that note.

There are only twelve pitch classes (which are cyclical, e.g., the note above number 11 is number 0), and the numerical values of the natural notes are as follows:

C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11

A sharp ("♯") raises a note by one, and a flat ("♭") lowers it by one. For this kata, we'll also be using the double sharp and the double flat, which are exactly what they sound like: the double sharp raises a pitch by two, and the double flat lowers a pitch by two. Since Codewars doesn't allow the characters for sharp, flat, double sharp, and double flat, we'll use the strings "#", "b", "x", and "bb" instead.

Some examples:

to_pitch_class(2) # - > should return ['D', 'Cx', 'Ebb']

to_pitch_class(10) # -> should return ['A#', 'Bb', 'Cbb']
toPitchClass(2) // - > should return ['D', 'Cx', 'Ebb']

toPitchClass(10) // -> should return ['A#', 'Bb', 'Cbb']

The order of the returned array doesn't matter.

Algorithms

More By Author:

Check out these other kata created by craecke

Stats:

CreatedFeb 9, 2015
PublishedFeb 9, 2015
Warriors Trained239
Total Skips51
Total Code Submissions582
Total Times Completed114
Ruby Completions43
JavaScript Completions80
Total Stars9
% of votes with a positive feedback rating90% of 47
Total "Very Satisfied" Votes38
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes0
Total Rank Assessments15
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • craecke Avatar
  • jhoffner Avatar
  • ZozoFouchtra Avatar
  • smile67 Avatar
Ad