29
3
As part of a city planning project, you've gotten the assignment of creating a program or function that will display the city skyline, given some input from the architects. The project is only in the startup phase, so a very rough sketch is sufficient. The easiest approach is of course to simply draw the skyline in ASCII-art.
All buildings will be by the river, thus they are all aligned. The architects will give the height of each building as input, and your code should display the skyline.
The input from the architects will either be an integer or a half-integer. If the number is an integer, the building will have a flat roof, while a half-integer will result in a pitched roof. A zero will just be flat ground. The walls of a building are 3 characters apart, while a zero will be a single character wide. Adjacent buildings share walls.
For details and clarifications regarding the output, please have a look at the examples below:
N = 3
___
| |
| |
|___|
N = 3.5
_
/ \
| |
| |
|___|
N = 6
___
| |
| |
| |
| |
| |
|___|
n = 0
_
Example input: 3 3.5 0 2
_
___ / \
| | | ___
| | | | |
|___|___|_|___|
Example input: 0 0 2.5 3 0 4 1
___
_ ___ | |
/ \| | | |
| | | | |___
__|___|___|_|___|___|
Louisville, 0 2 1 3.5 0 4 2 4 2 4 6 1 6 0 5 1
___ ___
| | | | ___
_ ___ ___ ___| | | | | |
/ \ | | | | | | | | | | |
___ | | | |___| |___| | | | | | |
| |___| | | | | | | | |___| | | |___
_|___|___|___|_|___|___|___|___|___|___|___|___|_|___|___|
The ASCII-characters used are: newline, space, and /\_|
(code points 10, 32, 47, 92, 95, 124).
Rules:
- It's optional to make a program that only take integers as input, by multiplying all numbers by two. So, instead of taking
3 3.5 2
, your program may take6 7 4
. If the second input format is chosen, an input of 6 should result in a 3 story building, 7 should be a 3 story building with pitched roofs etc. - The output should be exactly as described above, but trailing spaces and newlines are OK.
- The exact format of the input is optional. Whatever is best in your language.
- The result must be displayed on the screen, so that the architects can have a look at it.
- You can assume there will be at least one integer given, and that only valid input will be given.
This is codegolf, so the shortest code in bytes win.
1What would a building of height 0.5 look like? – Tom Carpenter – 2015-11-29T20:07:34.583
Haven't thought of it really. The most obvious choice would be just a pitched roof, almost like a hobbit home :-) but you're free to choose, or you can assume the input will never be 0.5... – Stewie Griffin – 2015-11-29T21:44:18.443
1At the moment weird things happen as there are no walls (I assumed 0.5 high didn't exist), so I'll have to work on my answer a bit. – Tom Carpenter – 2015-11-29T21:54:24.070
I just tried your code with height 0.5, and I agree, "weird" is a very descriptive word =P I haven't gone through it in detail, so I'm not sure what is going on... Anyhow, you answer is perfectly valid, you can assume there aren't any 0.5 buildings... – Stewie Griffin – 2015-11-30T12:50:29.067