19
5
The zombie apocalypse has come, and the world is coming to an end. Suddenly, someone discovers a formula that takes the current hour, minute, and day, and spits out the perfect note to play on a piano that instantly kills every zombie that hears it. Unfortunately, there is only one piano player left in the world, and he has forgotten how to read notes, but he still knows how to read sheet music. Of course, this is a very time-sensitive thing, so it seems natural to have a computer do it.1
Your challenge is to take a note, such as G
, and output the note placed on a staff (in treble clef), like this:
-----
-----
|
---|-
|
--O--
-----
Specification:
- You must output a staff of alternating lines of
-----
(5 dashes) and a blank line. There will be 5-----
s total. The note must be superimposed on top of this staff. - The input will specify where the note is located. The input will be:
- an optional
H
orL
, specifying "high" or "low" - a letter from
A
toG
, specifying the pitch - an optional
#
orb
, specifying sharp or flat.
- an optional
- The "note" is defined as:
- One
O
(capital O) aligned to the middle of the staff, which is in the place of the note. (The top line isHF
(high F), and the bottom line isE
(a normal E).) - Three
|
s (vertical bars), the stem, which will be:- one space to the left of the note and going downwards (starting one space below the note) if the note is on the middle line (
B
) or above, or - one space to the right of the note and going upwards (starting one space above the note) if the note is below the middle line.
- one space to the left of the note and going downwards (starting one space below the note) if the note is on the middle line (
- A
#
orb
one space directly to the left of the note if specified in the input.
- One
- Ledger lines must be added if the note is too high or low. These lines will be
---
(only 3 dashes in width, as opposed to 5) and will only appear if the note is on or above/below (for top/bottom ledger lines respectively) the ledger lines. - Extraneous spaces may be placed anywhere you want; for example, you could make the blank lines have spaces or have a space after the ledger lines if it helps you save any characters.
Here is a visualization, to understand the specification more easily, with all the note names next to the lines:
HB
--- HA
HG
----- HF
HE
----- HD
HC
----- B
A
----- G
F
----- E
D
--- C
LB
--- LA
LG
--- LF
... (bottom cut off for brevity, you get the idea anyway)
Here are some more examples that you can use to test your program:
Input: HG#
#O
-|---
|
-|---
-----
-----
-----
Input: LAb
-----
-----
-----
-----
-----
|
--|
|
bO-
Input: HB
O
|--
|
-|---
-----
-----
-----
-----
Input: C
-----
-----
-----
-----
|
---|-
|
-O-
This is code-golf, so the shortest code in bytes will win!
1: most realistic exposition evar! :-P
2It looks very strange to have
#
orb
at the right of the note rather than at the left; is it really what is required? – Thomas Baruchel – 2014-03-23T21:16:53.983@ברוכאל No; that's just me not thinking properly ;-) edited – Doorknob – 2014-03-23T21:18:52.603
You have two HC's in your Visualization. I assume the top one should be deleted, as you make no mention of HHC (double high) in the rest of the specification. – Level River St – 2014-03-23T22:27:58.967
@steve Oops; also a mistake. Edited – Doorknob – 2014-03-23T22:29:01.213
2What about B# and the like? 1. plot as-is; 2. reject; 3. silently convert to C? – Digital Trauma – 2014-03-23T22:42:58.220
@DigitalTrauma Plot those too; I've played B#s and E#s in my experience with piano before. (I've even played double sharps, but that's outside the scope of the challenge. ;-)) – Doorknob – 2014-03-23T22:44:31.503
2It may be better to explicitly state that it should be in treble clef. – user12205 – 2014-03-24T03:10:52.457
To clarify, by "on or above/below ... them" you mean the ledger lines, or alternately the pitches represented by the ledger lines. – couchand – 2014-03-24T03:39:46.507
@ace Of course; edited. – Doorknob – 2014-03-24T03:56:05.507
@couchand I thought that would be implied, but it's always good to be specific ;-) edited – Doorknob – 2014-03-24T03:56:55.627
How about your "blank line" requirement? Must it be be an absolutely empty line if there is no note or could it be four/five spaces? – Martin Ender – 2014-03-24T21:03:10.627
1@m.buettner Added an extra rule at the end of the specification to clarify. – Doorknob – 2014-03-24T21:24:24.990
Does it have to be text output? We should be able to render it as an image if we want. – AJMansfield – 2014-03-25T16:14:50.237
3
Anyone up to attempting this in Fugue?
– AJMansfield – 2014-03-25T16:18:10.5773@AJM Yes, it has to be ASCII art. – Doorknob – 2014-03-25T17:02:09.910