r/dailyprogrammer • • Aug 05 '12
[8/3/2012] Challenge #85 [intermediate] (3D cuboid projection)
Write a program that outputs simple 3D ASCII art for a cuboid in an oblique perspective, given a length, height, and depth, like this:
$ python 3d.py 20 10 3
:::::::::::::::::::/
:::::::::::::::::::/+
:::::::::::::::::::/++
####################+++
####################+++
####################+++
####################+++
####################+++
####################+++
####################+++
####################++
####################+
####################(The characters used for the faces (here #, :, and +) are fully up to you, but make sure you don't forget the / on the top-right edge.)
11
Upvotes
3
u/5outh 1 0 Aug 05 '12
Pretty simple in Haskell, but tons and tons of replicate.
2
u/andkerosine Aug 06 '12
Ruby:
3
u/bradengroom Aug 06 '12 edited Aug 06 '12
Perl:
2
u/DNAW Aug 05 '12
Hi, new subscriber to this subreddit, and since I wanted to learn a new language this month, here is my Python solution:
2
u/bh3 Aug 05 '12
Python:
2
u/Lord_Skellig Aug 07 '12 edited Aug 07 '12
Python:
1
u/goldjerrygold_cs Aug 05 '12
Pretty straightforward, took a bit of trial and error, but yeah. Doesn't work for 0 values but easily could be extended:
1
u/fgsguedes 0 0 Aug 06 '12
My [Java implementation] (https://github.com/fgsguedes/reddit-daily-programmer/blob/master/src/challenge85/intermediate/CubeProjection.java)
ps. I really wish Java had the "string" * number feature that python have, it made goldjerrygold_cs's solution way much clean without all if's
:P
1
u/[deleted] Aug 06 '12 edited Aug 06 '12
C. I put the characters for face, top, side and edge as optional parameters, as well. If you do not specify them, the characters from OP's example are used.
Edit: My father pointed out that it doesn't work well for depth values that are higher than length and height. If someone would like to fix this, I would be interested in looking at it, but I don't have the time right now.
1
u/[deleted] Aug 07 '12 edited Aug 07 '12
http://codepad.org/onain42u
My code has inconsistent results when two of the dimensions are zero, I wonder if there's any pretty way to fix that without making it too much more verbose...
EDIT: took out needless "printN" function.
EDIT 2: slightly more minimalistic.
1
u/5hassay Aug 08 '12 edited Aug 08 '12
Here's mine, only tested to work with given example and two other examples (horray for Python!):
EDIT:
Fixing formatting, -_-Formatting1
u/Puzzel Aug 08 '12
Here's a Python 3 solution:
1
u/cdelahousse Aug 10 '12
Javascript.
1
u/cdelahousse Aug 10 '12 edited Aug 10 '12
Concise Javascript. I rewrote my previous script. I only used one loop in the body.
1
u/landscapez Aug 16 '12 edited Aug 16 '12
Always thanks for your problems! My C++ solution
Though, this day's challenge #85[easy] was harder to solve
0
u/BlueMelonG Aug 07 '12
Here is my solution, http://pastebin.com/zv07vTwH
0
u/shinthemighty Aug 08 '12
Python, object oriented: