问题
The challenge
The shortest code, by character count to output an ASCII representation of Sierpinski's Triangle of N iterations made from the following ASCII triangle:
/\
/__\
Input is a single positive number.
Test cases
Input:
2
Output:
/\
/__\
/\ /\
/__\/__\
Input:
3
Output:
/\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\
Input:
5
Output:
/\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\ /__\/__\
/\ /\ /\ /\
/__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\/__\/__\/__\/__\/__\/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\ /__\/__\
/\ /\ /\ /\
/__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\/__\/__\/__\ /__\/__\/__\/__\
/\ /\ /\ /\
/__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\/__\ /__\/__\ /__\/__\ /__\/__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\ /__\ /__\ /__\ /__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\
Code count includes input/output (i.e full program).
回答1:
Golfscript - 46
' /\ /__\ '4/{).+: ;.{ \ ++}%\{.+}%+~ ]}@~(*n*
Golfscript - 47
' /\ /__\ '4/): ;{ +: ;.{ \ ++}%\{.+}%+}@~(*n*
Golfscript - 48
' ': '/\ /__\\'+4/{2 *: ;.{ \ ++}%\{.+}%+}@~(*n*
Golfscript - 51
~' ': '/\ /__\\'+4/\(,{;2 *: ;.{ \ ++}%\{.+}%+}%;n*
Same algorithm as my shorter python ( and ruby ) answer
Golfscript - 78
2\~(?,{-1*}$1: ;{" ":$*. 2base.{[$$+' /\ ']=}%n+@@{[$$+"/__\\"]=}%n .2*^: ;}%
Same algorithm as my longer python solution
This one has significant newlines
2\~(?,{-1*}$1: ;{" ":
*. 2base.{[
2*' /\ ']=}%n+@@{[
2*"/__\\"]=}%n .2*^: ;}%
回答2:
J
46 characters, reading from stdin.
(,.~,~[,.~' '$~#,#)^:(<:".1!:1]3)' /\',:'/__\'
\n
always delimits sentences, which made it impossible to fit inside S3 (only 54 characters to play with). S4 is a bit big at 162, so I padded it to fit. Serendipitously, /\
is a legal adverb. ☺
/\ i=:3 /\ /\ %r=:1!:1 /\ /\ t=:] [r+i /\ /\ /\ /\ b=:' /\',:'/__\' /\ /\ i=:1 -".t /\ /\ /\ /\ h=:(' '$ ~#,#),.] /\ /\ /\ /\ s=:( h^:1 ,d=: ,.~) /\ /\ /\ /\ /\ /\ /\ /\ (,,&(10{a.)"1[s^:(-i)b)(1!:2)(4)