高尔夫代码:谢尔宾斯基的三角 [英] Code Golf: Sierpinski's Triangle
本文介绍了高尔夫代码:谢尔宾斯基的三角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按字符计数的最短代码,用于输出由以下ASCII三角形组成的Sierpinski的N次迭代的Triangle的ASCII表示形式:
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:
2
Output:
/\
/__\
/\ /\
/__\/__\
Input:
3
Output:
/\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\
Input:
5
Output:
/\
/__\
/\ /\
/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\ /__\/__\
/\ /\ /\ /\
/__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\/__\/__\/__\/__\/__\/__\/__\
/\ /\
/__\ /__\
/\ /\ /\ /\
/__\/__\ /__\/__\
/\ /\ /\ /\
/__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\/__\/__\/__\ /__\/__\/__\/__\
/\ /\ /\ /\
/__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\/__\ /__\/__\ /__\/__\ /__\/__\
/\ /\ /\ /\ /\ /\ /\ /\
/__\ /__\ /__\ /__\ /__\ /__\ /__\ /__\
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\
/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\/__\
代码计数包括输入/输出(即完整程序).
Code count includes input/output (i.e full program).
推荐答案
Golfscript-46
' /\ /__\ '4/{).+: ;.{ \ ++}%\{.+}%+~ ]}@~(*n*
Golfscript-47
' /\ /__\ '4/): ;{ +: ;.{ \ ++}%\{.+}%+}@~(*n*
Golfscript-48
' ': '/\ /__\\'+4/{2 *: ;.{ \ ++}%\{.+}%+}@~(*n*
Golfscript-51
~' ': '/\ /__\\'+4/\(,{;2 *: ;.{ \ ++}%\{.+}%+}%;n*
与我的较短python(和ruby)答案相同的算法
Same algorithm as my shorter python ( and ruby ) answer
Golfscript-78
2\~(?,{-1*}$1: ;{" ":$*. 2base.{[$$+' /\ ']=}%n+@@{[$$+"/__\\"]=}%n .2*^: ;}%
与我更长的python解决方案相同的算法
Same algorithm as my longer python solution
这是一条重要的换行符
2\~(?,{-1*}$1: ;{" ":
*. 2base.{[
2*' /\ ']=}%n+@@{[
2*"/__\\"]=}%n .2*^: ;}%
这篇关于高尔夫代码:谢尔宾斯基的三角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文