60
14
Consider these seven ASCII train cars.
Engine (E)
__
====== \/
| [] |=========
| )
================
O-O-O O-O-O \\
Passenger car (P)
===============
| [] [] [] [] |
===============
O-O O-O
Boxcar (B)
===============
|-|-| | |-|-|
===============
O-O O-O
Tanker (T)
_____---_____
( )
===============
O-O O-O
Hopper (H)
_______________
\ | | | | | | /
===============
O-O O-O
Flatbed (F)
===============
O-O O-O
Caboose (C)
=====
====| |====
| [] [] |
=============
O-O O-O
Write a program that when given a sequence of the characters EPBTHFC
, outputs it's ASCII train representation, using --
for the car couplings. The leftmost input characters become the rightmost train cars. The train is always facing right.
For example, an input of EEHTBPFC
should produce
__ __
===== ====== \/ ====== \/
====| |==== =============== =============== _____---_____ _______________ | [] |========= | [] |=========
| [] [] | | [] [] [] [] | |-|-| | |-|-| ( ) \ | | | | | | / | ) | )
=============--===============--===============--===============--===============--===============--================--================
O-O O-O O-O O-O O-O O-O O-O O-O O-O O-O O-O O-O O-O-O O-O-O \\ O-O-O O-O-O \\
Details
- This is code golf; the shortest program in bytes wins.
- Any sequence of one or more of the letters
EPBTHFC
is valid input. - Your program must be able to output all 7 car types exactly as they appear above.
- Take input from the command line or directly from the user (e.g. message box). Output to stdout. (Quotes around input are fine.)
- The height of the output should either be 6 or the maximum height needed for the train cars being drawn.
- Do not put couplings (
--
) at the front of the first car or the back of the last car.
1
Related: http://codegolf.stackexchange.com/q/3628/194 , http://codegolf.stackexchange.com/q/4638/194
– Peter Taylor – 2014-07-19T08:39:05.873Will there always be an
E
at the front and could there be anE
somewhere in the middle? – Martin Ender – 2014-07-19T09:31:17.313There could be an E at the back or in the middle or no E's at all. Same goes for every other car type. – Calvin's Hobbies – 2014-07-19T09:32:52.883
1"the shortest program wins." => do we count bytes or characters? – xem – 2014-07-19T11:08:41.673
1
@xem, bytes unless otherwise specified
– Peter Taylor – 2014-07-19T12:57:32.180@PeterTaylor: As shown in the example output, presumably. – Ilmari Karonen – 2014-07-19T13:02:01.810
@Calvin'sHobbies Would you mind clarifying the rules on trailing whitespace and the width of the output - does it have to be a rectangle, or can it have trailing spaces beyond the rectangle defined by non-whitespace characters, or can it be trimmed within the rectangle? – VisualMelon – 2014-07-20T17:19:36.157
@VisualMelon Having trailing whitespace of any sort is fine. The output lines may form a rectangle or may be staggered or may have no trailing spaces at all. There should be no leading whitespace before the last car, however. – Calvin's Hobbies – 2014-07-20T17:27:45.453
@Calvin'sHobbies Thanks for the clarification, I'm not sure I like having the trailing white-space, but it shaved off 7bytes ;) great question BTW, good fun – VisualMelon – 2014-07-20T17:53:04.747
1
Another related question: http://codegolf.stackexchange.com/q/4690/9498
– Justin – 2014-07-23T23:45:52.317