The Note of Destiny - place a note on a staff
Ruby – 271 267 252 249 234 229 220 214 characters

I literally just learned Ruby for this. So there is certainly room for improvement in golfing it down. Or doing anything really. But I needed a language with mutable strings. :)



def f(n)s=[0]*20
s.fill{|i|i%2&gt;0?i&lt;3||i&gt;11?" ---":?-*5:" "*5}
s[l=(3-n[(p="H_L".index n[0])?1:0].ord)%7+7*(p||1)][1,2]=("#b"[n[-1]]||s[l][1])+?O
s[l+3-2*o=l&gt;7?3:1,3].map{|t|t[o]=?|}
puts s[[3,l].min..[11,l].max]end


Somewhat ungolfed:

def f(note)
  staff=[]
  0.step(20) {|i| staff[i] = " "*5}
  1.step(19,2) {|i| staff[i] = " ---"}
  3.step(11,2) {|i| staff[i] = "-"*5}
  level = 7
  if !(pos="HL".index note[i=0]).nil?
    level = 14*pos
    i += 1
  end
  level += (73-note[i].ord)%7
  staff[level][2] = "O"
  mark = note[-1]
  if !"#b".index(mark).nil?
    staff[level][1] = mark
  end
  offset = (level &gt; 7) ? 3 : 1
  staff[level-2*offset+3,3].map {|line| line[offset] = "|"}
  first = [3,level].min
  last = [11,level].max
  puts s[first..last]
end


I can cut it by another 2 characters down to 212 characters if leading blank lines are allowed. This solution doesn't fill the lines that aren't printed anyway:

def f(n)s=[]
[3,l=(3-n[(p="H_L".index n[0])?1:0].ord)%7+7*(p||1)].min.step(l&gt;11?l:11){|i|s[i]=i%2&gt;0?i&lt;3||i&gt;11?" ---":?-*5:" "*5}
s[l][1,2]=("#b"[n[-1]]||s[l][1])+?O
s[l+3-2*o=l&gt;7?3:1,3].map{|t|t[o]=?|}
puts s
end


Are lambda's fair game? Then I can get 210 characters with the first approach

f=-&gt;n{s=[0]*20
s.fill{|i|i%2&gt;0?i&lt;3||i&gt;11?" ---":?-*5:" "*5}
s[l=(3-n[(p="H_L".index n[0])?1:0].ord)%7+7*(p||1)][1,2]=("#b"[n[-1]]||s[l][1])+?O
s[l+3-2*o=l&gt;7?3:1,3].map{|t|t[o]=?|}
puts s[[3,l].min..[11,l].max]}


Or 207 characters with additional blank lines:

f=-&gt;n{s=[]
[3,l=(3-n[(p="H_L".index n[0])?1:0].ord)%7+7*(p||1)].min.step(l&gt;11?l:11){|i|s[i]=i%2&gt;0?i&lt;3||i&gt;11?" ---":?-*5:" "*5}
s[l][1,2]=("#b"[n[-1]]||s[l][1])+?O
s[l+3-2*o=l&gt;7?3:1,3].map{|t|t[o]=?|}
puts s}


Of course, now you'd need to do f.call("HGb").