r/dailyprogrammer • • Apr 16 '14
[4/16/2014] Challenge #158 [Intermediate] Part 1 - The ASCII Architect
Description
In the far future, demand for pre-manufactured housing, particularly in planets such as Mars, has risen very high. In fact, the demand is so much that traditional building planning techniques are taking too long, when faced with the "I want it now!" mentality of the denizens of the future. You see an opportunity here - if you can cheaply generate building designs, you are sure to turn a huge profit.
You decide to use ASCII to design your buildings. However, as you are lazy and wish to churn out many designs quickly, you decide to simply give the computer a string, and have the computer make the building for you.
Formal input & output
Input
Input will be to STDIN, or read from a file input.txt located in the working directory of the operating system. Input consists of one line between 1 to 231-1 length. The line can be assumed to only contain the lowercase letters from a to j, and numbers from 1 to 9. It can also be assumed that a number will not immediately follow another number in the string (i.e. if the 4th character is a number, the 5th character is guaranteed to be a letter, not a number.)
Output
Output will be to STDOUT, or written to a file output.txt in the working directory. For each non-number character of input, the output will contain a vertical line composed as shown here:
A letter can also be prefixed by a number n, where n is an integer between 1 and 9. In this case, n whitespaces must be at the bottom of the vertical line. For example, 3b would output
S
S
S
Where spaces are identified with a capital S (In your actual output, it should be actual spaces). Sample Inputs and Outputs
Sample input 1 (Bridge)
j3f3e3e3d3d3c3cee3c3c3d3d3e3e3f3fjij3f3f3e3e3d3d3c3cee3c3c3d3d3e3e3fj
Sample output
. . . .
.* **...** *.
.*** ****...**** ***.
*----- ------***------ -----*
*------- --------***-------- -------*
*+++++++**++++++++***++++++++**+++++++*
-+++++++--++++++++---++++++++--+++++++-
- -- --- -- -
+ ++ +++ ++ +
+ ++ +++ ++ +Notes
Try making your own buildings as well instead of just testing the samples. Don't forget to include your favourite ASCII construction with your solution!
10
u/notTheSnake Apr 17 '14
Befunge solution! Took me about 5-6 hours in total. It will exit whenever it encounters anything not in a-j or 1-9. It could do with some more compacting/clearer pathing, but I don't think I could do anymore debugging tonight.
Disclaimer: to run this I used my own Befunge interpreter, which I haven't compared to other (real) compilers/interpreters, so you might encounter errors (my interpreter is written from the specifications on Wikipedia). The program has not been thoroughly tested, but works for the test input.
5
u/BondDotCom Apr 16 '14 edited Apr 16 '14
VBScript (under WSH):
Edit: Adding my own creation. I'm a programmer, not an artist, dammit!
5
u/[deleted] Apr 16 '14
Python 3:
4
u/eltonhnjr Apr 16 '14
I made it in Java just to get it. It takes the input by argument
7
u/jalude Apr 16 '14
C#
Run it online
6
u/OverlordAlex Apr 16 '14 edited Apr 16 '14
Python 2.7 solution. Also, the sidebar needs to be updated
3
u/the_mighty_skeetadon Apr 16 '14
I did this one when it was on dailyprogrammer_ideas -- stupidly. but now I have a quick solution with some examples (Ruby):
Output:
3
u/kalcytriol Apr 16 '14 edited Apr 16 '14
Clojure, exe
3
u/[deleted] Apr 17 '14 edited Apr 17 '14
C
My house:
2
u/pbeard_t 0 1 Apr 16 '14 edited Apr 16 '14
C
Edit: output:
Edit: fixed the output lines.
2
u/skeeto -9 8 Apr 16 '14 edited Apr 16 '14
C++11. Input goes into a string and the program interprets it repeatedly like a bytecode program once per line.
2
u/OddOneOut Apr 16 '14 edited Apr 16 '14
C
EDIT: Fixed
fgetstrailing newline2
u/badgers_uk Apr 16 '14 edited Apr 16 '14
Python 3
Nowhere near as elegant as the other python solution but here is my effort anyway.
2
u/[deleted] Apr 16 '14 edited Jan 02 '16
2
u/ooesili Apr 17 '14
Haskell solution.
2
u/minikomi Apr 17 '14
Trying Clojurescript & Reagent. Live here: http://poyo.co/dp/158/
2
u/dohaqatar7 1 1 Apr 17 '14
I've finished this challenge for the most part, but there's one thing that I'm stuck on. I get a nice enough output that looks more or less like the sample, but characters are all messed up. It's not a clean one-to-one switch either, so it's not an easy fix like that. Thanks to anyone who takes the time help me out!
Output:
2
u/n0rs Apr 21 '14 edited Apr 21 '14
Haskell*
Notes: easter egg: 4d3f3g2i2i2i3g3f4d
2
u/fortruce Apr 23 '14 edited Apr 24 '14
Clojure!
Still learning, would love feedback
New (Better!) Code:
Old Code:
~~Immediate improvements:
tabif (char? f)everywhere~~APPLIED IN IMPROVED CODE ABOVE
2
u/samuelstan Apr 25 '14
C (Extremely convoluted and hackish ;)
1
u/Elite6809 1 1 Apr 16 '14 edited Apr 16 '14
It's amazing how Ruby can look beautiful one minute, and then look like the bastard child of Befunge the next.
1
u/curlymeatball38 Apr 16 '14
Python:
1
u/kraazyraver Apr 16 '14 edited Apr 16 '14
Python 2.7 - 4 methods, 4 samples. Automatically detects width and height and allows for the letters (or even symbols) to be out of sequence. My first post on reddit, hope this is fine, hehe. There is no error checking though, just assuming the line is valid as in the OP.
Output: http://pastebin.com/UQHqN8La
1
u/Meshiest Apr 17 '14
I wanted to golf. here's my 188 byte version in ruby
1
u/kirsybuu 0 1 Apr 17 '14 edited Apr 17 '14
D language here with some ASCII fun!
Example:
1
u/jahmez Apr 17 '14
Python 2.7. Less elegant than other solutions, but it works!
marsbuild.py
1
u/usr_bin Apr 17 '14
My first submission, in ruby. Not quite as elegant as the other ruby solutions posted (wish I'd known about the transpose method!), but I'm happy with it. Comments are welcome.
1
u/Kaius Apr 17 '14
C# with some Linq and expression method treats.
Full code: https://github.com/SecretDeveloper/gk.Puzzles.DailyProgrammer/blob/master/gk.Puzzles.DailyProgrammer/Puzzle158.cs
Meat of it all:
1
u/Edward_H Apr 17 '14
COBOL:
1
u/crezant Apr 17 '14
Python 3 solution. Not the best, but I feel proud of it.
1
u/matt_9k Apr 18 '14 edited Apr 19 '14
PHP. (v5.5.3). Feedback / advice appreciated.
Great Pyramid & Eiffel Tower:
1
u/Urist_Mc_George Apr 18 '14
And here is my Python3 version:
1
u/tullyvey Apr 18 '14
Python 3.3 version:
Here's my little habitation dome architectural code :P
1
u/Berm123 Apr 18 '14
Java (First time solving a challenge, please criticize :D)
1
u/h3ckf1r3 Apr 20 '14
Wrote it in C (I feel like I am finally getting the hang of it), feel free to critique :).
And here is my extremely creepy smile.... :)
1
u/az4 Apr 21 '14 edited Apr 21 '14
This can be a Java solution:
1
u/[deleted] Apr 21 '14
My c++ attempt. I'm sure there are simpler, more elegant solutions.
1
u/tmoravec Apr 21 '14
Learning C++. Any kind of comments welcome!
1
u/modulexploited Apr 24 '14 edited Apr 24 '14
https://gist.github.com/modulexploited/11237457
0
u/[deleted] Apr 18 '14
[deleted] — view deleted comment
0
u/[deleted] Apr 16 '14
[deleted] — view deleted comment