# 在数组中弹跳

25

### 介绍

``````[1, 2, 3, 4, 5, 6, 7, 8, 9]
[9, 8, 7, 6, 5, 4, 3, 2, 1]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
``````

``````[1, -, -, -, 5, -, -, -, 9]
[-, 8, -, 6, -, 4, -, 2, -]
[-, -, 3, -, -, -, 7, -, -]
``````

``````[-, 2, -, -, -, 6, -, -, -]
[9, -, 7, -, 5, -, 3, -, 1]
[-, -, -, 4, -, -, -, 8, -]
``````

``````[-, -, 3, -, -, -, 7, -, -]
[-, 8, -, 6, -, 4, -, 2, -]
[1, -, -, -, 5, -, -, -, 9]
``````

``````[1, 8, 3, 6, 5, 4, 7, 2, 9]
[9, 2, 7, 4, 5, 6, 3, 8, 1]
[1, 8, 3, 6, 5, 4, 7, 2, 9]
``````

### 测试用例

``````Input:                       Output:
[1, 2, 3, 4, 5]              [1, 7, 3, 9, 5]
[6, 7, 8, 9, 0]              [6, 2, 8, 4, 0]

Input:                       Output:
[1, 2, 3, 4, 5]              [1, 2, 3, 4, 5]

Input:                       Output:
[0, 0, 0, 0, 0, 0, 0, 0]     [0, 9, 0, 9, 0, 9, 0, 100]
[9, 9, 9, 9, 9, 9, 9, 100]   [9, 0, 9, 0, 9, 0, 9, 0]
[0, 0, 0, 0, 0, 0, 0, 0]     [0, 9, 0, 9, 0, 9, 0, 100]

Input:                       Output:
[0, 1, 2, 3, 4, 5]           [0, 7, 14, 9, 4, 11]
[6, 7, 8, 9, 10, 11]         [6, 1, 8, 15, 10, 5]
[12, 13, 14, 15, 16, 17]     [12, 7, 2, 9, 16, 11]

Input:                       Output:
[0, 0, 0, 0, 0, 0]           [0, 2, 2, 6, 2, 6]
[1, 2, 3, 4, 5, 6]           [1, 0, 3, 2, 5, 2]
[2, 2, 2, 2, 2, 2]           [2, 2, 0, 4, 2, 4]
[9, 8, 7, 6, 5, 4]           [9, 2, 3, 0, 5, 2]
``````

2

lirtosiast '16

ETHproductions 2016年

1

feersum

feersum

1
@LuisMendo这是唯一的反弹方式，在第0行它不能再上涨
edc65 '16

7

## Pyth，17个字节

``````>lQC.e.>bkC+_PtQQ
``````

``````                      implicit: Q=input
>                     First
l Q                   len(Q) elements of the
C .e                  Transpose of enumerated map lambda b,k:
.>                 Rotate the kth element rightwards by
b
k               k.
C +              Transpose of: Q concatenated to
_ P t Q        itself reversed without first and last elements.
Q
``````

7

# JavaScript（ES6），70

``a=>a.map((r,k)=>r.map((e,j)=>(a[k-=d]||a[d=-d,k-=d+d]||r)[j],d=1,++k))``

``````F = a=>a.map((r,k)=>r.map((e,j)=>(a[k-=d]||a[d=-d,k-=d+d]||r)[j],d=1,++k))

test = [{
I: [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 0]
],
O: [
[1, 7, 3, 9, 5],
[6, 2, 8, 4, 0]
]
}, {
I: [
[1, 2, 3, 4, 5]
],
O: [
[1, 2, 3, 4, 5]
]
}, {
I: [
[0, 0, 0, 0, 0, 0, 0, 0],
[9, 9, 9, 9, 9, 9, 9, 100],
[0, 0, 0, 0, 0, 0, 0, 0]
],
O: [
[0, 9, 0, 9, 0, 9, 0, 100],
[9, 0, 9, 0, 9, 0, 9, 0],
[0, 9, 0, 9, 0, 9, 0, 100]
]
}, {
I: [
[0, 1, 2, 3, 4, 5],
[6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17]
],
O: [
[0, 7, 14, 9, 4, 11],
[6, 1, 8, 15, 10, 5],
[12, 7, 2, 9, 16, 11]
]
}, {
I: [
[0, 0, 0, 0, 0, 0],
[1, 2, 3, 4, 5, 6],
[2, 2, 2, 2, 2, 2],
[9, 8, 7, 6, 5, 4]
],
O: [
[0, 2, 2, 6, 2, 6],
[1, 0, 3, 2, 5, 2],
[2, 2, 0, 4, 2, 4],
[9, 2, 3, 0, 5, 2]
]
}];

console.log = x => O.textContent += x + '\n';

test.forEach(t => {
var r = F(t.I),
ok = r.join `\n` == t.O.join `\n`
console.log((ok ? 'OK' : 'KO') + '\nInput\n' + t.I.join `\n` + '\nOutput\n' + r.join `\n` + '\n')
})``````
``<pre id=O></pre>``

3

## CJam，31个 30字节

``````q~__W%1>W<+_z,_@*<zee::m>z\,<p
``````

3

# 果冻，29 25 24字节

``````ṖḊm-³;Z
,ZL€R_€/‘ż€Çị/€€
``````

2

## Ruby（2.2.2p95），124个字节

``````->*a{b=a.length;b<2?a:b.times.map{|i|d=i>0?-1:1;c=i;a[0].length.times.map{|j|r=a[c][j];c+=d;d*=-1if c==0||c==a.length-1;r}}}
``````

2

# Japt，55 49 41 39字节

``````C=2*Nl -2Nw £YoY+Ul)£NgLmX%CC-X%C)gY} ·
``````

``````           // Implicit: N = array of input arrays, U = first input array, J = -1, L = 100
// Let's use the first example. 3 input arrays, each of length 9.
C=2*Nl -2  // Set variable C to 2*N.length - 2. In the example, C is 4.
Nw      }  // Reverse N and map each index Y to:
YoY+Ul)    //  Create the range [Y...U.length+Y).
//  The first time through (Y=0), we have   [0, 1, 2, 3, 4, 5, 6, 7, 8]
£       }  //  Map each item X and index Y to:
X%C        //   Take X mod C.                          [0, 1, 2, 3, 0, 1, 2, 3, 0]
C-X%C      //   Take C - (X mod C).                    [4, 3, 2, 1, 4, 3, 2, 1, 4]
Lm         //   Take the minimum of these and 100.     [0, 1, 2, 1, 0, 1, 2, 1, 0]
Ng         //   Get the array at the resulting index.
gY         //   Get the item at index Y in this array. [1, 8, 3, 6, 5, 4, 2, 7, 9]
·          // Join the result with newlines. I guess this isn't necessary, but it helps with readability.
``````

### 非竞争版本，36字节

``````C=J+Nl)òC±C ®óUl)£NgLmX%CC-X%C)gY} ·
``````

• `ò`-与相同`o`，但返回`[X..Y]`而不是`[X..Y)`
• `ó`-与相同`o`，但返回`[X..X+Y)`而不是`[X..Y)`

2

# Python 2中，107个106 108 105 104字节

（删除了一些多余的括号）（错误的起始位置（ب_ب））（已经有该长度的列表）

``````def b(a):
r,e=len(a)-1,enumerate
print[[a[abs((i-o-r)%(r*2or 1)-r)][i]for i,_ in e(q)]for o,q in e(a)]``````

1

## APL，33个字符

``````{(⍳≢⍵){0⌷(⍺-⍳≢⍉⍵)⊖⍵⍪1↓¯1↓⊖⍵}¨⊂↑⍵}
``````

``````1 - - - - - 1 - - - -
- 2 - - - 2 - 2 - - -
- - 3 - 3 - - - 3 - 3
- - - 4 - - - - - 4 -
``````

``````1 - - - - - 1 - - - -
- 2 - - - - - 2 - - -
- - 3 - - - - - 3 - -
- - - 4 - - - - - 4 -
- - - - 3 - - - - - 3
- - - - - 2 - - - - -
``````

lstefano

1

## Clojure，125个字节

``````(fn[v](let[H(count v)r range R(r H)](for[i R](map #((v %2)%)(r(count(v 0)))(drop i(cycle(concat R(reverse(r 1(dec H))))))))))
``````