Is this a Major Scale (or equivalent)?
Clash 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).
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
add a comment |Â
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).
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
So,E#
is equal toF
, andCb
equal toB
?
– 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
andB# = C
.
– Skidsdev
1 hour ago
add a comment |Â
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).
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
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).
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
code-golf music
asked 2 hours ago


Luis felipe De jesus Munoz
3,57811049
3,57811049
So,E#
is equal toF
, andCb
equal toB
?
– 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
andB# = C
.
– Skidsdev
1 hour ago
add a comment |Â
So,E#
is equal toF
, andCb
equal toB
?
– 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
andB# = 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
add a comment |Â
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?
add a comment |Â
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';
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 ofx[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
add a comment |Â
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
I don't know Dart, but parts are similar as Java. Therefore: changingi=1
toi=0
can reduce a byte by changingfor(;i<7;i++)
tofor(;++i<7;)
. In addition, the bracketscan 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 changingreturn j=='221222';
toreturn'221222'==j;
to get rid of the space. -6 (210 bytes) after these modifications.
– Kevin Cruijssen
23 mins ago
add a comment |Â
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?
add a comment |Â
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?
add a comment |Â
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?
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?
edited 15 mins ago
answered 54 mins ago
nwellnhof
5,438920
5,438920
add a comment |Â
add a comment |Â
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';
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 ofx[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
add a comment |Â
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';
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 ofx[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
add a comment |Â
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';
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';
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 ofx[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
add a comment |Â
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 ofx[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
add a comment |Â
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
I don't know Dart, but parts are similar as Java. Therefore: changingi=1
toi=0
can reduce a byte by changingfor(;i<7;i++)
tofor(;++i<7;)
. In addition, the bracketscan 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 changingreturn j=='221222';
toreturn'221222'==j;
to get rid of the space. -6 (210 bytes) after these modifications.
– Kevin Cruijssen
23 mins ago
add a comment |Â
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
I don't know Dart, but parts are similar as Java. Therefore: changingi=1
toi=0
can reduce a byte by changingfor(;i<7;i++)
tofor(;++i<7;)
. In addition, the bracketscan 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 changingreturn j=='221222';
toreturn'221222'==j;
to get rid of the space. -6 (210 bytes) after these modifications.
– Kevin Cruijssen
23 mins ago
add a comment |Â
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
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
edited 10 mins ago
answered 47 mins ago
Elcan
1914
1914
I don't know Dart, but parts are similar as Java. Therefore: changingi=1
toi=0
can reduce a byte by changingfor(;i<7;i++)
tofor(;++i<7;)
. In addition, the bracketscan 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 changingreturn j=='221222';
toreturn'221222'==j;
to get rid of the space. -6 (210 bytes) after these modifications.
– Kevin Cruijssen
23 mins ago
add a comment |Â
I don't know Dart, but parts are similar as Java. Therefore: changingi=1
toi=0
can reduce a byte by changingfor(;i<7;i++)
tofor(;++i<7;)
. In addition, the bracketscan 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 changingreturn j=='221222';
toreturn'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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
So,
E#
is equal toF
, andCb
equal toB
?– 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
andB# = C
.– Skidsdev
1 hour ago