Skip to content

Instantly share code, notes, and snippets.

@graphemecluster
Created June 6, 2022 03:07
Show Gist options
  • Save graphemecluster/a2147fe9bc5c0eb976f0732034c94dc3 to your computer and use it in GitHub Desktop.
Save graphemecluster/a2147fe9bc5c0eb976f0732034c94dc3 to your computer and use it in GitHub Desktop.
Code Golf - Interval between two musical notes
f=c=>{for(s=0,i=0;c[i];i++){x=c.charCodeAt(i);s+=i?((x^3024)%3-1)*(((x&12)==8)+1)*7:(x+1&15)*2%7}return s},d=(l,r)=>("mmmmPPPMMMM"[(s=f(r)-f(l))+5]||(s<0?"d":"A").repeat(-~(s<0?-s:s)/7))+(((s*4%7)+7)%7+1)
// > d("B#","Fb")
// "ddd5"
// Supported characters:
// CDEFGABcdefgabCDEFGABcdefgab
// 𝄫♭bb♮♯##𝄪xx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment