Gistflow Xmas Quiz! by releu
What will we do until Xmas? Of course we will prepare for it!
Let's print Xmas tree by your favourite language!
All winners will get a present ;)
Here is the tree:
()
/\
/ *\
/ * \
/ * * *\
/* * *\
/ * * *\
/ * * * \
/ * * * \
[]
Decorations * should be placed randomly, but they can't be near each other for each line and their count should be equal 3 or less if they doesn't fit.
Shorter solution for each language wins.
Comments
Maysora commented 5 months ago
not really a short solution :P http://jsfiddle.net/maysora/QUvvK/
edit: oops.. i guess i misunderstood the question, i should have evenly divide the inside by 3 instead of just separate decoration by 1 space :/
makaroni4 commented 5 months ago
@Maysora
releu commented 5 months ago
Cool
killthekitten commented 5 months ago
I missed, that decorations can't be near each other. So you can fork my codepen and try to work it out http://codepen.io/killthekitten/pen/xvwdp
Maysora commented 5 months ago
@killthekitten the decoration maxed at 2 per line? i can't read coffeescript though so i don't know where it's wrong..
makaroni4 commented 5 months ago
Here is #ruby solution, it puts toys randomly with frequency you pass as an argument.
produces:
makaroni4 commented 5 months ago
Also it would be nice to animate christmas tree, but for mac terminal
system 'clear'doesn't work, I made smth like:but with big fps (delay 0.1 sec for example) it locks keyboard
Maysora commented 5 months ago
a bit update http://jsfiddle.net/maysora/QUvvK/1/
skammer commented 5 months ago
This almost works as requested, but not quite :/
To print a tree of arbitrary height:
Or as a oneliner (220 chars):
puts " "*8+"()"+"\n"+Array.new(8){|i|Array.new(3){Array.new(2){" "*(i*2-6>0 ? rand(i*2-6)/2 : rand(2))}.join "* "}.join.chars.first(i*2).join.center(i*2).prepend(" "*(8-i)+?/).concat(?\\)}.join("\n")+"\n"+" "*8+"[]"+"\n"agentcooper commented 5 months ago
makaroni4 commented 5 months ago
releu commented 5 months ago
Here is mine:
and compact (250 chars):
releu commented 5 months ago
And here is animated tree:
drakmail commented 5 months ago
Some #python code for diversity.
Formally, all rules met, but decorations placing in clusters (random clusters) :)
Link to online repl with code
pashh commented 5 months ago
Hello everyone
it just a refactoring makaroni4 #ruby solution. this code is not perfect and I try to fix it. But it most shorter (154 chars):
puts [" "*11+"()"]+(0..10).map{|i| Array.new(i*2){|j| j=['*', " "].shuffle[1..2].join }.push('/').reverse.push('\\').join("").center(25)}.push(" "*11+"[]")makaroni4 commented 5 months ago
@pashh what do you mean 'is not perfect' and what have you fixed in it?
Man, negativity is for the lazy and to say that someone's code is not perfect you at least should say why.
pashh commented 5 months ago
no, I mean my version is not perfect, because the "**" is exist near each other for each line.
releu commented 5 months ago
By the way @makaroni4 solution is not correct in terms of the rules.
makaroni4 commented 5 months ago
@pashh OK, so it was me who misunderstood the message
I am sorry for this.
drakmail commented 5 months ago
Could be ruby code obfuscated? Yes, it could!
Perl-style one-line ruby xmas tree:
output
releu commented 5 months ago
OMG. Your code can be used for interview. "Please tell me what this code is doing" :D
pashh commented 5 months ago
the last revision in concise, functional mood(170 characters):
puts [" "*10+"()"]+(0..10).map{|i| (Array.new(2*i,' ')+['*','*','*']).shuffle[1..2*i].push('/').reverse.push('\\').join.gsub(/\*\*/ ," "*2).center(22)}.push(" "*10+"[]")all conditionals was done
pashh commented 5 months ago
and this latest tiny fix (167 characters)
puts [" "*10+"()"]+(0..10).map{|i| (Array.new(2*i,' ')+['*','*','*']).shuffle[1..2*i].join.gsub(/\*\*/ ," "*2).insert(0,'/').concat('\\').center(22)}.push(" "*10+"[]")pashh commented 5 months ago
and of course Xmas tree for hipsters:
puts [" "*10+"()"]+(0..10).map{|i| (Array.new(2*i,' ')+['*','*','*']).shuffle[1..2*i].join.gsub(/\*\*/ ," "*2).insert(0,'\\').concat('/').center(22)}.push(" "*10+"[]")makaroni4 commented 5 months ago
powder96 commented 5 months ago
PHP, 245 bytes: https://gist.github.com/4413869 Source code: https://gist.github.com/4413821
atzkey commented 5 months ago
Ruby, 111 bytes:
puts *['()',*0.step(15,2).map{|i|'/'+('* '*3+' '*i)[0,i].scan(/../).shuffle*''+'\\'},'[]'].map{|t|t.center(16)}releu commented 5 months ago
pashh commented 5 months ago
impressive, I'm give up :)
makaroni4 commented 5 months ago