29
4
Input:
- You get a series of integers (fed via stdin or prompt).
- Every pair of integers in this series represents a building's WIDTH [valid range: 1..10] and HEIGHT [valid range: 0..10]
- Assume input to be well-formed.
Sample input (the second line is for demonstration purposes only):
1 2 1 1 1 0 2 4 1 3 1 2 2 1 W H W H W H W H W H W H W H
Corresponding sample output:
______ /______ /| | | |__ | |/__ /| __ | | | |__ /__ /| | | |/__ /| | | |__ | | | | |______ | |/__ /| | | | |/______ /| | | | |_| | | | | | |_o_|_o_|/__|_o_____|_o_|_o_|_o_____|/ ------------------------------------- - - - - - - - - - - - - - -------------------------------------
Rules:
The buildings
- A basic building block looks like this (1 W, 1H)
__ /__ /| (base cube is borrowed from the one at this question: | | | http://stackoverflow.com/questions/1609702/code-golf-playing-cubes) |___|/
Our view is (ahum) ~3D so neighbouring buildings may hide parts of others. Buildings are 'logically' rendered from left to right.
The first building is preceded by two spaces to it's left.
You render every building by applying the WIDTH and HEIGHT to the dimensions of the base cube (do have a look at the sample output provided!). For reference: number of characters from the left to the right 'wall' (for a building with W > 1): (W*5)-(W-1).
Buildings with Height > 0 have ONE door (which is depicted by the character
o
and is located at two characters from the 'left' wall on the 'bottom' row ).
The road:
- The road consists of three parts which we'll call 'top', 'middle' and 'bottom'.
- The 'top' part and 'bottom' part are identical apart from the fact that the 'top' part is preceded by two spaces.
- The middle part is preceded by one space and consists of a repetition of the
following pattern:
'- '
- Length is to be determined by the total width of the combined buildings: the most rightmost part of the road corresponds with the position of the 'right' wall of the 'last' building.
Winners:
This is code-golf! The winner is the qualifying contestant with the shortest solution (by source code count). The source must consist solely of printable ASCII characters. Have fun!
Imaginary bonus points for (random) windows, cars or pedestrians.
Feel free to comment if the specifications are not clear!
@user unknown: there was indeed a small typo in the rules indeed. Should be fixed now, thanks! – ChristopheD – 2012-01-18T16:36:48.407
Trailing whitespace permitted? You seem to have some in the example, so I assume so. – Peter Taylor – 2012-01-18T16:59:06.160
@Peter Taylor: trailing whitespace is allowed. – ChristopheD – 2012-01-18T17:21:08.397
Road part 3, should that be
'- '
(with two spaces)? Edit: Ah, the two spaces don't show :P. You can display multiple spaces by using ASCII 255 (non-breaking space, ALT+255 on numpad), or by copying and pasting from my comment here. Orr... you could instead just say it's a repetition of' - '
:) – mellamokb – 2012-01-18T18:52:11.677It looks like the height valid range is actually [0..10]. Also what do you mean by
but you must not enforce this
in 3)? IMO, any assumption is available to be exploited if it increases your score. So I may write code that only works if the total width is less than 80 if I can squeeze out a lower character count. For example, writing output to a display buffer array with a width of 80, so it will crash on any higher total width. If you want any width supported, then don't give the assumption - you can't have both :P – mellamokb – 2012-01-18T19:00:56.123@mellamokb: thanks for commenting! (spaces and range fixed). You may write code that only works if the total width is less than 80, that was what I was trying to convey. But you are right, I'll delete part of the assumption. – ChristopheD – 2012-01-18T19:08:57.647