# N平板斜切蛋糕

23

``````/\
\/
``````

``````/\/\
\/ /
/ /
\/
``````

``````/\/\/\
\/ / /
/ / /
\/ /
/ /
\/
``````

``````/\/\/\/\
\/ / / /
/ / / /
\/ / /
/ / /
\/ /
/ /
\/
``````

• “输出”表示打印斜线图案或将其作为字符串返回。
• 输出中允许使用单行尾换行符。
• 输出中允许尾随空格，但不允许前导空格。

Answers:

10

# Pyth，25个字节

``````j_+t.iJ*R"/ "SQ+L\\J*Q"/\
``````

### 说明：

``````j_+t.iJ*R"/ "SQ+L\\J*Q"/\   implicit: Q = input number
SQ             create the list [1, 2, ..., Q]
*R"/ "               repeat "/ " accordingly to this numbers
J                     assign this list of strings to J
+L\\J        create a 2nd list, which contains the same strings
as in J, just with a "\" prepended
.i                      interleave these two lists
t                        remove the first element
*Q"/\   repeat the string "/\" Q times
+                         append it to the list
_                          reverse it
j                           print each string on a separate line
``````

10

## CJam，32 30 29 28字节

``````ri_"/\ /"2/f*)@,\f>+_z..e>N*
``````

### 说明

``````ri       e# Read input and convert to integer N.
_        e# Duplicate.
"/\ /"2/ e# Push an array with two strings: ["/\" " /"]
f*       e# Repeat each of the two strings N times. That gives the first two rows.
)        e# Detach the second row.
@,       e# Pull up the other copy of N and turn into range [0 1 ... N-1].
\f>      e# For each element i in that range, discard the first i characters of
e# the second row.
+        e# Add all those lines back to the first row.
``````

``````/\/\/\/\
/ / / /
/ / / /
/ / /
/ / /
``````

``````/ / /
\/ /
/ / /
\/ /
/ / /
\/ /
/ /
\/
``````

``````_z   e# Duplicate the grid and transpose it.
..e> e# For each pair of characters in corresponding positions, pick the maximum.
N*   e# Join the lines by linefeed characters.
``````

7

# Japt，46 44 41 40字节

``````Uo-U £Y?"\\/"sYv)+" /"pU-Y/2 :"/\\"pU} ·
``````

### 脱节和解释

``````Uo-U mXYZ{Y?"\\/"sYv)+" /"pU-Y/2 :"/\\"pU} qR
``````

``````Uo-U    // Build an array of all integers in the range [-U, U).
mXYZ{   // Map each item X and index Y in this array with the following function.
...
} qR    // Join the resulting array with newlines.
``````

``````/\/\/\/\

\/   / / /
/    / / /
\/   / /
/    / /
\/   /
/    /
\/
``````

``````Y? ... :  // If Y, the current index, is 0,
"/\\"pU   // return the pattern "/\" repeated U*2 times.
``````

``````"\\/"s  // Otherwise, slice the pattern "\/" at
Yv)     //  if Y is even, 1; otherwise, 0.
``````

``````" /"p  // Repeat the pattern " /"
U-Y/2  //  floor(U - (Y/2)) times.
``````

5

# GNU Sed，59岁

``````s|1|/\\|gp
y|/\\| /|
s| |\\|p
:
s|\\(..)|\1|p
s|/ |\\|p
t
``````

### 测试输出：

``````\$ sed -nrf slantcake.sed <<< 111
/\/\/\
\/ / /
/ / /
\/ /
/ /
\/
\$
``````

4

# CJam，36 35 34字节

``````ri_"/\\"*N@,W%{'\'/@" /"*+_N\N}/;;
``````

``````ri_     Get input, convert to integer, and copy.
"/\\"   Pattern for first line.
*N      Repeat N times, and add a newline.
@,      Rotate N to top, and create [0 .. N-1] sequence.
W%      Invert sequence to [N-1 .. 0].
{       Loop over counts, creating two lines for each.
'\      Leading character for first in pair of lines. Rest will be the same
for both lines.
'/      First character for repeated part.
@       Rotate count to top.
" /"    Repetitive pattern.
*       Replicate it by count.
+       Concatenate with '/.
_       Copy whole thing for use as second in pair of lines.
N\      Put a newline between the pair of lines.
N       Add a newline after second line.
}/      End of loop over counts.
;;      Created an extra line, get rid of it.
``````

1

NinjaBearMonkey

GamrCorps，2015年

3

## Python 2，80个字节

``````n=input()
print"/\\"*n
for i in range(n*2,1,-1):print"\\"*(1-i%2)+"/ "*(i/2+i%2)
``````

2

## 数学，123个122 121字节

``````""<>(#<>"
"&/@Normal@SparseArray[{{i_,j_}/;2∣(i+j)&&i+j<2#+3->"/",{i_,j_}/;i~Min~j<2&&2∣i~Max~j->"\\"},{2#,2#}," "])&
``````

2

## Java-141字节

``````String a(int a){String s="";int b=-1,c,e;for(a*=2;++b<a;){for(c=-1;++c<a;)s+=(e=b+c)>a?" ":e%2==0?"/":b==0||c==0?"\\":" ";s+="\n";}return s;}
``````

## 不打高尔夫球

``````String a(int a){
String s ="";
int b=-1,c,e;
for (a*=2;++b < a;){
for (c = -1 ; ++c < a ;)
s+= (e=b+c)>a?" ": e%2==0? "/" : b==0||c==0? "\\" : " ";
s+="\n";
}
return s;
}
``````

## 输入项

``````System.out.println(a(5));
``````

## 输出量

``````/\/\/\/\/\
\/ / / / /
/ / / / /
\/ / / /
/ / / /
\/ / /
/ / /
\/ /
/ /
\/
``````

1

## Pyth，30个字节

``````*"/\\"QVr*2Q1+*\\!%N2*s.DN2"/
``````

1

# JavaScript中，128个125 123 114字节

``````n=>{r='';for(i=0;i<n;i++)r+='/\\';for(j=0;j<2*n-1;j++){r+='\n'+(j%2?'':'\\');for(i=n-j/2;i>0;i--)r+='/ '}return r}
``````

``````function c(n) {
r = '';
for (i = 0; i < n; i++) r += '/\\';
for (j = 0; j < 2 * n - 1; j++) {
r += '\n' + (j % 2 ? '' : '\\');
for (i = n - j / 2; i > 0; i--) r += '/ '
}
return r
}

alert(c(prompt()));``````

1

# Ruby，50个字节

``````->n{s='/\\'*n
n.times{|i|puts s,?\\+s='/ '*(n-i)}}
``````

``````f=->n{s='/\\'*n
n.times{|i|puts s,?\\+s='/ '*(n-i)}}
f[gets.to_i]
``````

1

# Javascript（ES6），107 104 100 98 97 91 90字节

``````p=>{s=`/\\`.repeat(p++)+`
`;for(i=p;i>2;s+='\\'+o+o)o=`/ `.repeat(--i)+`
`;return s+'\\/'}
``````

``````len => {
var str = `/\\`.repeat(len++) + '\n';

for (var i = len, mid; i > 2; str += '\\' + mid + mid) {
mid = `/ `.repeat(--i) + '\n';
}

return str + '\\/';
}
``````

107 => 104字节：@insertusername此处
97 => 90字节：@ user81655

1

insertusername此处，2015年

user81655

@ user81655啊，对此感到抱歉。感谢您向我展示该`repeat`方法。
usandfriends 2015年

1

## Python 2，66字节

``````n=input();b=1
print'/\\'*n
while~-n+b:print'\\'*b+'/ '*n;b^=1;n-=b``````

``````k=2*input()+1
print k/2*"/\\"
while k>2:print k%2*'\\'+k/2*'/ ';k-=1``````

1

## Minkolang 0.14，46字节

``````n\$z"/\"z\$D\$OlOz[" /"zi-\$Dlr\$d"\"zi1+-3&5\$X\$O].
``````

### 说明

``````n\$z               Take number from input (n) and store it in the register (z)
"/\"           Push these characters (in reverse)
z\$D        Push register value and duplicate the whole stack that many times
\$O      Output whole stack as characters
lO    Output newline

z                                   Push n from register
[                                  Open for loop that repeats n times
" /"                              Push these characters (in reverse)
zi-                           n - loop counter
\$D                         Pop k and duplicate whole stack k times
l                        Push 10 (for newline)
r                       Reverse stack
\$d                     Duplicate whole stack
"\"                  Push this character
zi1+-             0 if n = loop counter + 1, truthy otherwise
3&           Do the next three characters if top of stack is 0
5\$X        Dump the bottom-most five items of the stack
\$O      Output whole stack as characters
].    Close for loop and stop
``````

1

## 批处理，121字节

``````@echo off
set/an=%1-1
if %1==1 (echo /\%2) else call %0 %n% /\%2
set a=/\%2
echo \%a:\= %
if not \%2==\ echo %a:\= %
``````

``````@echo off
set a=%1
echo %a:1=/\%
:a
echo \%a:1=/ %
set a=%a:~1%
if not %a%1==1 echo / %a:1=/ %&goto a
``````

0

# Matlab，122个字节

``````M=2*input('');
z=zeros(M);[y,x]=ndgrid(1:M);
z(~mod(x+y,2)&x+y<M+3)=1;v=2-mod(1:M,2);
z(1,:)=v;z(:,1)=v;disp([15*z.^2+32,''])
``````

0

# Haskell，99个字节

``````f n=mapM_ putStrLn\$[[x?y|x<-[0..2*n-y-0^y]]|y<-[0..2*n-1]]
x?y|mod(x+y)2==0='/'|x*y==0='\\'|0<1=' '
``````

``````f n=mapM_ putStrLn\$[[x?y|x<-[y..2*n-0^y]]|y<-[0..2*n-1]]
x?y|mod x 2==0='/'|mod y x==0='\\'|0<1=' '
``````

0

## 哈斯克尔（96）

``````f=g.(*2)
g m=unlines\$t m(c"/\\"):[t n l|(n,l)<-zip[m,m-1..2]\$c['\\':p,p]]
p=c"/ "
c=cycle
t=take
``````

• `p` 可以内联，长度不变。
• `[t n l|(n,l)<-...]`保存2个以上`(map(uncurry t)\$...)`

0

## 锡兰，100

``````String s(Integer n)=>"\n".join{"/\\".repeat(n),for(i in 2*n+1..3)"\\".repeat(i%2)+"/ ".repeat(i/2)};
``````

``````String s(Integer n) =>
"\n".join{
"/\\".repeat(n),
for (i in 2*n + 1 .. 3)
"\\".repeat(i % 2)
+ "/ ".repeat(i / 2)
};
``````

0

## PHP，117字节

``````<?\$n=\$argv[1];\$r=str_repeat;echo\$r("/\\",\$n);for(;\$i++<\$n*2-1;)echo"\n".(\$i%2?"\\":'').\$r("/ ",\$n-floor((\$i-1)/2));?>
``````

``````<?php
error_reporting(E_ALL & ~E_NOTICE);

\$n = \$argv[1];
\$r='str_repeat';
echo \$r("/\\",\$n);
for(;\$i++<\$n*2-1;){
echo"\n".((\$i%2)?"\\":'') . \$r("/ ",\$n-floor((\$i-1)/2));
}
?>
``````

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.