Is this a Major Scale (or equivalent)?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












Sandbox



The major scale (or Ionian scale) is one of the most commonly used musical scales, especially in Western music. It is one of the diatonic scales. Like many musical scales, it is made up of seven notes: the eighth duplicates the first at double its frequency so that it is called a higher octave of the same note.



The seven musical notes are:




C, D, E, F, G, A, B, C (repeated for example purposes)




A major scale is a diatonic scale. Take the previous succession of notes as a major scale (Actually, It is the scale C Major). The sequence of intervals between the notes of a major scale is:




whole, whole, half, whole, whole, whole, half




where "whole" stands for a whole tone (a red u-shaped curve in the figure), and "half" stands for a semitone (a red broken line in the figure).



enter image description here



In this case, from C to D exist a whole tone, from D to E exist a whole tone, from E to F exist half tone, etc...



We have 2 components that affects the tone distance between notes. These are the Sharp symbol (♯) and the flat symbol (♭).



The Sharp symbol (♯) adds half tone to the note. Example. From C to D we mentioned that exists a whole tone, if we use C♯ instead C then from C♯ to D exists half tone.



The Flat symbol (♭) do the opposite of the Sharp symbol, it subtract half tone from the note. Example: From D to E we mentioned that exists a whole tone, if we use Db instead D then from Db to E exists a tone and a half.



By default, from Note to Note exist a whole tone except for E to F and B to C in where just half tone exists.



Note in some cases using enharmonic pitches can create an equivalent to a Major Scale. An example of this is C#, D#, E#, F#, G#, A#, B#, C# where E# and B# are enharmonic but the scale follows the sequence of a Major Scale.




Challenge



Given a scale, output a truthy value if it is a Major Scale or equivalent, otherwise output a falsey value.



Rules



  • Standard I/O method allowed

  • Standard code-golf rules apply

  • You don't need to take in consideration the 8th note. Assume the input will only consist of 7 notes

  • Assume double flat (♭♭), double sharp (♯♯) or natural sign (♮) don't exist


Test cases



C, D, E, F, G, A, B => true
C#, D#, E#, F#, G#, A#, B# => true
Db, Eb, F, Gb, Ab, Bb, C => true
D, E, Gb, G, A, Cb, C# => true
Eb, E#, G, G#, Bb, B#, D => true
-----------------------------------------------
C, D#, E, F, G, A, B => false
Db, Eb, F, Gb, Ab, B, C => false
G#, E, F, A, B, D#, C => false
C#, C#, E#, F#, G#, A#, B# => false
Eb, E#, Gb, G#, Bb, B#, D => false









share|improve this question





















  • So, E# is equal to F, and Cb equal to B?
    – Abigail
    1 hour ago










  • @Abigail Basically yes. They have the same tone although they are different notes.
    – Luis felipe De jesus Munoz
    1 hour ago










  • and conversely, Fb = E and B# = C.
    – Skidsdev
    1 hour ago














up vote
5
down vote

favorite












Sandbox



The major scale (or Ionian scale) is one of the most commonly used musical scales, especially in Western music. It is one of the diatonic scales. Like many musical scales, it is made up of seven notes: the eighth duplicates the first at double its frequency so that it is called a higher octave of the same note.



The seven musical notes are:




C, D, E, F, G, A, B, C (repeated for example purposes)




A major scale is a diatonic scale. Take the previous succession of notes as a major scale (Actually, It is the scale C Major). The sequence of intervals between the notes of a major scale is:




whole, whole, half, whole, whole, whole, half




where "whole" stands for a whole tone (a red u-shaped curve in the figure), and "half" stands for a semitone (a red broken line in the figure).



enter image description here



In this case, from C to D exist a whole tone, from D to E exist a whole tone, from E to F exist half tone, etc...



We have 2 components that affects the tone distance between notes. These are the Sharp symbol (♯) and the flat symbol (♭).



The Sharp symbol (♯) adds half tone to the note. Example. From C to D we mentioned that exists a whole tone, if we use C♯ instead C then from C♯ to D exists half tone.



The Flat symbol (♭) do the opposite of the Sharp symbol, it subtract half tone from the note. Example: From D to E we mentioned that exists a whole tone, if we use Db instead D then from Db to E exists a tone and a half.



By default, from Note to Note exist a whole tone except for E to F and B to C in where just half tone exists.



Note in some cases using enharmonic pitches can create an equivalent to a Major Scale. An example of this is C#, D#, E#, F#, G#, A#, B#, C# where E# and B# are enharmonic but the scale follows the sequence of a Major Scale.




Challenge



Given a scale, output a truthy value if it is a Major Scale or equivalent, otherwise output a falsey value.



Rules



  • Standard I/O method allowed

  • Standard code-golf rules apply

  • You don't need to take in consideration the 8th note. Assume the input will only consist of 7 notes

  • Assume double flat (♭♭), double sharp (♯♯) or natural sign (♮) don't exist


Test cases



C, D, E, F, G, A, B => true
C#, D#, E#, F#, G#, A#, B# => true
Db, Eb, F, Gb, Ab, Bb, C => true
D, E, Gb, G, A, Cb, C# => true
Eb, E#, G, G#, Bb, B#, D => true
-----------------------------------------------
C, D#, E, F, G, A, B => false
Db, Eb, F, Gb, Ab, B, C => false
G#, E, F, A, B, D#, C => false
C#, C#, E#, F#, G#, A#, B# => false
Eb, E#, Gb, G#, Bb, B#, D => false









share|improve this question





















  • So, E# is equal to F, and Cb equal to B?
    – Abigail
    1 hour ago










  • @Abigail Basically yes. They have the same tone although they are different notes.
    – Luis felipe De jesus Munoz
    1 hour ago










  • and conversely, Fb = E and B# = C.
    – Skidsdev
    1 hour ago












up vote
5
down vote

favorite









up vote
5
down vote

favorite











Sandbox



The major scale (or Ionian scale) is one of the most commonly used musical scales, especially in Western music. It is one of the diatonic scales. Like many musical scales, it is made up of seven notes: the eighth duplicates the first at double its frequency so that it is called a higher octave of the same note.



The seven musical notes are:




C, D, E, F, G, A, B, C (repeated for example purposes)




A major scale is a diatonic scale. Take the previous succession of notes as a major scale (Actually, It is the scale C Major). The sequence of intervals between the notes of a major scale is:




whole, whole, half, whole, whole, whole, half




where "whole" stands for a whole tone (a red u-shaped curve in the figure), and "half" stands for a semitone (a red broken line in the figure).



enter image description here



In this case, from C to D exist a whole tone, from D to E exist a whole tone, from E to F exist half tone, etc...



We have 2 components that affects the tone distance between notes. These are the Sharp symbol (♯) and the flat symbol (♭).



The Sharp symbol (♯) adds half tone to the note. Example. From C to D we mentioned that exists a whole tone, if we use C♯ instead C then from C♯ to D exists half tone.



The Flat symbol (♭) do the opposite of the Sharp symbol, it subtract half tone from the note. Example: From D to E we mentioned that exists a whole tone, if we use Db instead D then from Db to E exists a tone and a half.



By default, from Note to Note exist a whole tone except for E to F and B to C in where just half tone exists.



Note in some cases using enharmonic pitches can create an equivalent to a Major Scale. An example of this is C#, D#, E#, F#, G#, A#, B#, C# where E# and B# are enharmonic but the scale follows the sequence of a Major Scale.




Challenge



Given a scale, output a truthy value if it is a Major Scale or equivalent, otherwise output a falsey value.



Rules



  • Standard I/O method allowed

  • Standard code-golf rules apply

  • You don't need to take in consideration the 8th note. Assume the input will only consist of 7 notes

  • Assume double flat (♭♭), double sharp (♯♯) or natural sign (♮) don't exist


Test cases



C, D, E, F, G, A, B => true
C#, D#, E#, F#, G#, A#, B# => true
Db, Eb, F, Gb, Ab, Bb, C => true
D, E, Gb, G, A, Cb, C# => true
Eb, E#, G, G#, Bb, B#, D => true
-----------------------------------------------
C, D#, E, F, G, A, B => false
Db, Eb, F, Gb, Ab, B, C => false
G#, E, F, A, B, D#, C => false
C#, C#, E#, F#, G#, A#, B# => false
Eb, E#, Gb, G#, Bb, B#, D => false









share|improve this question













Sandbox



The major scale (or Ionian scale) is one of the most commonly used musical scales, especially in Western music. It is one of the diatonic scales. Like many musical scales, it is made up of seven notes: the eighth duplicates the first at double its frequency so that it is called a higher octave of the same note.



The seven musical notes are:




C, D, E, F, G, A, B, C (repeated for example purposes)




A major scale is a diatonic scale. Take the previous succession of notes as a major scale (Actually, It is the scale C Major). The sequence of intervals between the notes of a major scale is:




whole, whole, half, whole, whole, whole, half




where "whole" stands for a whole tone (a red u-shaped curve in the figure), and "half" stands for a semitone (a red broken line in the figure).



enter image description here



In this case, from C to D exist a whole tone, from D to E exist a whole tone, from E to F exist half tone, etc...



We have 2 components that affects the tone distance between notes. These are the Sharp symbol (♯) and the flat symbol (♭).



The Sharp symbol (♯) adds half tone to the note. Example. From C to D we mentioned that exists a whole tone, if we use C♯ instead C then from C♯ to D exists half tone.



The Flat symbol (♭) do the opposite of the Sharp symbol, it subtract half tone from the note. Example: From D to E we mentioned that exists a whole tone, if we use Db instead D then from Db to E exists a tone and a half.



By default, from Note to Note exist a whole tone except for E to F and B to C in where just half tone exists.



Note in some cases using enharmonic pitches can create an equivalent to a Major Scale. An example of this is C#, D#, E#, F#, G#, A#, B#, C# where E# and B# are enharmonic but the scale follows the sequence of a Major Scale.




Challenge



Given a scale, output a truthy value if it is a Major Scale or equivalent, otherwise output a falsey value.



Rules



  • Standard I/O method allowed

  • Standard code-golf rules apply

  • You don't need to take in consideration the 8th note. Assume the input will only consist of 7 notes

  • Assume double flat (♭♭), double sharp (♯♯) or natural sign (♮) don't exist


Test cases



C, D, E, F, G, A, B => true
C#, D#, E#, F#, G#, A#, B# => true
Db, Eb, F, Gb, Ab, Bb, C => true
D, E, Gb, G, A, Cb, C# => true
Eb, E#, G, G#, Bb, B#, D => true
-----------------------------------------------
C, D#, E, F, G, A, B => false
Db, Eb, F, Gb, Ab, B, C => false
G#, E, F, A, B, D#, C => false
C#, C#, E#, F#, G#, A#, B# => false
Eb, E#, Gb, G#, Bb, B#, D => false






code-golf music






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 hours ago









Luis felipe De jesus Munoz

3,57811049




3,57811049











  • So, E# is equal to F, and Cb equal to B?
    – Abigail
    1 hour ago










  • @Abigail Basically yes. They have the same tone although they are different notes.
    – Luis felipe De jesus Munoz
    1 hour ago










  • and conversely, Fb = E and B# = C.
    – Skidsdev
    1 hour ago
















  • So, E# is equal to F, and Cb equal to B?
    – Abigail
    1 hour ago










  • @Abigail Basically yes. They have the same tone although they are different notes.
    – Luis felipe De jesus Munoz
    1 hour ago










  • and conversely, Fb = E and B# = C.
    – Skidsdev
    1 hour ago















So, E# is equal to F, and Cb equal to B?
– Abigail
1 hour ago




So, E# is equal to F, and Cb equal to B?
– Abigail
1 hour ago












@Abigail Basically yes. They have the same tone although they are different notes.
– Luis felipe De jesus Munoz
1 hour ago




@Abigail Basically yes. They have the same tone although they are different notes.
– Luis felipe De jesus Munoz
1 hour ago












and conversely, Fb = E and B# = C.
– Skidsdev
1 hour ago




and conversely, Fb = E and B# = C.
– Skidsdev
1 hour ago










3 Answers
3






active

oldest

votes

















up vote
3
down vote














Perl 6, 76 68 bytes





:12[(.[1..*]Z-$_)X%12]==541178o*>>.&0+?/#/-?/b/


Try it online!



Explanation



*>>.& ... # Map notes to integers
1.6*.ord-103.3 # A=0.7 B=2.3 C=3.9 D=5.5 E=7.1 F=8.7 G=10.3
+|0 # Remove fractional part
-:1[<C F>Xle$_] # Subtract 1 if note >= C or note >= F
+?/#/ # Add 1 for '#'
-?/b/ # Subtract 1 for 'b'

o # Compose with block
(.[1..*]Z-$_) # Pairwise difference
X%12 # modulo 12
:12[ ] # Convert from base-12
==541178 # Equals 221222 in base-12?





share|improve this answer





























    up vote
    2
    down vote














    JavaScript (Node.js), 150 131 bytes





    l=>(l=l.map(x=>[...'C0D0EF0G0A0B'].indexOf(x[0])+(x[1]=='#'|-(x[1]=='b')))).slice(1).map((n,i)=>(b=n-l[i])<0?2:b)+""=='2,2,1,2,2,2'


    Try it online!



    -19 bytes thanks to Luis felipe



    Ungolfed:



    function isMajor(l) 
    // Get tone index of each entry
    let array = l.map(function (x) -(x[1]=='b');
    );
    // Calculate deltas
    let deltas = array.slice(1).map(function (n,i)
    // If delta is negative, replace it with 2
    // This accounts for octaves
    if (n - array[i] < 0) return 2;
    // Otherwise return the delta
    return n - array[i];
    );
    // Pseudo array-comparison
    return deltas+"" == '2,2,1,2,2,2';






    share|improve this answer


















    • 1




      [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
      – Luis felipe De jesus Munoz
      49 mins ago










    • x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
      – Luis felipe De jesus Munoz
      47 mins ago











    • @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
      – Skidsdev
      42 mins ago

















    up vote
    2
    down vote














    Dart, 210 bytes



    f(l)var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];for(;++i<7;j+='$(y[0]-y[1])%12')for(k=0;k<2;k++)y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);return'221222'==j;


    Try it online!



    Ungolfed:



    f(l)
    var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];
    for(;++i<7;j+='$(y[0]-y[1])%12')
    for(k=0;k<2;k++)
    y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);

    return'221222'==j;



    A whole step is 2, a quarter is 1. Mod 12 in case you jump to a higher octave.
    Iterates through all notes and computes the difference between the ith note and the i-1th note.
    Concatenates the result and should expect 221222 (2 whole, 1 half, 3 wholes).



    • -2 bytes by not assigning 0 to k

    • -4 bytes by using j as a String and not a List

    • -6 bytes thanks to @Kevin Cruijssen by removing unnecessary clutter in loops





    share|improve this answer






















    • I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
      – Kevin Cruijssen
      23 mins ago











    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "200"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175516%2fis-this-a-major-scale-or-equivalent%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote














    Perl 6, 76 68 bytes





    :12[(.[1..*]Z-$_)X%12]==541178o*>>.&0+?/#/-?/b/


    Try it online!



    Explanation



    *>>.& ... # Map notes to integers
    1.6*.ord-103.3 # A=0.7 B=2.3 C=3.9 D=5.5 E=7.1 F=8.7 G=10.3
    +|0 # Remove fractional part
    -:1[<C F>Xle$_] # Subtract 1 if note >= C or note >= F
    +?/#/ # Add 1 for '#'
    -?/b/ # Subtract 1 for 'b'

    o # Compose with block
    (.[1..*]Z-$_) # Pairwise difference
    X%12 # modulo 12
    :12[ ] # Convert from base-12
    ==541178 # Equals 221222 in base-12?





    share|improve this answer


























      up vote
      3
      down vote














      Perl 6, 76 68 bytes





      :12[(.[1..*]Z-$_)X%12]==541178o*>>.&0+?/#/-?/b/


      Try it online!



      Explanation



      *>>.& ... # Map notes to integers
      1.6*.ord-103.3 # A=0.7 B=2.3 C=3.9 D=5.5 E=7.1 F=8.7 G=10.3
      +|0 # Remove fractional part
      -:1[<C F>Xle$_] # Subtract 1 if note >= C or note >= F
      +?/#/ # Add 1 for '#'
      -?/b/ # Subtract 1 for 'b'

      o # Compose with block
      (.[1..*]Z-$_) # Pairwise difference
      X%12 # modulo 12
      :12[ ] # Convert from base-12
      ==541178 # Equals 221222 in base-12?





      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote










        Perl 6, 76 68 bytes





        :12[(.[1..*]Z-$_)X%12]==541178o*>>.&0+?/#/-?/b/


        Try it online!



        Explanation



        *>>.& ... # Map notes to integers
        1.6*.ord-103.3 # A=0.7 B=2.3 C=3.9 D=5.5 E=7.1 F=8.7 G=10.3
        +|0 # Remove fractional part
        -:1[<C F>Xle$_] # Subtract 1 if note >= C or note >= F
        +?/#/ # Add 1 for '#'
        -?/b/ # Subtract 1 for 'b'

        o # Compose with block
        (.[1..*]Z-$_) # Pairwise difference
        X%12 # modulo 12
        :12[ ] # Convert from base-12
        ==541178 # Equals 221222 in base-12?





        share|improve this answer















        Perl 6, 76 68 bytes





        :12[(.[1..*]Z-$_)X%12]==541178o*>>.&0+?/#/-?/b/


        Try it online!



        Explanation



        *>>.& ... # Map notes to integers
        1.6*.ord-103.3 # A=0.7 B=2.3 C=3.9 D=5.5 E=7.1 F=8.7 G=10.3
        +|0 # Remove fractional part
        -:1[<C F>Xle$_] # Subtract 1 if note >= C or note >= F
        +?/#/ # Add 1 for '#'
        -?/b/ # Subtract 1 for 'b'

        o # Compose with block
        (.[1..*]Z-$_) # Pairwise difference
        X%12 # modulo 12
        :12[ ] # Convert from base-12
        ==541178 # Equals 221222 in base-12?






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 15 mins ago

























        answered 54 mins ago









        nwellnhof

        5,438920




        5,438920




















            up vote
            2
            down vote














            JavaScript (Node.js), 150 131 bytes





            l=>(l=l.map(x=>[...'C0D0EF0G0A0B'].indexOf(x[0])+(x[1]=='#'|-(x[1]=='b')))).slice(1).map((n,i)=>(b=n-l[i])<0?2:b)+""=='2,2,1,2,2,2'


            Try it online!



            -19 bytes thanks to Luis felipe



            Ungolfed:



            function isMajor(l) 
            // Get tone index of each entry
            let array = l.map(function (x) -(x[1]=='b');
            );
            // Calculate deltas
            let deltas = array.slice(1).map(function (n,i)
            // If delta is negative, replace it with 2
            // This accounts for octaves
            if (n - array[i] < 0) return 2;
            // Otherwise return the delta
            return n - array[i];
            );
            // Pseudo array-comparison
            return deltas+"" == '2,2,1,2,2,2';






            share|improve this answer


















            • 1




              [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
              – Luis felipe De jesus Munoz
              49 mins ago










            • x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
              – Luis felipe De jesus Munoz
              47 mins ago











            • @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
              – Skidsdev
              42 mins ago














            up vote
            2
            down vote














            JavaScript (Node.js), 150 131 bytes





            l=>(l=l.map(x=>[...'C0D0EF0G0A0B'].indexOf(x[0])+(x[1]=='#'|-(x[1]=='b')))).slice(1).map((n,i)=>(b=n-l[i])<0?2:b)+""=='2,2,1,2,2,2'


            Try it online!



            -19 bytes thanks to Luis felipe



            Ungolfed:



            function isMajor(l) 
            // Get tone index of each entry
            let array = l.map(function (x) -(x[1]=='b');
            );
            // Calculate deltas
            let deltas = array.slice(1).map(function (n,i)
            // If delta is negative, replace it with 2
            // This accounts for octaves
            if (n - array[i] < 0) return 2;
            // Otherwise return the delta
            return n - array[i];
            );
            // Pseudo array-comparison
            return deltas+"" == '2,2,1,2,2,2';






            share|improve this answer


















            • 1




              [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
              – Luis felipe De jesus Munoz
              49 mins ago










            • x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
              – Luis felipe De jesus Munoz
              47 mins ago











            • @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
              – Skidsdev
              42 mins ago












            up vote
            2
            down vote










            up vote
            2
            down vote










            JavaScript (Node.js), 150 131 bytes





            l=>(l=l.map(x=>[...'C0D0EF0G0A0B'].indexOf(x[0])+(x[1]=='#'|-(x[1]=='b')))).slice(1).map((n,i)=>(b=n-l[i])<0?2:b)+""=='2,2,1,2,2,2'


            Try it online!



            -19 bytes thanks to Luis felipe



            Ungolfed:



            function isMajor(l) 
            // Get tone index of each entry
            let array = l.map(function (x) -(x[1]=='b');
            );
            // Calculate deltas
            let deltas = array.slice(1).map(function (n,i)
            // If delta is negative, replace it with 2
            // This accounts for octaves
            if (n - array[i] < 0) return 2;
            // Otherwise return the delta
            return n - array[i];
            );
            // Pseudo array-comparison
            return deltas+"" == '2,2,1,2,2,2';






            share|improve this answer















            JavaScript (Node.js), 150 131 bytes





            l=>(l=l.map(x=>[...'C0D0EF0G0A0B'].indexOf(x[0])+(x[1]=='#'|-(x[1]=='b')))).slice(1).map((n,i)=>(b=n-l[i])<0?2:b)+""=='2,2,1,2,2,2'


            Try it online!



            -19 bytes thanks to Luis felipe



            Ungolfed:



            function isMajor(l) 
            // Get tone index of each entry
            let array = l.map(function (x) -(x[1]=='b');
            );
            // Calculate deltas
            let deltas = array.slice(1).map(function (n,i)
            // If delta is negative, replace it with 2
            // This accounts for octaves
            if (n - array[i] < 0) return 2;
            // Otherwise return the delta
            return n - array[i];
            );
            // Pseudo array-comparison
            return deltas+"" == '2,2,1,2,2,2';







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 35 mins ago

























            answered 53 mins ago









            Skidsdev

            5,8732664




            5,8732664







            • 1




              [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
              – Luis felipe De jesus Munoz
              49 mins ago










            • x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
              – Luis felipe De jesus Munoz
              47 mins ago











            • @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
              – Skidsdev
              42 mins ago












            • 1




              [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
              – Luis felipe De jesus Munoz
              49 mins ago










            • x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
              – Luis felipe De jesus Munoz
              47 mins ago











            • @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
              – Skidsdev
              42 mins ago







            1




            1




            [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
            – Luis felipe De jesus Munoz
            49 mins ago




            [...'C0D0EF0G0A0B'] instead of 'C0D0EF0G0A0B'.split('') and +"" instead of .toString() to save some bytes
            – Luis felipe De jesus Munoz
            49 mins ago












            x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
            – Luis felipe De jesus Munoz
            47 mins ago





            x[1]=='#'|-(x[1]=='b') instead of x[1]=='#'?1:(x[1]=='b'?-1:0) save some bytes too
            – Luis felipe De jesus Munoz
            47 mins ago













            @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
            – Skidsdev
            42 mins ago




            @LuisfelipeDejesusMunoz Oh nice thanks! I can't believe I forgot about array expansion and adding an empty string
            – Skidsdev
            42 mins ago










            up vote
            2
            down vote














            Dart, 210 bytes



            f(l)var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];for(;++i<7;j+='$(y[0]-y[1])%12')for(k=0;k<2;k++)y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);return'221222'==j;


            Try it online!



            Ungolfed:



            f(l)
            var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];
            for(;++i<7;j+='$(y[0]-y[1])%12')
            for(k=0;k<2;k++)
            y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);

            return'221222'==j;



            A whole step is 2, a quarter is 1. Mod 12 in case you jump to a higher octave.
            Iterates through all notes and computes the difference between the ith note and the i-1th note.
            Concatenates the result and should expect 221222 (2 whole, 1 half, 3 wholes).



            • -2 bytes by not assigning 0 to k

            • -4 bytes by using j as a String and not a List

            • -6 bytes thanks to @Kevin Cruijssen by removing unnecessary clutter in loops





            share|improve this answer






















            • I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
              – Kevin Cruijssen
              23 mins ago















            up vote
            2
            down vote














            Dart, 210 bytes



            f(l)var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];for(;++i<7;j+='$(y[0]-y[1])%12')for(k=0;k<2;k++)y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);return'221222'==j;


            Try it online!



            Ungolfed:



            f(l)
            var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];
            for(;++i<7;j+='$(y[0]-y[1])%12')
            for(k=0;k<2;k++)
            y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);

            return'221222'==j;



            A whole step is 2, a quarter is 1. Mod 12 in case you jump to a higher octave.
            Iterates through all notes and computes the difference between the ith note and the i-1th note.
            Concatenates the result and should expect 221222 (2 whole, 1 half, 3 wholes).



            • -2 bytes by not assigning 0 to k

            • -4 bytes by using j as a String and not a List

            • -6 bytes thanks to @Kevin Cruijssen by removing unnecessary clutter in loops





            share|improve this answer






















            • I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
              – Kevin Cruijssen
              23 mins ago













            up vote
            2
            down vote










            up vote
            2
            down vote










            Dart, 210 bytes



            f(l)var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];for(;++i<7;j+='$(y[0]-y[1])%12')for(k=0;k<2;k++)y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);return'221222'==j;


            Try it online!



            Ungolfed:



            f(l)
            var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];
            for(;++i<7;j+='$(y[0]-y[1])%12')
            for(k=0;k<2;k++)
            y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);

            return'221222'==j;



            A whole step is 2, a quarter is 1. Mod 12 in case you jump to a higher octave.
            Iterates through all notes and computes the difference between the ith note and the i-1th note.
            Concatenates the result and should expect 221222 (2 whole, 1 half, 3 wholes).



            • -2 bytes by not assigning 0 to k

            • -4 bytes by using j as a String and not a List

            • -6 bytes thanks to @Kevin Cruijssen by removing unnecessary clutter in loops





            share|improve this answer















            Dart, 210 bytes



            f(l)var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];for(;++i<7;j+='$(y[0]-y[1])%12')for(k=0;k<2;k++)y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);return'221222'==j;


            Try it online!



            Ungolfed:



            f(l)
            var i=0,k=0,n='C':0,'D':2,'E':4,'F':5,'G':7,'A':9,'B':11,'b':-1,'#':1,j='',y=[0,0];
            for(;++i<7;j+='$(y[0]-y[1])%12')
            for(k=0;k<2;k++)
            y[k]=n[l[i-k][0]]+(l[i-k].length>1?n[l[i-k][1]]:0);

            return'221222'==j;



            A whole step is 2, a quarter is 1. Mod 12 in case you jump to a higher octave.
            Iterates through all notes and computes the difference between the ith note and the i-1th note.
            Concatenates the result and should expect 221222 (2 whole, 1 half, 3 wholes).



            • -2 bytes by not assigning 0 to k

            • -4 bytes by using j as a String and not a List

            • -6 bytes thanks to @Kevin Cruijssen by removing unnecessary clutter in loops






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 10 mins ago

























            answered 47 mins ago









            Elcan

            1914




            1914











            • I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
              – Kevin Cruijssen
              23 mins ago

















            • I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
              – Kevin Cruijssen
              23 mins ago
















            I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
            – Kevin Cruijssen
            23 mins ago





            I don't know Dart, but parts are similar as Java. Therefore: changing i=1 to i=0 can reduce a byte by changing for(;i<7;i++) to for(;++i<7;). In addition, the brackets can be removed around that loop, by putting the j+=... inside the third part of the loop: for(;++i<7;j+='$(y[0]-y[1])%12'). And one last thing is changing return j=='221222'; to return'221222'==j; to get rid of the space. -6 (210 bytes) after these modifications.
            – Kevin Cruijssen
            23 mins ago


















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175516%2fis-this-a-major-scale-or-equivalent%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            One-line joke