跳过像兔子！

Erik the Outgolfer 08/26/2017. 30 answers, 2.887 views

[0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | []
^ First element, always include it
[0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | [0]
^ Skip 0 elements
[0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | [0, 1]
^ Skip 1 element
[0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | [0, 1, 2]
^ Skip 2 elements
[0, 1, 0, 2, 5, 1, 3, 1, 6, 2] | [0, 1, 2, 3]
Skip 3 elements; you're done

[4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2] | []
^ First element, always include it
[4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2] | [4]
^ Skip 4 elements
[4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2] | [4, 3]
^ Skip 3 elements
[4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2] | [4, 3, 3]
^ Skip 3 elements
[4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2] | [4, 3, 3, 4]
Skip 4 elements; you're done

[0, 2, 0, 2, 4, 1, 2] | []
^ First element, always include it
[0, 2, 0, 2, 4, 1, 2] | [0]
^ Skip 0 elements
[0, 2, 0, 2, 4, 1, 2] | [0, 2]
^ Skip 2 elements
[0, 2, 0, 2, 4, 1, 2] | [0, 2, 4]
Skip 4 elements; you're done (out of bounds)

规则

• 你可能不会在这些人中间使用任何无聊的欺骗手段，他们会让挑战变得无聊和无趣。
• 你只应该返回/打印最终结果。 STDERR输出被忽略。
• 您可能无法将输入作为任何基数中的一串数字输入（例如，第一种情况为“0102513162”）。
• 您必须使用从左到右的顺序输入。
• 正如在工作的例子中，如果你超出界限，执行终止，否则。
• 您应该使用0来跳过0个元素。
• 给定空列表（ [] ）作为输入，你应该返回[]

测试用例

[]                                                     => []
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]                     => [0, 1, 3, 7]
[5, 1, 2, 3, 4, 5, 2, 1, 2, 1, 0, 0]                   => [5, 2, 1, 0]
[0, 1, 0, 2, 5, 1, 3, 1, 6, 2]                         => [0, 1, 2, 3]
[4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2] => [4, 3, 3, 4]
[0, 2, 0, 2, 4, 1, 2]                                  => [0, 2, 4]

Erik the Outgolfer 07/28/2017

3 Shaggy 07/28/2017

2 Rod 07/28/2017

1 Roman Gräf 07/28/2017

1 Erik the Outgolfer 07/28/2017
@RomanGräf抱歉但不是，这会太模棱两可，因为有些情况下你应该在输出中跟踪0秒。

Rod 07/28/2017.

Python 2，36字节

f=lambda x:x and x[:1]+f(x[x[0]+1:])
Mr. Xcoder 07/28/2017

Erik the Outgolfer 07/28/2017

Rod 07/28/2017
@EriktheOutgolfer是的，但它需要是一个列表，所以它会是[x[0]]
Erik the Outgolfer 07/28/2017
@Rod你并没有用x[:1]保存任何字节，反正... f=lambda x:x and[x[0]]+f(x[x[0]+1:])

Mr. Xcoder 08/19/2017.

Python2，49 46 * 41字节

* -3 thanks to @ASCII-only

l=input()
while l:print l[0];l=l[l[0]+1:]

这个怎么用？

• l=input() - 从标准输入中读取列表。

• while l: - 滥用空列表在Python中是虚假的，循环直到列表为空。

• print l[0]; - 打印列表的第一个元素。

• l=l[l[0]+1:] - “像兔子一样跳过” - 修剪列表中的第一个l[0]+1

我们举个例子吧

ASCII-only 07/28/2017

w0lf 07/28/2017.

哈斯克尔， 29 27 26字节

j(x:y)=x:j(drop x y)
j x=x

Zgarb 07/28/2017

w0lf 07/28/2017
@Zgarb酷，谢谢！

05AB1E ， 10 9个字节

[¬Dg>#=ƒ¦

Magic Octopus Urn 07/28/2017

Martin Ender 07/28/2017.

Mathematica， 46 44字节

SequenceCases[#,NO

SequenceCases[#,NO
Mr.Wizard 07/28/2017

Johan Karlsson 07/28/2017.

JavaScript（ES6）， 4239 35字节

a=>a.map((n,i)=>a.splice(i+1,n))&&a

let f =
a=>a.map((n,i)=>a.splice(i+1,n))&&a

console.log(f([]))                                                     // => []
console.log(f([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))                     // => [0, 1, 3, 7]
console.log(f([5, 1, 2, 3, 4, 5, 2, 1, 2, 1, 0, 0]))                   // => [5, 2, 1, 0]
console.log(f([0, 1, 0, 2, 5, 1, 3, 1, 6, 2]))                         // => [0, 1, 2, 3]
console.log(f([4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2])) // => [4, 3, 3, 4]
console.log(f([0, 2, 0, 2, 4, 1, 2]))                                  // => [0, 2, 4]

旧的解决方案39字节

a=>a.map(n=>i--||r.push(i=n),r=i=[])&&r

-3 bytes thanks to @ThePirateBay

ThePirateBay 07/28/2017
39个字节a=>a.map(n=>i--||r.push(i=n),r=i=[])&&r

TheLethalCoder 07/28/2017.

C＃，68个字节

a=>{for(int i=0;i

namespace System
{
class P
{
static void Main()
{
Action> f = a =>            {
for (int i = 0; i < a.Count; i += a[i] + 1)
System.Console.Write(a[i] + " ");
};

f(new Collections.Generic.List() { });Console.WriteLine();
f(new Collections.Generic.List() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });Console.WriteLine();
f(new Collections.Generic.List() { 5, 1, 2, 3, 4, 5, 2, 1, 2, 1, 0, 0 });Console.WriteLine();
f(new Collections.Generic.List() { 0, 1, 0, 2, 5, 1, 3, 1, 6, 2 });Console.WriteLine();
f(new Collections.Generic.List() { 4, 5, 1, 3, 8, 3, 0, 1, 1, 3, 1, 2, 7, 4, 0, 0, 1, 2 });Console.WriteLine();
f(new Collections.Generic.List() { 0, 2, 0, 2, 4, 1, 2 });Console.WriteLine();

}
}
}

a=>{var l=new System.Collections.Generic.List();for(int i=0;i
2 TheLethalCoder 07/28/2017

Thomas Ayoub 07/31/2017

TheLethalCoder 07/31/2017
@ThomasAyoub我们只能假设它是有OCD的人。

Zgarb 07/28/2017.

稻壳 ， 8个 6字节

←TU¡Γ↓

-2字节（以及一个全新的解决方案概念），感谢Leo！

说明

←TU¡Γ↓  Implicit input, e.g. [0,2,0,2,4,1,2]
Γ↓  Pattern match using drop
¡    iterated infinitely: [[0,2,0,2,4,1,2],[2,0,2,4,1,2],[4,1,2],[],[],[],...
U     Cut at first repeated value: [[0,2,0,2,4,1,2],[2,0,2,4,1,2],[4,1,2],[]]
T      Transpose: [[0,2,4],[2,0,1],[0,2,2],[2,4],[4,1],[1,2],[2]]
←       First element: [0,2,4]
Leo 07/28/2017

Leo 07/28/2017
Zgarb 07/28/2017
@Leo哦，哇，这很聪明！
Erik the Outgolfer 07/28/2017

Zgarb 07/28/2017
@ErikTheOutgolfer这是一个错误（我在我的手机上，显然推了一些意外）。 我试图撤消它...

Ruud 07/28/2017.

Python2，59 55字节

l=input()
i=0
while l[i:]:i+=1;l[i:i+l[i-1]]=[]
print l
1 Rod 07/28/2017

1 ASCII-only 07/28/2017

Dave 07/28/2017.

Pyth，22字节

VQ aY.(Q0VeY .x.(Q0 ;Y

Erik the Outgolfer 07/28/2017

Dave 07/28/2017

3 Wheat Wizard 07/28/2017

isaacg 07/31/2017

Rod 07/28/2017.

Python 2,60 42字节

-18字节感谢Luis Mendo

x=input()
i=0
while 1:print x[i];i+=1+x[i]

Martin Ender 07/28/2017.

视网膜 ，36字节

.+
$* ((1)*¶)(?<-2>1*¶)*$1
%M.
\I@nO/

说明

/   Switch to Ordinal mode.
.   Duplicate it.
n   Logical NOT (gives truthy if we're at EOF).
/   Switch to Cardinal.
The IP wraps around to the left.
\   Switch to Ordinal.
\$@  Terminate the program if we're at EOF.
.   Duplicate the input line again.
O   Print it.
\   Switch to Cardinal.
h   Increment the value.
&   Store the result in the iterator queue.
The program wraps around to the beginning.

Mr.Wizard 07/28/2017.

Mathematica ，37（30？）

±NO

±NO

1 JungHwan Min 07/28/2017
±Drop[NO可以是±NO因为±的优先级低于Infix
Mr.Wizard 07/28/2017
@JungHwanMin我错过了; 谢谢！

Jenny_mathy 07/28/2017.

Mathematica，65字节

(s=#;t=1;w={};While[t<=Length@s,AppendTo[w,k=s[[t]]];t=t+k+1];w)&

w0lf 07/28/2017.

Ruby， 36 33 31

f=->l{a,*l=l;a&&f[l.drop(p a)]}
sethrin 07/30/2017

w0lf 07/30/2017
@sethrin即使我需要递归调用它？
sethrin 07/30/2017

w0lf 07/30/2017
@sethrin谢谢！ :)

AnonymousReality 07/28/2017.

Swift，63字节

func a(d:[Int]){var i=0;while i

Stephen 07/28/2017

AnonymousReality 07/28/2017
@StepHen - 谢谢！ 我想这会让我的其他版本无效。 期待更多贡献！

Perl 6,31字节

{(@_,{.[1+.[0]..*]}...^0)[*;0]}

扩展：

{  # bare block lambda with implicit parameter ｢@_｣
(
# generate a sequence

@_,

{
.[ # index into previous value in the sequence
1 + .[0]  # start by skipping one plus the first element
# of the previous value in the sequence
..  *     # use that to create a Range with no end
]
}

...^  # keep doing that until: (and throw away last value)
0     # it generates an empty list

)[ *; 0 ]  # from every value in the sequence, get the first element
}

[0, 1, 0, 2, 5, 1, 3, 1, 6, 2],
(1, 0, 2, 5, 1, 3, 1, 6, 2),
(2, 5, 1, 3, 1, 6, 2),
(3, 1, 6, 2)

Renzo 07/29/2017.

C ++（gcc），172字节

#includeint main(){std::istream& i=std::cin;char c;int a,b;while(i>>c&&i>>a){std::cout<>c&&i>>b);}std::cout<

<<(c/93?"":"]")最后只是处理[]空输入转角的情况

Erik the Outgolfer 07/30/2017

Jonathan Allan 07/29/2017.

果冻 ，8 个字节

ḢṄ‘ṫ@µL¿

怎么样？

ḢṄ‘ṫ@µL¿ - Main link: list of non-negative integers  e.g. [2,5,4,0,1,2,0]
¿ - while:           Iteration:  1                  2             3          4        5
L  -   length (0 is falsey)       7                  4             3          1        0
µ   - ...do:                                                                            stop
Ḣ        -   head (pop & modify)        2 ([5,4,0,1,2,0])  0 ([1,2,0])   1 ([2,0])  0 ([0])
Ṅ       -   print it (and yield it)   "2\n"              "0\n"         "1\n"      "0\n"
‘      -   increment                  3                  1             2          1
ṫ@    -   tail from index            [0,1,2,0]          [1,2,0]      [0]         []
-
-                       i.e. a resulting in the printing of: '''2
0
1
0
'''
Erik the Outgolfer 07/30/2017

Erik the Outgolfer 07/30/2017

Evpok 07/30/2017.

Python 3，35字节

f=lambda h=0,*t:t and[h,*f(*t[h:])]

f(*l)运行它，其中l是您的输入。 可以延伸的输入规则，但我只是喜欢高级拆包。

cliffroot 07/28/2017.

Clojure，67字节

#(nth(reduce(fn[[z k]b](if(= z 0)[b(conj k b)][(- z 1)k]))[0[]]%)1)

Python 2.4,85字节

locals()['_[1]']是。 Python为列表创建秘密名称_[1] ，同时创建它并将其存储在locals 。 名称_[2]_[3] ...也用于嵌套列表。

lambda n:[j for i,j in enumerate(n)if i==len(locals()['_[1]'])+sum(locals()['_[1]'])]

Neil 07/28/2017.

批量，69字节

:l
@if not "%1"=="" echo %1&(for /l %%i in (0,1,%1)do @shift)&goto l

（我需要() s for否则goto会在循环中发生。）