从ASCII的位模式生成分形


34

总览

编写一个程序,在给出编码分形的位模式后,再打印出简单的分形模式,再加上分代的每代比例因子和世代数。

说明

这是Sierpinski地毯的ASCII表示形式:

第0代:

# 

第1代:

# # # 
#   # 
# # # 

第2代:

# # # # # # # # # 
#   # #   # #   # 
# # # # # # # # # 
# # #       # # # 
#   #       #   # 
# # #       # # # 
# # # # # # # # # 
#   # #   # #   # 
# # # # # # # # # 

ASCII Sierpinski地毯的n + 1代由一个包含8个n代副本的3x3网格组成,但缺少网格的中心元素。

因此,因为它是使用3x3网格定义的,并且每一代的宽度和高度都增大了3倍,所以可以说它的比例因子是3。

我们可以为Sierpinski地毯定义位模式,方法是将3x3网格中的元素从0到8进行编号(从上到下,从左到右),并在n + 1代包含一个整数的情况下设置整数的相应位。在那个网格位置的第n代的副本:

bit:       place value:   bit pattern:   bit value:

0 1 2      1    2    4    1 1 1          1    2    4
3 4 5      8   16   32    1 0 1          8    0   32 
6 7 8      64 128  256    1 1 1          64 128  256 

integer value = 1 + 2 + 4 + 8 + 32 + 64 + 128 + 256 = 495

对于比例因子2,位模式将如下排列:

0 1
2 3

等等。

您的任务是编写一个程序,以这种形式接受位模式,比例因子(例如,Sierpinski Carpet为3)和世代号,并输出ASCII分形。

输入项

您的程序应按以下顺序接受3个整数:位模式,比例因子(范围从2到5,包括端值)和世代计数(范围从0到5,包括端值)。

您不需要对这些值执行任何输入验证,并且如果程序适用于大于指定范围的值,则完全可以。

输入可以任何形式传递(元组,逗号/以空格分隔的列表等)

输出量

程序应输出一个分形,该分形由以下#字符组成:定义该分形的位置后跟一个空格,未定义该分形的位置后加一个空格,并在每行末尾添加换行符,以打印出来或返回字符串从功能。

例子

输入:

495,3,3

输出(Sierpinski Carpet第三代):

# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # #       # # # # # #       # # # # # #       # # # 
#   #       #   # #   #       #   # #   #       #   # 
# # #       # # # # # #       # # # # # #       # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # #                   # # # # # # # # # 
#   # #   # #   #                   #   # #   # #   # 
# # # # # # # # #                   # # # # # # # # # 
# # #       # # #                   # # #       # # # 
#   #       #   #                   #   #       #   # 
# # #       # # #                   # # #       # # # 
# # # # # # # # #                   # # # # # # # # # 
#   # #   # #   #                   #   # #   # #   # 
# # # # # # # # #                   # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # #       # # # # # #       # # # # # #       # # # 
#   #       #   # #   #       #   # #   #       #   # 
# # #       # # # # # #       # # # # # #       # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 

输入:

7,2,5

输出(Sierpinski Triangle):

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #   
# #     # #     # #     # #     # #     # #     # #     # #     
#       #       #       #       #       #       #       #       
# # # #         # # # #         # # # #         # # # #         
#   #           #   #           #   #           #   #           
# #             # #             # #             # #             
#               #               #               #               
# # # # # # # #                 # # # # # # # #                 
#   #   #   #                   #   #   #   #                   
# #     # #                     # #     # #                     
#       #                       #       #                       
# # # #                         # # # #                         
#   #                           #   #                           
# #                             # #                             
#                               #                               
# # # # # # # # # # # # # # # #                                 
#   #   #   #   #   #   #   #                                   
# #     # #     # #     # #                                     
#       #       #       #                                       
# # # #         # # # #                                         
#   #           #   #                                           
# #             # #                                             
#               #                                               
# # # # # # # #                                                 
#   #   #   #                                                   
# #     # #                                                     
#       #                                                       
# # # #                                                         
#   #                                                           
# #                                                             
#                                                               

输入:

325,3,3

输出(Cantor Dust):

#   #       #   #                   #   #       #   # 

#   #       #   #                   #   #       #   # 



#   #       #   #                   #   #       #   # 

#   #       #   #                   #   #       #   # 









#   #       #   #                   #   #       #   # 

#   #       #   #                   #   #       #   # 



#   #       #   #                   #   #       #   # 

#   #       #   #                   #   #       #   # 

输入项

186,3,3

输出(Vicsek分形):

                          #                           
                        # # #                         
                          #                           
                    #     #     #                     
                  # # # # # # # # #                   
                    #     #     #                     
                          #                           
                        # # #                         
                          #                           
        #                 #                 #         
      # # #             # # #             # # #       
        #                 #                 #         
  #     #     #     #     #     #     #     #     #   
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
  #     #     #     #     #     #     #     #     #   
        #                 #                 #         
      # # #             # # #             # # #       
        #                 #                 #         
                          #                           
                        # # #                         
                          #                           
                    #     #     #                     
                  # # # # # # # # #                   
                    #     #     #                     
                          #                           
                        # # #                         
                          #                           

输入:

279,3,3

输出(不对称分形的示例):

# # # # # # # # # # # # # # # # # # # # # # # # # # # 
  #     #     #     #     #     #     #     #     #   
    #     #     #     #     #     #     #     #     # 
      # # #             # # #             # # #       
        #                 #                 #         
          #                 #                 #       
            # # #             # # #             # # # 
              #                 #                 #   
                #                 #                 # 
                  # # # # # # # # #                   
                    #     #     #                     
                      #     #     #                   
                        # # #                         
                          #                           
                            #                         
                              # # #                   
                                #                     
                                  #                   
                                    # # # # # # # # # 
                                      #     #     #   
                                        #     #     # 
                                          # # #       
                                            #         
                                              #       
                                                # # # 
                                                  #   
                                                    # 

等等

笔记:

  • 这是所以最短答案以字节为单位
  • 您的程序可以是独立程序,也可以是使用3个输入参数调用并返回(或打印)字符串的函数
  • 即使对于0的位模式,也将生成0定义为##后跟一个空格)。
  • 最后一行的尾随换行符是可选的,但允许,每行中的尾随空格也可以。

3
+1,我在沙盒中喜欢它,在这里我更喜欢它,其符号从更改"##""# "。我看到您的示例中包含了行尾的一个尾随空格,这是必需的吗?。根据最后一条规则,我认为它是可选的,但是对于第0代您需要尾随空格的事实使我感到奇怪。另外,我认为您应该指出允许的最大空白和换行符。作为一个极端的例子,我总是可以从2 * 5 ^ 6空间的5 ^ 6 = 15625行数组开始,然后替换#s。在大多数输入情况下,这是大量未使用的空白
Level River St

@steveverrill我在输出第0代时不需要尾随空格,但是尾随空格是其定义的一部分,后代是根据其定义的。固定的换行符是复数形式。
samgak

您是否可以为不对称的对象发布期望的输出279,3,3
aditsu

@aditsu当然可以,请参见编辑后的问题
samgak

Answers:


4

APL(Dyalog Unicode),37字节SBCS

'# '{⊃⍪/,/⍺\⍤1⊂⍉⍪⍉⍵}⍣⎕⍨(2⍴⎕)⍴⌽⎕⊤⍨992
                                      input the bit pattern
                               ⊤⍨992  decode 99 binary digits from it
                                        (53 is the limit for floating point)
                                      reverse, least significant bit goes first
                                      input the scale factor
                       (2 )           twice, to use as dimensions of a matrix
                                      reshape bit pattern into such a matrix
                                      input the number of generations
'# '{              }⍣                 apply that many times, starting from '# '
               ⍉⍪⍉⍵                    make sure the argument is a matrix
                                      enclose
          \⍤1                         expand using rows of bit-pattern matrix
                                        (1 for identical copy, 0 for zeroed out)
     ⊃⍪/,/                             concat all horizontally and vertically

在线尝试!


11

普通Lisp 248 242字节

(lambda(n r g &aux(s(expt r g)))(labels((f(g x y s)(or(= g 0)(#2=multiple-value-bind(q x)(floor x s)(#2#(p y)(floor y s)(if(logbitp(+ q(* p r))n)(f(1- g)x y(/ s r))))))))(#3=dotimes(y s)(#3#(x s)(princ(if(f g x y(/ s r))"# ""  ")))(terpri))))

不打高尔夫球

(defun fractal (n r g &aux (s (expt r g)))
  (labels((f(g x y s)
            (or(= g 0)
               (multiple-value-bind (px x) (truncate x s)
                 (multiple-value-bind (py y) (truncate y s)
                   (and
                    (logbitp (+ px (* py r)) n)
                    (f (1- g) x y (/ s r))))))))
    (fresh-line)
    (dotimes(y s)
      (dotimes(x s)
        (princ
         (if (f g x y(/ s r))
             "# "
             "  ")))
      (terpri))))

说明

  • 输入:
    • N是编码模式
    • R是图案的大小
    • G是一代
  • 输出是长度为S = R G的隐式平方矩阵
  • 我们遍历每行y,第x列(嵌套dotimes),并计算是否应绘制每个像元(类似射线投射的方法)。这是通过使用f辅助函数递归查看分形内部来完成的。
  • 如果应绘制(x,y)位置的分形,请打印"# ",否则请打印" "。当然,我们还在每行的末尾打印换行符。

例如,Sierpinsky的三角形由S=7和表示R=2。在第3代中,正方形大小为2 3 = 8。对于每个像元(x,y),将发生以下情况:

  • f通过xyg绑定到3以及s绑定到4(8/2)来调用
  • 我们用s截断x,以便知道x是属于隐式矩阵的左侧还是右侧。同时返回分别绑定到pxx的商和余数(我们重复使用相同的符号x,但这不是问题)。truncate
  • y相同,给出py和new y
  • 在此示例中,pxpy可以为0或1(因为图案是长度为2的正方形)。他们确定,其中是(X,Y)在分形的图案:当在位置的位py.R + PXÑ是0,Xÿ表示其中没有什么应被绘制的位置。
  • 否则,我们必须“放大”到分形的相应部分,并f使用xy的新绑定递归调用。这些现在是内部分形内部的相对位置。我们将G-1传递给生成,将s / 2传递给分形的一半长度。
  • G为零时遇到递归的基本情况,在这种情况下应绘制当前(x,y)位置。

(fractal 186 3 3)

                          #                           
                        # # #                         
                          #                           
                    #     #     #                     
                  # # # # # # # # #                   
                    #     #     #                     
                          #                           
                        # # #                         
                          #                           
        #                 #                 #         
      # # #             # # #             # # #       
        #                 #                 #         
  #     #     #     #     #     #     #     #     #   
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
  #     #     #     #     #     #     #     #     #   
        #                 #                 #         
      # # #             # # #             # # #       
        #                 #                 #         
                          #                           
                        # # #                         
                          #                           
                    #     #     #                     
                  # # # # # # # # #                   
                    #     #     #                     
                          #                           
                        # # #                         
                          #                           

使用计算第8代Sierpinski地毯(fractal 495 3 8)需要24.7秒,并生成83 MB的输出文本文件。我写了一个稍微修改的版本,可以输出图像。对于相同的参数,GIF文件的权重为1.5MB(相同的计算时间):

谢尔宾斯基的地毯,第8代

Vicsek(单击以查看原始大小):

Vicsek分形


1
+1看起来像一个简陋的程序,用一种非常冗长的语言。)连续嵌套8 个!
水平河圣

@steveverrill我从来没有赢得过代码高尔夫比赛……但是,我仍然认为语法对于大型程序是有回报的。老实说,我几乎再也看不到括号了,只是一棵漂亮的树。
coredump

那个gif图像实际上使我的手机的Web浏览器崩溃了……用一种更不寻常的语言进行的伟大高尔夫运动
Glenn Smith

@HiGuy谢谢。CodeGolf是否有用于使其他人的浏览器崩溃的标志?它应该:-)
coredump

5

Pyth,38个字节

VJ^UQvwjdm@" #".A@L_.[0^Q2jvz2+V*RQNdJ

在线尝试:常规输入/测试套件

稍后进行解释。


1+我仍在等待186 3 5(在线解释器)的输出,但除此之外,它的短短确实给我留下了深刻的印象。
coredump

1
@coredump我认为使用在线解释器不会获得如此大的输出。如果要对其进行测试,则必须下载Pyth编译器。我的笔记本电脑大约需要10秒钟。
2015年

4

红宝石154

分数仅适用于该功能。在下面的测试程序中显示。我目前声称的唯一高尔夫活动是删除注释和缩进。我待会打高尔夫球。此刻,我在玩这个程序很开心。

该函数接受六个参数,但是在首次调用时,每个spec仅提供前三个参数。这会导致将剩余的三个参数设置为默认值,尤其a是将创建存储输出的字符串并将其初始化为以换行符结尾的空格行。作为副作用,$w还会创建全局变量,指示每行的符号数。

当函数递归调用自身时,它将提供所有六个参数,包括字符串a以及下一个递归的左上角的x和y坐标

如注释所示,该程序的其余部分非常简单。

#function
f=->b,s,g,x=0,y=0,a=(' '*(-1+2*$w=s**g)+'
')*$w{                                         #accept arguments, if x,y,a are not provided create them. $w = number of symbols per row 
  v=s**g/s                                     #v=width of blocks for this recursion depth
  if g==0
    a[2*y*$w+2*x]=?#                           #if g==0 plot a #
  else                                         #else iterate s*s times through the bits of b, and recurse as necessary
    (s*s).times{|i|b>>i&1>0&&f.call(b,s,g-1,x+i%s*v,y+i/s*v,a)} 
  end
  a
}

#test program (requires 3 input numbers separated by newlines)
b=gets.to_i
s=gets.to_i
g=gets.to_i
#get return value and output to stdout
puts f.call(b,s,g)

输出量

这是一组分形的松散形式,基于单词GOLF的字母形式。使用较大的位图可以实现更逼真的字母。如最后一个示例所示,最有趣的分形是偶然发现的。

63775,4,2 (G)

# # # # # # # # # # # # # # # #
#       #       #       #      
#     # #     # #     # #     #
# # # # # # # # # # # # # # # #
# # # #                        
#                              
#     #                        
# # # #                        
# # # #                 # # # #
#                       #      
#     #                 #     #
# # # #                 # # # #
# # # # # # # # # # # # # # # #
#       #       #       #      
#     # #     # #     # #     #
# # # # # # # # # # # # # # # #

495,3,3 (O, sierpinski carpet)

# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # #       # # #                   # # #       # # #
#   #       #   #                   #   #       #   #
# # #       # # #                   # # #       # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #

457,3,3 (L)

#                                                    
#                                                    
# # #                                                
#                                                    
#                                                    
# # #                                                
#     #     #                                        
#     #     #                                        
# # # # # # # # #                                    
#                                                    
#                                                    
# # #                                                
#                                                    
#                                                    
# # #                                                
#     #     #                                        
#     #     #                                        
# # # # # # # # #                                    
#                 #                 #                
#                 #                 #                
# # #             # # #             # # #            
#                 #                 #                
#                 #                 #                
# # #             # # #             # # #            
#     #     #     #     #     #     #     #     #    
#     #     #     #     #     #     #     #     #    
# # # # # # # # # # # # # # # # # # # # # # # # # # #

7967,4,2 (F)

# # # # # # # # # # # # # # # #
#       #       #       #      
# # # # # # # # # # # # # # # #
#       #       #       #      
# # # #                        
#                              
# # # #                        
#                              
# # # # # # # # # # # # # # # #
#       #       #       #      
# # # # # # # # # # # # # # # #
#       #       #       #      
# # # #                        
#                              
# # # #                        
#      

1879,3,3 (skull and crossbones discovered by accident)

# # # # # # # # # # # # # # # # # # # # # # # # # # #
  #     #     #     #     #     #     #     #     #  
#   # #   # #   # #   # #   # #   # #   # #   # #   #
      # # #             # # #             # # #      
        #                 #                 #        
      #   #             #   #             #   #      
# # #       # # # # # #       # # # # # #       # # #
  #           #     #           #     #           #  
#   #       #   # #   #       #   # #   #       #   #
                  # # # # # # # # #                  
                    #     #     #                    
                  #   # #   # #   #                  
                        # # #                        
                          #                          
                        #   #                        
                  # # #       # # #                  
                    #           #                    
                  #   #       #   #                  
# # # # # # # # #                   # # # # # # # # #
  #     #     #                       #     #     #  
#   # #   # #   #                   #   # #   # #   #
      # # #                               # # #      
        #                                   #        
      #   #                               #   #      
# # #       # # #                   # # #       # # #
  #           #                       #           #  
#   #       #   #                   #   #       #   #

3

果酱,45岁

3aaq~@2b2$_*0e[W%@/a*{ffff*:.+:.+}/' ff+Sf*N*

实现我的第一个想法。在线尝试

基本上,它从一个包含3('#'和''之间的差)的1 * 1矩阵开始,然后将该矩阵中的每个数字与位模式(0/1矩阵)重复相乘,然后将所得矩阵合并为一个更大的矩阵。最后,它为每个数字添加一个空格,并与空格和换行符连接。

第二个主意,49

q~@2bW%2$/z@@m*_,\_m*:z@f{3@@f{\~@==*}~' +}/Sf*N*

在线尝试

这将生成输出矩阵的所有坐标,作为小于比例因子的所有<generation count>对数字数组(所有此类组合),然后为每对数字从模式中获取相应的位,并为每个坐标数组它将位乘以3。最后的处理是相同的。

可能还有更多打高尔夫球的空间。


2

C,316字节

main(a,_,b,s,g,i,w,o,z,x,y)char**_,*o;{b=atoi(_[1]);s=atoi(_[2]);g=atoi(_[3]);w=1;for(i=0;i<g;++i){w*=s;}o=malloc(w*w);for(i=0;i<w*w;++i)o[i]=35;z=w/s;while(z){for(y=0;y<w;++y)for(x=0;x<w;++x)if(!((b>>((y/z)%s*s+(x/z)%s))&1))o[y*w+x]=32;z/=s;}for(y=0;y<w;++y){for(x=0;x<w;++x)printf("%c ",o[y*w+x]);printf("\n");}}

未打高尔夫球:

#include <stdio.h>

int main(int argc, char *argv[]) 
{
    int bitpattern;
    int scale;
    int generation;

    bitpattern = atoi(argv[1]);
    scale = atoi(argv[2]);
    generation = atoi(argv[3]);

    int i;
    int width = 1;
    for (i=0; i<generation; ++i) {width*=scale;}

    char *out=malloc(width*width);

    for (i=0; i<width*width; ++i) out[i]='#';


    int blocksize = width/scale;
    for (i=0; i<generation; ++i) {
        int x,y;
        for (y=0; y<width; ++y) {
            for (x=0; x<width; ++x) {
                int localX = x/blocksize;
                localX %= scale;
                int localY = y/blocksize;
                localY %= scale;
                int localPos = localY*scale+localX;
                if (!((bitpattern>>localPos)&1))out[y*width+x]=' ';
            }
        }
        blocksize/=scale;
    }

    int x,y;
    for (y=0; y<width; ++y) {
        for (x=0; x<width; ++x)
            printf("%c ",out[y*width+x]);
        printf("\n");
    }
    return 0;
}

3
根据规范末尾的要点,允许使用功能而不是程序。将其更改为一个函数,然后将三个输入参数传递给它-这将消除所有atoi的内容,并为您节省大约40个字节。
水平河圣

2

斯卡拉293 299

(e:Int,s:Int,g:Int)=>{def b(x:Int,y:Int)=(1<<x*s+y&e)>0;def f(n:Int):Seq[Seq[Char]]=if(n<1)Seq(Seq('#'))else if(n<2)Seq.tabulate(s,s)((i,j)=>if(b(i,j))'#'else' ')else{val k=f(n-1);val t=k.size;Seq.tabulate(t*s,t*s)((i,j)=>if(b(i/t,j/t))k(i%t)(j%t)else' ')};f(g).map(_.mkString(" ")).mkString(" \n")}

松散:

//create an anonymous function
(encoded: Int, size: Int, generation: Int) => {

  // method will return true if coords (x,y) should be drawn as '#'
  def isBlackInPattern(x: Int, y: Int): Boolean = (1 << x * size + y & encoded) > 0

  // recurse until generation is 1
  def fillRecursively(gen: Int): Seq[Seq[Char]] = {

    // this is just to satisfy OP requirements.
    // if the stopping condition were generation = 1,
    // I could have spared this line...
    if(gen < 1) Seq(Seq('#'))

    //actual stopping condition (generation 1). 
    // fill a matrix of characters with spaces
    // and hashes acording to the pattern.
    else if(gen < 2) Seq.tabulate(size, size)((i, j) => 
      if (isBlackInPattern(i,j)) '#' 
      else ' '
    )

    // recurse, and use previously created fractals to fill
    // the current generation according to the `isBlackInPattern` condition
    else {
      val previousGeneration = fillRecursively(gen-1)
      val previousSize = previousGeneration.size
      // create the current matrix and fill it
      Seq.tabulate(previousSize*size,previousSize*size)((i,j)=>
        if(isBlackInPattern(i/previousSize,j/previousSize))
          previousGeneration(i%t)(j%t)
        else ' '
      )
    }
  }
  // call to recursive function and format matrix of characters to string
  fillRecursively(generation).map(_.mkString(" ")).mkString(" \n")
}

例子:

val f = (e:Int,s:Int,g:Int)=>{def b(x:Int,y:Int)=(1<<x*s+y&e)>0;def f(n:Int):Seq[Seq[Char]]=if(n<1)Seq(Seq('#'))else if(n<2)Seq.tabulate(s,s)((i,j)=>if(b(i,j))'#'else' ')else{val k=f(n-1);val t=k.size;Seq.tabulate(t*s,t*s)((i,j)=>if(b(i/t,j/t))k(i%t)(j%t)else' ')};f(g).map(_.mkString(" ")).mkString(" \n")}
f: (Int, Int, Int) => String = <function3>

scala> println(f(495,3,3))
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # #       # # # # # #       # # # # # #       # # # 
#   #       #   # #   #       #   # #   #       #   # 
# # #       # # # # # #       # # # # # #       # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # #                   # # # # # # # # # 
#   # #   # #   #                   #   # #   # #   # 
# # # # # # # # #                   # # # # # # # # # 
# # #       # # #                   # # #       # # # 
#   #       #   #                   #   #       #   # 
# # #       # # #                   # # #       # # # 
# # # # # # # # #                   # # # # # # # # # 
#   # #   # #   #                   #   # #   # #   # 
# # # # # # # # #                   # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # #       # # # # # #       # # # # # #       # # # 
#   #       #   # #   #       #   # #   #       #   # 
# # #       # # # # # #       # # # # # #       # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # #

scala> println(f(7,2,5))
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #   
# #     # #     # #     # #     # #     # #     # #     # #     
#       #       #       #       #       #       #       #       
# # # #         # # # #         # # # #         # # # #         
#   #           #   #           #   #           #   #           
# #             # #             # #             # #             
#               #               #               #               
# # # # # # # #                 # # # # # # # #                 
#   #   #   #                   #   #   #   #                   
# #     # #                     # #     # #                     
#       #                       #       #                       
# # # #                         # # # #                         
#   #                           #   #                           
# #                             # #                             
#                               #                               
# # # # # # # # # # # # # # # #                                 
#   #   #   #   #   #   #   #                                   
# #     # #     # #     # #                                     
#       #       #       #                                       
# # # #         # # # #                                         
#   #           #   #                                           
# #             # #                                             
#               #                                               
# # # # # # # #                                                 
#   #   #   #                                                   
# #     # #                                                     
#       #                                                       
# # # #                                                         
#   #                                                           
# #                                                             
# 

scala> println(f(18157905,5,2))
#       #                               #       # 
  #   #                                   #   #   
    #                                       #     
  #   #                                   #   #   
#       #                               #       # 
          #       #           #       #           
            #   #               #   #             
              #                   #               
            #   #               #   #             
          #       #           #       #           
                    #       #                     
                      #   #                       
                        #                         
                      #   #                       
                    #       #                     
          #       #           #       #           
            #   #               #   #             
              #                   #               
            #   #               #   #             
          #       #           #       #           
#       #                               #       # 
  #   #                                   #   #   
    #                                       #     
  #   #                                   #   #   
#       #                               #       # 

第一次打球,也许可以打得更远...


您在每一个之间都缺少空格#。除了规范要求之外,它确实可以增强输出的外观。
水平河圣

@steveverrill您的权利。起初我没有注意到。我进行了快速修复。谢谢:)
吉拉德·霍奇(Gilad hoch)2015年

2

Matlab,115字节

Kronecker kron产品使一切变得简单:

function f(p,f,g);z=nan(f);z(:)=de2bi(p,f*f);x=3;for k=1:g;x=kron(x,z);end;disp([reshape([x;0*x],f^g,2*f^g)+32,''])

# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # #       # # # # # #       # # # # # #       # # # 
#   #       #   # #   #       #   # #   #       #   # 
# # #       # # # # # #       # # # # # #       # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # #                   # # # # # # # # # 
#   # #   # #   #                   #   # #   # #   # 
# # # # # # # # #                   # # # # # # # # # 
# # #       # # #                   # # #       # # # 
#   #       #   #                   #   #       #   # 
# # #       # # #                   # # #       # # # 
# # # # # # # # #                   # # # # # # # # # 
#   # #   # #   #                   #   # #   # #   # 
# # # # # # # # #                   # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # #       # # # # # #       # # # # # #       # # # 
#   #       #   # #   #       #   # #   #       #   # 
# # #       # # # # # #       # # # # # #       # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 
#   # #   # #   # #   # #   # #   # #   # #   # #   # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # 

虽然de2bi只有在拥有“通讯系统工具箱”的情况下才有效。没有它是行不通的。这将需要dec2bin
汤姆·卡彭特

看来此工具箱包含在我的标准学生版中,所以我认为这是可以接受的。(请注意,de2bi这与dec2bin。不同)
。–瑕疵的

2

C,158字节

f(p,s,g,h,i,j,c){for(j=1;g--;j*=s);for(h=j;h;){h--;for(i=j;i;){i--;for(c=35,g=j/s;g;g/=s)c=!((p>>((h/g)%s*s+(i/g)%s))&1)?32:c;printf("%c ",c);}printf("\n");}}

1

K5,70个字节

这是一个开始:

{,/'("  ";"# ")$[z;(z-1){,/'+,/'+x@y}[(0*t;t)]/t:(2#y)#|(25#2)\x;,,1]}

实际上:

{,/'("  ";"# ")$[z;(z-1){,/'+,/'+x@y}[(0*t;t)]/t:(2#y)#|(25#2)\x;,,1]}[186;3]'!4
(,"# "
 ("  #   "
  "# # # "
  "  #   ")
 ("        #         "
  "      # # #       "
  "        #         "
  "  #     #     #   "
  "# # # # # # # # # "
  "  #     #     #   "
  "        #         "
  "      # # #       "
  "        #         ")
 ("                          #                           "
  "                        # # #                         "
  "                          #                           "
  "                    #     #     #                     "
  "                  # # # # # # # # #                   "
  "                    #     #     #                     "
  "                          #                           "
  "                        # # #                         "
  "                          #                           "
  "        #                 #                 #         "
  "      # # #             # # #             # # #       "
  "        #                 #                 #         "
  "  #     #     #     #     #     #     #     #     #   "
  "# # # # # # # # # # # # # # # # # # # # # # # # # # # "
  "  #     #     #     #     #     #     #     #     #   "
  "        #                 #                 #         "
  "      # # #             # # #             # # #       "
  "        #                 #                 #         "
  "                          #                           "
  "                        # # #                         "
  "                          #                           "
  "                    #     #     #                     "
  "                  # # # # # # # # #                   "
  "                    #     #     #                     "
  "                          #                           "
  "                        # # #                         "
  "                          #                           "))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.