Last active
December 31, 2015 14:09
-
-
Save zfogg/7998269 to your computer and use it in GitHub Desktop.
/r/dailyprogrammer #145 - easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
# | |
# http://redd.it/1t0r09 -/r/dailyprogrammer | |
# [12/16/13] Challenge #145 [Easy] Tree Generation | |
zipWith = (xss..., f) -> | |
for i in [0..-1+Math.min.apply 0, (x.length for x in xss)] | |
f.apply @, (xs[i] for xs in xss) | |
mul = (x, n) -> x for _ in [0...Math.max n, 0] | |
tree = (n, tr='=', le='*', sp=' ') -> | |
zipWith \ | |
(mul sp, (n-i-2) for i in [0...n]), | |
(mul le, (2*i+1)%(2*n-1) for i in [0...n]), | |
(mul sp, (n-i-2) for i in [0...n]), | |
(mul [], n-1).concat([(mul sp, n-3).concat (mul tr, 3), (mul sp, n-3)]), | |
((xs, yss...) -> xs.concat.apply xs, yss) | |
for i in [3..7] by 2 | |
console.log ((tree i).map (xs) -> xs.join '').join '\n' | |
# Output: | |
# * | |
# *** | |
# === | |
# * | |
# *** | |
# ***** | |
# ******* | |
# === | |
# * | |
# *** | |
# ***** | |
# ******* | |
# ********* | |
# *********** | |
# === | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment