Skip to main content
remove trailing space from grace lines
Source Link
couchand
  • 296
  • 1
  • 4

GolfScript - 243 232 228228 227 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

EDIT: Saved six characters by properly using the increment operator, three by making good use of the stack, and six more by irresponsibly redefining operators I'm not using, and one more by not printing the trailing space after grace lines.

Entirely golfed:

..0="HL"?2+3%:o)2%.@="CDEFGAB"?7o*+:`2%45 32if:r;
).2$,<{=}{;;r}if:&;
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
[`<~]\[`>([0=:^&79r^]''+\~]
+17`<`)18if<9`>`9if:j>:t 13`>.2*):x;
4,1>{`j-\2${+}{-}if}%\;
{.@<\t>(:v[x<'|'+x)v>+]\++:t}
/-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*

GolfScript - 243 232 228 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

EDIT: Saved six characters by properly using the increment operator, three by making good use of the stack, and six more by irresponsibly redefining operators I'm not using.

Entirely golfed:

..0="HL"?2+3%:o)2%.@="CDEFGAB"?7o*+:`2%45 32if:r;
).2$,<{=}{;;r}if:&;
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
[`<~]\[`>([0=:^&79r^]''+\~]
+17`<`)18if<9`>`9if:j>:t 13`>.2*):x;
4,1>{`j-\2${+}{-}if}%\;
{.@<\t>(:v[x<'|'+x)v>+]\++:t}
/-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*

GolfScript - 243 232 228 227 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

EDIT: Saved six characters by properly using the increment operator, three by making good use of the stack, six more by irresponsibly redefining operators I'm not using, and one more by not printing the trailing space after grace lines.

Entirely golfed:

..0="HL"?2+3%:o)2%.@="CDEFGAB"?7o*+:`2%45 32if:r;
).2$,<{=}{;;r}if:&;
[" "5*:|" ---":g]4*[|"-"5*]5*+[|g|]+.
[`<~]\[`>([0=:^&79r^]''+\~]
+17`<`)18if<9`>`9if:j>:t 13`>.2*):x;
4,1>{`j-\2${+}{-}if}%\;
{.@<\t>(:v[x<'|'+x)v>+]\++:t}
/-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*
a few optimizations
Source Link
couchand
  • 296
  • 1
  • 4

GolfScript - 243243 232 228 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

EDIT: Saved six characters by properly using the increment operator, three by making good use of the stack, and six more by irresponsibly redefining operators I'm not using.

Entirely golfed:

..0="HL"?2+3%:o 2%1\-)2%.@="CDEFGAB"?7o*+:k 2%45`2%45 32if:r;
1+).2$,<{=}{;;r}if:a;&;
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
[k<~]\[k>[`<~]\[`>([0=:w a 79r w]''+\~]^&79r^]''+\~]
+17k<1k+18if<9k>k 9if+17`<`)18if<9`>`9if:j>:t;
13k>t 13`>.2*1+2*):x;
4,1>{k j`j-\2${+}{-}if}%\;
{.t<\t>@<\t>(:v[x<'|'+1x+v>+]\++v[x<'|'+x)v>+]\++:t;t}
/t-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*

GolfScript - 243 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

Entirely golfed:

..0="HL"?2+3%:o 2%1\-.@="CDEFGAB"?7o*+:k 2%45 32if:r;
1+.2$,<{=}{;;r}if:a;
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
[k<~]\[k>([0=:w a 79r w]''+\~]
+17k<1k+18if<9k>k 9if:j>:t;
13k>.2*1+:x;
4,1>{k j-\2${+}{-}if}%\;
{.t<\t>(:v[x<'|'+1x+v>+]\++:t;}
/t-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*

GolfScript - 243 232 228 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

EDIT: Saved six characters by properly using the increment operator, three by making good use of the stack, and six more by irresponsibly redefining operators I'm not using.

Entirely golfed:

..0="HL"?2+3%:o)2%.@="CDEFGAB"?7o*+:`2%45 32if:r;
).2$,<{=}{;;r}if:&;
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
[`<~]\[`>([0=:^&79r^]''+\~]
+17`<`)18if<9`>`9if:j>:t 13`>.2*):x;
4,1>{`j-\2${+}{-}if}%\;
{.@<\t>(:v[x<'|'+x)v>+]\++:t}
/-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*
Source Link
couchand
  • 296
  • 1
  • 4

GolfScript - 243 characters

I translated my CoffeeScript answer into GolfScript, which is much more suited to the string manipulations.

Entirely golfed:

..0="HL"?2+3%:o 2%1\-.@="CDEFGAB"?7o*+:k 2%45 32if:r;
1+.2$,<{=}{;;r}if:a;
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.
[k<~]\[k>([0=:w a 79r w]''+\~]
+17k<1k+18if<9k>k 9if:j>:t;
13k>.2*1+:x;
4,1>{k j-\2${+}{-}if}%\;
{.t<\t>(:v[x<'|'+1x+v>+]\++:t;}
/t-1%n*

With comments:

# extract octave
..0="HL"?2+3%:o

# extract note
2%1\-.@="CDEFGAB"?7o*+:k

# line spacer
2%45 32if:r;

# extract accidental
1+.2$,<{=}{;;r}if:a;

# staff
[" "5*:|" --- ":g]4*[|"-"5*]5*+[|g|]+.

# lines below
[k<~]\

# note line and above
[k>([0=:w a 79r w]''+\~]+

# cut off just what we need
17k<1k+18if<
9k>k 9if:j>:t;

# and the note stem
13k>.2*1+:x;4,1>{k j-\2${+}{-}if}%\;

{
  .t<\
  t>(:v[x<'|'+1x+v>+]\++:t;
}/

# now output the note
t-1%n*