11
3
Given an ascii musical score, you must be able to output the note and its corresponding length. The score will contain between 5 and 15 notes inclusive, and is transcribed on a stave. A stave is made up of five horizontal lines comprising of - (minus) characters separated by lines of spaces. The bottom line in the stave is equivalent to the note 'E'. The line of spaces immediately above the bottom line indicates an 'F', and is of a higher pitch that the 'E' below it. This continues as below. Note that notes only go up to 'G' before starting again at 'A'. See below:
F ----------
E
D ----------
C
B ----------
A
G ----------
F
E ----------
Note that the letters aren't included in the input. The notes are superimposed on top of the stave using a o (lowercase ooh) character to indicate the 'note head'. This note head indicates the frequency of the note, and therefore the alphabetic representation of it as above. For example, a note placed on the score as below indicates an 'A' :
----
----
----
o
----
----
A note, like the 'A' above, is called a 'whole note' and would be played for one whole beat. Other durations can be indicated by including a 'stem' rising from the note, and between zero and three 'flags'. A stem is made up of three | (pipe, or vertical bar) characters stacked immediately above the note head . A stem with no flags is considered a 'quarter-note', and plays for quarter of a beat. Flags are \ (backslash) characters, and hand on the right hand side of the stem. Each stem halves the time the note is played for. The length of each note will be one of the following: a whole note, a quarter note, an eighth note, a sixteenth note or a thirty-second note. This how each type of note would look for A :
--------------------
----|---|\--|\--|\--
| | |\ |\
----|---|---|---|\--
o o o o o
--------------------
--------------------
Putting more than one note together gives you a score. Each note can be considered to be four characters wide, with a note being in the first column of each four-character block. For example :
|\
----|\--|\----------
|\ | |\
----o---|---o---|\--
| o |
|---------------o---
|
o-------------------
--------------------
The example above contains the following notes, in order: a quarter note 'G', a thirty-second note 'D', an eighth note 'C', a whole note 'D' and a sixteenth note 'B'. Each note in your output should be in the format letter/length, where letter is A-G and length is the fraction of the note's length when compared to a whole note. As an exception, the length and / character should not be printed if the note is a whole note. Each note in your output should be separated by a single space. Therefore, for the score above, your code should output the following:
G/4 D/32 C/8 D B/16
- The notes will be in the following range: E F G A B C D E F. Note that only the letter needs to be printed, the octave is ignored.
- Note that the number of lines of input varies from 9 to 12, since notes with quarter time or less on line D or higher will require more lines to show completely.
- There is no half-note in this case.
Shortest code wins (whitespace doesn't count).
Edit: Fixed error in spacing in one input.
Some sample inputs:
|\
----|\--|-------------------
|\ | |
|---|---o---------------o---
| o |\
o---------------|\--|\------
|\ |\ |\
------------|\--|\--o-------
|\ o
------------o---------------
Output: B/8 C/8 D/8 E/32 F/32 G/32 D
----------------o-------------------
o
------------o-----------------------
o
--------o---------------------------
o
----o-------------------------------
o
o-----------------------------------
Output: E G B D F F A C E
|\
|\
|\
------------o-------|-----------
| o | |\
|---|\--------------|---|\------
| | o |\
o---|---|\--------------o---|\--
o |\ |\
--------|\------------------|---
o o
--------------------------------
Output: B/4 A/8 F/32 F/32 E C/4 B/32 F/16
Why doesn't whitespace count? – J B – 2011-07-22T11:59:33.027
@J: So that people won't feel inclined to submit programs one line long with no spaces. – Neil – 2011-07-22T12:19:38.150
1
It is conventional to count whitespace but to not count new-lines that are only there to keep the entry under a reasonable width. George's userscript does this with some languages (including c).
– dmckee --- ex-moderator kitten – 2011-07-22T14:26:31.3832@Neil well right now all I feel inclined to submit is a Whitespace program. – J B – 2011-07-22T16:36:16.267
@Neil, yeah, but then you get smartasses who write really verbose solutions, pack them into a string of whitespace, and golf a decode-and-exec: http://codegolf.stackexchange.com/questions/3203/meta-golf-challenge/3209#3209
– boothby – 2011-07-22T18:28:25.803How about whitespace that is required for your code to run counts? – Briguy37 – 2011-07-22T18:51:52.040
Is input given on stdin, or as command line arguments to a program or as input to a function? – Gareth – 2011-07-22T21:15:17.313
not counting whitespace is good for Haskell, since it has layout (similar to python) – FUZxxl – 2011-07-23T13:19:32.017
Assume it's stdin, though for Javascript, assume an input variable called input which holds the equivalent input string (assigning of the input string doesn't count in the length of the program). – Neil – 2011-07-25T08:36:58.340
@J B: Obviously Whitespace is excluded as a possible language to use, though if you really wish to inflict pain on yourself, I'll let you use Whitespace, though unlike other languages, I will count whitespace characters. – Neil – 2011-07-25T08:40:21.760
What about chords? What about accidentals? If it's supposed to be musical scores then both should certainly be supported, making the task much more interesting! – ceased to turn counterclockwis – 2011-08-04T00:21:37.457
@leftaroundabout: Might make a good follow-up task. I didn't want to write an impossibly difficult task complete with rests, staccato, and a small accompanied symphony. :) – Neil – 2011-09-13T14:10:32.277