# Note span (whole, quarter, eighth, sixteenth, thirty-second spans = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # Note tone notes = Array.new(20) # Tones for each line in the input tones = ['B', 'A', 'G', 'F','E','D','C','B','A','G','F','E'] # Counter for tones array t=0 IO.foreach('../input.txt') { |line| # Counter for notes array i=0 begin # Grab the chars for the note and flag columns n = line[i*4+1] m = line[i*4] # If flag, there may be more, add 7 spans[i] += 7 if n == ?\\ # If bar, add 1 if flag (to make 8) or if we didn't already see a flag spans[i] += 1 if m == ?| && (n == ?\\ || spans[i] < 8) # Add 1 if whole or quarter note and set the tone for the note if m == ?o spans[i] += 1 if spans[i] < 4 notes[i] = tones[t] end i += 1 end until i >= line.size t += 1 } str = '' n=0 spans.each { |i| # If 0, no more notes break if i == 0 # 32'nd note only has 3 flags, fix here i += 8 if i == 24 # Build note string str << notes[n] str << '\\' << i.to_s if i > 1 str << ' ' n += 1 } puts str.rstrip