Beatles Songs and Hexagons
Befunge-93, width = 13 15, titles = 31 24 chars
A power outage last night prevented me from updating this when I figured it out, but I managed to reduce the triangle width and increase the song lengths!
Pointing-up program: "Dig a Pony", 10 characters:
v
v>
v# >
"<
v <>"y"v>
<v"Dig a P"
"^>:#,_@.>"no
Explanation
I REALLY took advantage of Befunge's wrap-around trick and I picked "Dig a Pony" specifically because it had a space at the 6th position. This allows program flow to move through the song name. Try it in the online interpreter to see how it works.
Pointing-down program: "If I Fell", 9 characters:
< v"f I Fell"
v>"I">:#,_@
"raC yM "
v"Drive
.
(Period is extraneous and only included to make the other lines show up.)
Explanation
The only relevant lines here are the first two. I used the wrap-around trick (the instruction pointer is sent left immediately) to squeeze in one more character. The second line prints out the song name.
Combined: "Drive My Car", 12 characters:
v< v"f I Fell"v
v> v>"I">:#,_@v>
v# >"raC yM "v# >
"< v"Drive"<
v <>"y"v> v <>"y"v>
<v"Dig a P" <v"Dig a P"
"^>:#,_@.>"no "^>:#,_@.>"no
< v"f I Fell"v< v"f I Fell"
v>"I">:#,_@v> v>"I">:#,_@
"raC yM "v# >"raC yM "
v"Drive"< v"Drive
v <>"y"v>
<v"Dig a P"
"^>:#,_@.>"no
Here's the same thing, but with lines added to show the hexagon and triangles.
-----------------
/v\< v"f I Fell"/v\
/v> \v>"I">:#,_@/v> \
/v# >\"raC yM "/v# >\
/"< \v"Drive/"< \
/v <>"y"v>\ /v <>"y"v>\
/<v"Dig a P"\ /<v"Dig a P"\
/"^>:#,_@.>"no\ /"^>:#,_@.>"no\
-------------------------------
\< v"f I Fell"/v\< v"f I Fell"/
\v>"I">:#,_@/v> \v>"I">:#,_@/
\"raC yM "/v# >\"raC yM "/
\v"Drive/"< \v"Drive/
\ /v <>"y"v>\ /
\ /<v"Dig a P"\ /
\ /"^>:#,_@.>"no\ /
-----------------
Explanation
This is where the third and fourth lines of the pointing-down triangle come into play. There are several redirects at the edge of both triangles that serve to move the instruction pointer through those two lines and push "Drive My Car" onto the stack. Then it is printed out using the >:#,_@
bit in the pointing-up triangle. Incidentally, both the left and the right pointing-up triangles are used.
There might be a way to use more of the empty space, but I think my time is better spent on other questions. :P
Python 2, width = 51
#print "Yellow Submarine" if id else "(Reprise)" ##
#.##...............................................##.#
#...##.............................................##...#
#.....##...........................................##.....#
#.......##.........................................##.......#
#.........##.......................................##.........#
#...........##.....................................##...........#
#.............##...................................##.............#
#...............##.................................##...............#
#.................##...............................##.................#
#...................##.............................##...................#
#.....................##...........................##.....................#
#.......................##.........................##.......................#
#.........................##.......................##.........................#
#...........................##.....................##...........................#
#.............................##...................##.............................#
#...............................##.................##...............................#
#.................................##...............##.................................#
#...................................##.............##...................................#
#.....................................##...........##.....................................#
#.......................................##.........##.......................................#
#.........................................##.......##.........................................#
#...........................................##.....##...........................................#
#.............................................##...##.............................................#
#...............................................##.##...............................................#
print "Sgt. Pepper's Lonely Hearts Club Band",;id=0#print "Sgt. Pepper's Lonely Hearts Club Band",;id=0
print "Yellow Submarine" if id else "(Reprise)" ##print "Yellow Submarine" if id else "(Reprise)" #
#...............................................##.##...............................................#
#.............................................##...##.............................................#
#...........................................##.....##...........................................#
#.........................................##.......##.........................................#
#.......................................##.........##.......................................#
#.....................................##...........##.....................................#
#...................................##.............##...................................#
#.................................##...............##.................................#
#...............................##.................##...............................#
#.............................##...................##.............................#
#...........................##.....................##...........................#
#.........................##.......................##.........................#
#.......................##.........................##.......................#
#.....................##...........................##.....................#
#...................##.............................##...................#
#.................##...............................##.................#
#...............##.................................##...............#
#.............##...................................##.............#
#...........##.....................................##...........#
#.........##.......................................##.........#
#.......##.........................................##.......#
#.....##...........................................##.....#
#...##.............................................##...#
#.##...............................................##.#
#print "Sgt. Pepper's Lonely Hearts Club Band",;id=0#
Yeah, well... Python.
Python comments begin with #
, so the majority of lines is just comments. For the upwards facing triangle, the only thing that executes is
print "Sgt. Pepper's Lonely Hearts Club Band",;id=0
which prints Sgt. Pepper's Lonely Hearts Club Band
.
For the downwards facing triangle, we execute
print "Yellow Submarine" if id else "(Reprise)"
which prints Yellow Submarine
, since the function id
is truthy.
When we combine the programs however, all that happens is the above two lines in sequence. Since the end of the first line sets id=0
, which is now falsy, the end result is that we tack a (Reprise)
to the end, getting Sgt. Pepper's Lonely Hearts Club Band (Reprise)
as our output (Calvin said this is okay).
GolfScript, width = 9 chars, titles = 33 chars
Hexagon
"Let It Be"
}";"Yeste"}";
"Twi""rda""Twi"
"st an""y""st an"
"d Shout"}"d Shout"
Let It Be"Let It Be
"Yeste"}";"Yeste"
"rda""Twi""rda"
"y""st an""y"
}"d Shout"}
Prints Let It Be. (9 characters)
Try it online.
How it works
The token "Let It Be"
on the first line pushes the string Let It Be on the stack.
The second line begins with }
, an undocumented "super comment" that aborts execution immediately.
Before exiting, GolfScript prints the contents of the stack.
X triangle
"
}";
"Twi"
"st an"
"d Shout"
Prints Twist and Shout. (15 characters)
Try it online.
How it works
The first two lines push the string "\n }"
, which the command ;
discards from the stack.
The remaining lines contain the tokens "Twi"
, "st an"
and "d Shout"
, which push the string Twist and Shout in three pieces.
Before exiting, GolfScript prints the contents of the stack.
Y triangle
Let It Be
"Yeste"
"rda"
"y"
}
Prints Yesterday. (9 characters)
Try it online.
How it works
The tokens Let
, It
and Be
on the first line are undefined, so they do nothing.
The three following lines contain the tokens "Yeste"
, "rda"
and "y"
, which push the string Yesterday in three pieces.
The }
on the last line does nothing; the program would have finished anyway.
Once more, GolfScript prints the contents of the stack before exiting.