Skip to main content
deleted 1 character in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Batch, 136136 135 bytes

@set/ac=0,d=2,e=4,f=5,g=7,a=9,r=-23r=24 @call:c %2 :c @set s=%1 @set s=%s:b=-1% @set/ar=%s:#=+1%-r @if not "%2"=="" cmd/cset/aa13-r%%12+2r%%12 

Explanation: The substitutions in the c subroutine replace # in the note name with +1 and b with -1. As this is case insensitive, Bb becomes -1-1. The variables for C...A (also case insensitive) are therefore chosen to be the appropriate number of semitones away from B=-1. The resulting string is then evaluated, and @xnor's trick of subtracting the result from the value gives the desired effect of subtracting the note values from each other. As Batch's % is not a true moduloEdit: Finally I have to use a bias value of -23 instead@Arnauld's trick of 1subtracting the modulo from 13 to ensureachieve the result is always positivedesired answer, saving 1 byte.

Batch, 136 bytes

@set/ac=0,d=2,e=4,f=5,g=7,a=9,r=-23 @call:c %2 :c @set s=%1 @set s=%s:b=-1% @set/ar=%s:#=+1%-r @if not "%2"=="" cmd/cset/a-r%%12+2 

Explanation: The substitutions in the c subroutine replace # in the note name with +1 and b with -1. As this is case insensitive, Bb becomes -1-1. The variables for C...A (also case insensitive) are therefore chosen to be the appropriate number of semitones away from B=-1. The resulting string is then evaluated, and @xnor's trick of subtracting the result from the value gives the desired effect of subtracting the note values from each other. As Batch's % is not a true modulo I have to use a bias value of -23 instead of 1 to ensure the result is always positive.

Batch, 136 135 bytes

@set/ac=0,d=2,e=4,f=5,g=7,a=9,r=24 @call:c %2 :c @set s=%1 @set s=%s:b=-1% @set/ar=%s:#=+1%-r @if not "%2"=="" cmd/cset/a13-r%%12 

Explanation: The substitutions in the c subroutine replace # in the note name with +1 and b with -1. As this is case insensitive, Bb becomes -1-1. The variables for C...A (also case insensitive) are therefore chosen to be the appropriate number of semitones away from B=-1. The resulting string is then evaluated, and @xnor's trick of subtracting the result from the value gives the desired effect of subtracting the note values from each other. Edit: Finally I use @Arnauld's trick of subtracting the modulo from 13 to achieve the desired answer, saving 1 byte.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Batch, 136 bytes

@set/ac=0,d=2,e=4,f=5,g=7,a=9,r=-23 @call:c %2 :c @set s=%1 @set s=%s:b=-1% @set/ar=%s:#=+1%-r @if not "%2"=="" cmd/cset/a-r%%12+2 

Explanation: The substitutions in the c subroutine replace # in the note name with +1 and b with -1. As this is case insensitive, Bb becomes -1-1. The variables for C...A (also case insensitive) are therefore chosen to be the appropriate number of semitones away from B=-1. The resulting string is then evaluated, and @xnor's trick of subtracting the result from the value gives the desired effect of subtracting the note values from each other. As Batch's % is not a true modulo I have to use a bias value of -23 instead of 1 to ensure the result is always positive.