Skip to content

Instantly share code, notes, and snippets.

View graphemecluster's full-sized avatar

graphemecluster graphemecluster

View GitHub Profile
@graphemecluster
graphemecluster / index.js
Created June 6, 2022 03:07
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