Language agnostic 高尔夫代码:蜘蛛网 挑战

Language agnostic 高尔夫代码:蜘蛛网 挑战,language-agnostic,code-golf,rosetta-stone,Language Agnostic,Code Golf,Rosetta Stone,按字符数计算的最短代码,用于输出环等于用户输入的蜘蛛网 通过重建中心环开始蜘蛛网: \_|_/ _/ \_ \___/ / | \ 然后添加等于用户输入的金额的环。圆环是由\/和\制成的“蜘蛛圆”的另一层,它包裹着中心圆 输入始终保证为单个正整数 测试用例 代码计数包括输入/输出(即完整程序)。Python:240个字符 这里没有太棘手的问题;只需逐行打印-298 280 271 266 265 261 260 254 240个字符(忽略最后2个换行符) Pyth

按字符数计算的最短代码,用于输出环等于用户输入的蜘蛛网

通过重建中心环开始蜘蛛网:

   \_|_/
  _/   \_
   \___/
   / | \
然后添加等于用户输入的金额的环。圆环是由
\/
\
制成的“蜘蛛圆”的另一层,它包裹着中心圆

输入始终保证为单个正整数

测试用例

代码计数包括输入/输出(即完整程序)。

Python:240个字符 这里没有太棘手的问题;只需逐行打印-298 280 271 266 265 261 260 254 240个字符(忽略最后2个换行符)

Python,340-309-269-250个字符 我认为还有改进的余地

s=input()+1
f,b="/ ","\\"
r=range(s)
for i in r:w="_"*(s-i);print" "*(s+(i>=1)-i)+(f*i)[:-1]+b+w+"|"+w+"/"+"\ "*i
print"_/"*s+" "*3+"\_"*s+"\n"+" \\"*s+"_"*3+f*s
for i in r[::-1]:u="_ "[i<1]*(s-i);print" "*(s-i+(i>=1))+("\ "*i)[:-1]+"/"+u+"|"+u+b+f*i
s=input()+1
f、 b=“/”,“\\”
r=范围(s)
对于r中的i:w=“25;”*(s-i);打印“*(s+(i>=1)-i)+(f*i)[:-1]+b+w+”|“+w+”/“+”\”*i
打印“\\/”*s+”*3+“\\\\”*s+“\n”+“\\”*s+“\\”*3+f*s
对于r[::-1]:u=“\u”[i=1])+(“\”*i)[:-1]+“/”+u+“\124;”+u+b+f*i
-

Python(可选版本),250-246个字符
s=input()+1;r=range(s);c=“/”,“\\”y=“/”,“\\”
def o(i,r):u=“”[i=1)-i)+(y[r]*i)[:-1]+c[rPython-212个字符
Perl 264字符
通过在子例程中排列而缩短

perl -E'$"="";($i=<>)++;@r=map{$p=$i-$_;@d=(" "x$_,(" ","\\")x$p,"/","_"x$_);($d="@d")=~y:\\/:/\\:;@d=reverse@d;$d.="|@d"}1..$i;say for reverse@r;$_=$r[0];y: _|:_  :;s:.(.*)\\.*/(.*).:$1_/   \\_$2:;say;y: _\\/:_ /\\:;say;$r[-1]=~y:_: :;say for grep{y:\\/:/\\:}@r;'
perl-E'$“=”;($i=)++;@r=map{$p=$i-$\u;@d=(“x$”,(“,“\”))x$p,“/”,“\ux$”;($d=“@d”)=~y:\/:/\:;@d=reverse@d;$d.=“|@d”}1..$i;表示赞成reverse@r$$\\\\\\\\\\\$r[0];y:$r[-1]=~y:$s:.(.*)\\\\./(.*):$1\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\:$r[-1]=~y:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\:$r;'
扩展以提高可读性

perl -E'
  $"="";
  ($i=<>)++;
  @r=map{
    $p=$i-$_;
    @d=(
      " "x$_,
      (" ","\\")x$p,
      "/",
      "_"x$_
    );
    ($d="@d")=~y:\\/:/\\:;
    @d=reverse@d;
    $d.="|@d"
  }1..$i;
  say for reverse@r;
  $_=$r[0];
  y: _|:_  :;
  s:.(.*)\\.*/(.*).:$1_/   \\_$2:;
  say;
  y: _\\/:_ /\\:;
  say;
  $r[-1]=~y:_: :;
  say for grep{y:\\/:/\\:}@r;
'
perl-E'
$"="";
($i=)+;
@r=地图{
$p=$i-$\;
@d=(
“x$”,
(“”,“\\”)x$p,
"/",
_ux$_
);
($d=“@d”)=~y:\/:/\:;
@d=reverse@d;
$d.=“|@d”
}1.$i;
表示赞成reverse@r;
$\ r=$r[0];
y:|:|:|;
s:.(.*)\\./(.*):$1\\\\\\\$2:;
说,;
y:\\/:\/\:;
说,;
$r[-1]=~y:u::;
代表grep{y:\\/:/\\:}@r;
'
这是我最小化它之前的代码:

#! /opt/perl/bin/perl
use 5.10.1;

($i=<>)++;
$"=""; #" # This is to remove the extra spaces for "@d"

sub d(){
  $p=$i-$_;
  " "x$_,(" ","\\")x$p,"/","_"x$_
}

sub D(){
 @d=d;
 ($d="@d")=~y:\\/:/\\:; # swap '\' for '/'
 @d=reverse@d;
 $d.="|@d"
}

@r = map{D}1..$i;

say for reverse@r; # print preceding lines

# this section prints the middle two lines
$_=$r[0];
y: _|:_  :;
s:.(.*)\\.*/(.*).:$1_/   \\_$2:;
say;
y: _\\/:_ /\\:;
say;

$r[-1]=~y:_: :; # remove '_' from last line
say for grep{y:\\/:/\\:}@r; # print following lines
!/opt/perl/bin/perl
使用5.10.1;
($i=)+;
$“=”;##这是为了删除“@d”的额外空格
附属d(){
$p=$i-$\;
“x$”、(“”、“\”)x$p、“/”、“\ux”$_
}
附属D(){
@d=d;
($d=“@d”)=~y:\/:/\:;#将“\”交换为“/”
@d=reverse@d;
$d.=“|@d”
}
@r=map{D}1..$i;
表示赞成reverse@r##打印前几行
#本节打印中间的两行
$\ r=$r[0];
y:|:|:|;
s:.(.*)\\./(.*):$1\\\\\\\$2:;
说,;
y:\\/:\/\:;
说,;
$r[-1]=~y:::#从最后一行中删除“35;”
为grep{y:\/:/\\:}@r;#打印以下行
Ruby1.9-181 chars 卢比1.8-185 chars
JRL的一些改进

n=gets.to_i+1;s=' '
u='_';a=0.upto(n-1).map{|i|s*(j=n-i)+' /'*i+'\\'+u*j+'|'+u*j+'/'+'\ '*i+s*j}
d=a.reverse.map{|x|x.reverse}
d[-1].tr!u,s;puts a,'_/'*n+s*3+'\_'*n,' \\'*n+u*3+'/ '*n,d
红宝石-207字符
Ruby似乎对“\”有一些特殊的规则

Golfscript-124个字符 所有空格都是有效的!如果您不小心在末尾添加了一个换行符,则在输出的末尾会有一个额外的

~):@,{@\:&-:0' ': *& '/':/+*'\\':~'_':
0*.'|':|\/~ +&*n}%
/+@*   ~
+@*n ~+@*


@/ +*n@,{):& *@&-:( ~+*/[
 ](!=&*.|\~/ +(*n}%
Golfscript-129个字符

~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
0*.'|'\'/'~ +&*n}%'_/'@*   '\_'@*n ~+@*


@'/ '*n@,{):& *@&-:( ~+*'/'[
 ](!=&*.'|'\~'/ '(*n}%
~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
0*.'|'\'/'~ +&*n}%'_/'@*3 *'\_'@*n' \\'@*3
*@'/ '*n@,{):& *@&-:( ~+*'/''_ '1/(!=&*.'|'\~'/ '(*n}%
Golfscript-133个字符

~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
0*.'|'\'/'~ +&*n}%'_/'@*   '\_'@*n ~+@*


@'/ '*n@,{):& *@&-:( ~+*'/'[
 ](!=&*.'|'\~'/ '(*n}%
~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
0*.'|'\'/'~ +&*n}%'_/'@*3 *'\_'@*n' \\'@*3
*@'/ '*n@,{):& *@&-:( ~+*'/''_ '1/(!=&*.'|'\~'/ '(*n}%
Perl,164个字符 195184171 167164

print@o=((映射{$z=\$x($x=1+$N-$\})$“x$x.”/“x$\$z.\$z/”'\'x$.$/}.0..($N=),
“\\\'x$N.$/”;
y'/\\'\/'、@o|y#u#u#u#u#u#、$t++u| y#u#u#u#,边打印边打印$_=pop@o
第一条语句打印出蜘蛛网的上半部分。第二条语句使用音译操作创建上半部分的反射

下一个重量接近314个字符(生产代码),但更符合本季的精神

           ;               "
         Tr                 Ic
        K|                   |t
       Re                     aT
       ",                     "H
       av                     e
        A:                    -
     )H AL                   LO  W
    ee  N"                   ,"  En
   jo    y_                 Yo    ur
   _      C&&             y";     ##
   &I      ();           $N=      1+
   <>;      $,=  $/;@O  =((     map 
    $" x($   X=$N-$_). ${   f}x$_.$
        B.${U}x$X.$P.${U}x$X.$
    F.${b}x$_,0..$N-1),${g}x$N.(${S}
   x3).${c}x$N);sub I{($F,$B,$U, $P)
  =qw         (/ \\ _ |);;         ${
 S}=        " ";$f=$S.$F;$g=$       U.
 $F     ;$b=$B.$S;$c=$B.${U};}@{    P}=
@{     O};  while($_=pop@{P}  ){     @{
 P}    ||   y:_: :;$spooky++  ||    0|
  0    ||   y@_ @ _@;y:/:8:;   ;    ;
   ;   ;;   y:\\:/:;y:8:\\:;  @O   =
    (  @O    ,$_);}print@O;   q{
       Do     !Discuss:Rel    ig
       io       n,Politi      cs
        ,&                   &T
        heG                 rea
          tP              ump
            ki           n}
;”
Tr Ic
K | | t
在
“,”H
AVE
A:-
)H AL LO W
"恩","恩",
乔·尤尔
_C&y“##
&I();$N=1+
;$,=$/;@O=((映射)
$“x($x=$N-$\)${f}x$\$
B.${U}x$x.$P.${U}x$x$
F.${b}x$0..$N-1),${g}x$N.(${S}
x3)${c}x$N);分I{($F,$B,$U,$P)
=qw(/\\\\\\\|)${
S} ='';$f=$S.$f;$g=$U。
$F;$b=$b.$S;$c=$b.${U};}{P}=
@{O};while($\=pop@{P}){@{
P} | | y:|:$spooky++| | 0|
0    ||   y@_y:/:8:;
;;y:\:/:;y:8:\\:;@O=
(@O,$)}print@O;q{
做!讨论:Rel ig
国际奥委会
,&&T
赫格里亚
tP-ump
ki n}
帽尖

我手工构建了蜘蛛形状的代码,但请参阅CPAN上的模块,以获得任务自动化(或至少半自动化)的帮助。

Vb.net、windows控制台、推断、严格、明确等。 Microsoft word没有空格,只能显示442个字符

可能会进一步减少,但这是我的最后一次更新(尝试2)

Module z
Sub Main()
    Dim i = CInt(Console.ReadLine), j = i + 1, h = j * 2 + 1, w = h * 2, z = "_", b = " "

    For y = 0 To h
        For x = 0 To w
            Dim l = (x + y Mod 2 + i Mod 2) Mod 2, u = j + y, e = j - y, k = h + e, o = x = h Or x = h - 1
            Console.Write(If(x = h, If(y = j, b, If(y = j + 1, z, "|")), "") & If(x = w, vbLf, If(y = j, If(x Mod 2 = 0 = (x < h), If(o, b, z), If(x < h, "/", "\")), If(x < k And x > u Or (x < u And x > k Or o) And y < h, z, If(x = k Or (x < u And y < j And x > e Or x > u And y > j And x < w + e) And l = 0, "/", If(x = u Or (x > k And y < j And x < h + u Or x < k And y > j And x > y - j - 1) And l = 1, "\", b))))))
        Next
    Next
End Sub
End Module
模块z
副标题()
尺寸i=CInt(Console.ReadLine),j=i+1,h=j*2+1,w=h*2,z=“”,b=“”
对于y=0到h
对于x=0到w
尺寸l=(x+y模2+i模2)模2,u=j+y,e=j-y,k=h+e,o=x=h或x=h-1
控制台.写(如果(x=h,如果(y=j,b,如果(y=j+1,z,“;”),“”)和如果(x=w,vbLf,如果(x模2=0=(xu或(xk或o)和ye或x>u和y>j和x+e)和l=0,“/”,如果(xk和yj和x>y-j-1)和l=1,“\”,b()()))
下一个
下一个
端接头
端模块
Ruby1.8179 使用ruby-n运行

n=$_.to_i+1
u,s,c=%w{_ \  \ \\}
z=(1..n).map{|i|k=n-i
s*i+c*k+'/'+u*i+'|'+u*i+"\\"+'/ '*k+s*i}
y=z.reverse.map{|a|a.reverse}
z[-1].tr!u,s
puts y,'_/'*n+s*3+'\_'*n,c*n+u*3+'/ '*n,z
在下面的第一次尝试中,只生成一个象限(我选择了左下角),然后镜像两次以获得整个web似乎是个好主意。但是生成两个象限(上半部分)并生成而不是
~):@,{@\:&-:0' ': *& '/':/+*'\\':~'_':
0*.'|':|\/~ +&*n}%
/+@*   ~
+@*n ~+@*


@/ +*n@,{):& *@&-:( ~+*/[
 ](!=&*.|\~/ +(*n}%
~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
0*.'|'\'/'~ +&*n}%'_/'@*   '\_'@*n ~+@*


@'/ '*n@,{):& *@&-:( ~+*'/'[
 ](!=&*.'|'\~'/ '(*n}%
~):@,{@\:&-:0' ': *&' /'*'\\':~'_':
0*.'|'\'/'~ +&*n}%'_/'@*3 *'\_'@*n' \\'@*3
*@'/ '*n@,{):& *@&-:( ~+*'/''_ '1/(!=&*.'|'\~'/ '(*n}%
print@o=((map{$z=_ x($x=1+$N-$_);$"x$x." /"x$_."\\$z|$z/".'\ 'x$_.$/}0..($N=<>)),
"_/"x++$N."   ".'\_'x$N.$/);
y'/\\'\/',@o||y#_# #,$t++||y#_ # _#,print while$_=pop@o
           ;               "
         Tr                 Ic
        K|                   |t
       Re                     aT
       ",                     "H
       av                     e
        A:                    -
     )H AL                   LO  W
    ee  N"                   ,"  En
   jo    y_                 Yo    ur
   _      C&&             y";     ##
   &I      ();           $N=      1+
   <>;      $,=  $/;@O  =((     map 
    $" x($   X=$N-$_). ${   f}x$_.$
        B.${U}x$X.$P.${U}x$X.$
    F.${b}x$_,0..$N-1),${g}x$N.(${S}
   x3).${c}x$N);sub I{($F,$B,$U, $P)
  =qw         (/ \\ _ |);;         ${
 S}=        " ";$f=$S.$F;$g=$       U.
 $F     ;$b=$B.$S;$c=$B.${U};}@{    P}=
@{     O};  while($_=pop@{P}  ){     @{
 P}    ||   y:_: :;$spooky++  ||    0|
  0    ||   y@_ @ _@;y:/:8:;   ;    ;
   ;   ;;   y:\\:/:;y:8:\\:;  @O   =
    (  @O    ,$_);}print@O;   q{
       Do     !Discuss:Rel    ig
       io       n,Politi      cs
        ,&                   &T
        heG                 rea
          tP              ump
            ki           n}
Module z
Sub Main()
    Dim i = CInt(Console.ReadLine), j = i + 1, h = j * 2 + 1, w = h * 2, z = "_", b = " "

    For y = 0 To h
        For x = 0 To w
            Dim l = (x + y Mod 2 + i Mod 2) Mod 2, u = j + y, e = j - y, k = h + e, o = x = h Or x = h - 1
            Console.Write(If(x = h, If(y = j, b, If(y = j + 1, z, "|")), "") & If(x = w, vbLf, If(y = j, If(x Mod 2 = 0 = (x < h), If(o, b, z), If(x < h, "/", "\")), If(x < k And x > u Or (x < u And x > k Or o) And y < h, z, If(x = k Or (x < u And y < j And x > e Or x > u And y > j And x < w + e) And l = 0, "/", If(x = u Or (x > k And y < j And x < h + u Or x < k And y > j And x > y - j - 1) And l = 1, "\", b))))))
        Next
    Next
End Sub
End Module
n=$_.to_i+1
u,s,c=%w{_ \  \ \\}
z=(1..n).map{|i|k=n-i
s*i+c*k+'/'+u*i+'|'+u*i+"\\"+'/ '*k+s*i}
y=z.reverse.map{|a|a.reverse}
z[-1].tr!u,s
puts y,'_/'*n+s*3+'\_'*n,c*n+u*3+'/ '*n,z
n=$_.to_i+1
m=2*n+1
u,s,b,f=%w{_ \  \\ /}
z=(0..n).map{|i|s*i+(s+b)*(n-i)+(i==0?u:f)+u*i}
q=z.reverse.map{|a|a.tr f+b,b+b+f}
q[n].gsub!' ','_'
q[n][m-1]=s
z=(q+z).map{|a|a+'|'+a.reverse.tr(f+b,b+b+f)}
z[n][m]=z[n+1][m]=s
z[m].gsub!u,s
puts z
n=...s=string r=s.reverse g=s.gsub a="\\|/"j=(" /"):rep(n+1)..a..("\\ "):rep(n+1) k=j o=k l=n*4+7 for i=1,n+1 do k=g(k,"^(.- )/(.-)|(.*)\\(.-)$","%1%2_|_%3%4")o=k..o end o=o..r(o)print((g(g(g(g(r(g(o:sub(1,l),"_"," ")..o:sub(l+1)),j,g(j," ","_")),("."):rep(l),"%1\n"),a," "),r(a),"___"))) Challenge Best Python Best Ruby The Wave 161 99 PEMDAS no python entry (default victory?) Seven Segs 160 175 Banknotes 83 (beat Perl!) 87 Beehive 144 164 RPN (no eval) 111 (157) 80 (107) Cubes 249 233 Webs 212 181 Victories 3 4 (5?)
$_='
 \_|_/
_/   \_
 \___/ 
 /_|_\\';
for$x(1..<>){
s|(.\S).*([/\\].)|$1$&$2|g;
s|\\(.*)/| \\_$1_/$` /$&\\ |;
s|(\s+)\K/(.*).$| \\$&/$1 /_$2_\\|
}
s|_(?=.*$)| |g;
print
#!perl -ap
$_='
 \_|_/
_/   \_
 \___/ 
 /_|_\\';
s|(.\S).*([/\\].)|$1$&$2|g,
s|\S(.*).| \\_$1_/$` /$&\\ |,
s|(\s+)\K/(.*).$| \\$&/$1 /_$2_\\|while$F[0]--;
s|_(?=.*$)| |g
#define B puts("");
#define K '\\'+'/'
#define F '_'+' '
#define P(s) putchar(s);
#define I int
c(I s,I f){if(s){P(f)c(s-1,f);P(f)}else P('|')} 
w(I lw,I s,I k,I f){if(s){P(' ')P(k)w(lw,s-1,k,f);P(K-k)P(' ')}else{P(K-k)c(1+lw,f);P(k)}}
h(I g,I s,I k,I f){I i;for(i=-1;i<g;++i)P(' ')w(g,s,k,f);} 
t(I g,I s){if(s)t(g+1,s-1);h(g,s,'/','_');B}
b(I g,I s){h(g,s,'\\',s?'_':' ');B;if(s)b(g+1,s-1);}
m(I s,I k,I f){if(s){P(f)P(k)m(s-1,k,f);P(K-k)P(f)}else{P(F-f)P(F-f)P(F-f)}}
main(I ac,char*av[]){I s;s=atoi(av[1]);t(0,s);m(1+s,'/','_');B;m(1+s,'\\',' ');B;b(0,s);}
(&)=(++) --9
f 0=[" \\_|_/","_/   \\_"," \\___/"," / | \\"] --52
f(n+1)=[s&h&u&"|"&u&g]&w(f n)&[s&g&s&"|"&s&h]where[a,b,c,d,e]=" _/\\|";[g,h]=["/","\\"];y=n+2;[u,s]=[r y b,r y a];p f s n x=let(a,b)=span(/=s)x in a&f b;i=dropWhile(==a);w[]=[];w[x]=[s&h&i(p(map(\x->if x==a then b else x))c d x)&g];w(l:e)|n==y*2-1=x%h:z|n>y=x&" "%" \\":z|n==y="_/"%"\\_":z|n<y=r(y-n)a&"\\ "%" /":z where n=length e;z=w e;x=r(n+1-y)a&g;(%)=(&).(&i l) --367
r=replicate --12
main=interact$unlines.f.read --29
spider 0=[" \\_|_/","_/   \\_"," \\___/"," / | \\"]
spider n=(s++"\\"++u++"|"++u++"/"):w m(spider(n-1))++[s++"/"++s++"|"++s++"\\"]
    where
        [a,b,c,d,e]=" _/\\|"
        [m,y]=[y*2,n+1]
        x=r y
        [u,s]=[x b,x a]
        t a b=map(\x->if x==a then b else x)
        p f s n x=let(a,b)=span(/=s)x;(c,d)=span(/=n)b in a++f c++d
        i=dropWhile(==a)
        w _[]=[]
        w _[x]=[s++"\\"++i(p(t a b)c d x)++"/"]
        w(a+1)(l:e) |a==m-1=wrapline x l"\\":z
                    |a>y=wrapline(x++" ")l" \\":z
                    |a==y=wrapline"_/"l"\\_":z
                    |a<y=wrapline(r(y-a)' '++"\\ ")l" /":z
            where
                z=w a e
                x=r(a+1-y)' '++"/"
                wrapline b l a=b++i l++a
r=replicate
main=interact$unlines.spider.read
[lcP1-d0<A]sA?sN[lK32sclAxRlNlK-l1scd0!=ARl3PlKl0sclAxRl9PlKlAxRl4PlNlK-
l2scd0!=AAPR]sW95s0124s9[ /]s1[\\ ]s292s347s4lN[dsKlWx1-d0<L]dsLx
[\\_][   ][_/][lN[rdPr1-d0<L]dsLxRRPlNlLxRR]dsBxAP[/ ][_ _][ \\]lBxAP[ \\]s1
[/ ]s247s392s41[dsKlWx1+dlN>L]dsLx32s032s9lNsKlWx
$ dc web.dc  
3
   \___|___/
   /\__|__/\ 
  / /\_|_/\ \ 
_/_/_/   \_\_\_
 \ \ \_ _/ / / 
  \ \/_|_\/ / 
   \/__|__\/ 
   /       \