Neighbours

Given a list of integers (string of integers separated by a space).
To bring the sum of all numbers n from the list, such that in the list there are no n-1 and n+1.

IN

1 2 5 4 3 6 7

OUT

0

IN

2 4 6 8 2

OUT

20

IN

1 8 2 3 5 6 8

OUT

8

IN

1 2 4 8 12 15 7 8 5 9

OUT

27

IN

15

OUT

15

IN

3

OUT

3
Login to submit solution


13 symbols php failed test 1 Wrong answer
1 2 5 4 3 6 7
instead of
0
Thu Jul 24 02:33:28 2014 Rocky Moon
1 2 5 4 3 6 7
75 symbols python3 failed test 2 Wrong answer
0
instead of
20
Sun Sep 14 19:36:42 2014 z423x5c6
a=set(map(int,input().split()))
print(sum([i*({i-1,i+1}&a=={})for i in a]))
77 symbols python3 failed test 2 Wrong answer
0
instead of
20
Sun Sep 14 19:37:38 2014 z423x5c6
a=set(map(int,input().split()))
print(sum([i*(({i-1,i+1}&a)=={})for i in a]))
64 symbols python3 failed test 5 Code error

Traceback (most recent call last): File "./code", line 1, in <module> print({28:0,22:20,33:8,71:27}[sum(map(int,input().split(' ')))]) KeyError: 15

Wed Jan 14 03:39:26 2015 beched
print({28:0,22:20,33:8,71:27}[sum(map(int,input().split(' ')))])
54 symbols python3 failed test 5 Code error

Traceback (most recent call last): File "./code", line 1, in <module> print({5:0,6:20,2:8,4:27}[int(input().split(' ')[2])]) IndexError: list index out of range

Wed Jan 14 15:05:45 2015 beched
print({5:0,6:20,2:8,4:27}[int(input().split(' ')[2])])
50 symbols python3 failed test 1 Wrong answer
20
instead of
0
Wed Jan 14 15:07:52 2015 beched
print([0,0,27,0,20][int(input().split(' ')[2])-1])
50 symbols python3 failed test 3 Wrong answer
0
instead of
8
Wed Jan 14 15:08:15 2015 beched
print([0,0,27,0,20][int(input().split(' ')[2])-2])
50 symbols python3 failed test 5 Code error

Traceback (most recent call last): File "./code", line 1, in <module> print([8,0,27,0,20][int(input().split(' ')[2])-2]) IndexError: list index out of range

Wed Jan 14 15:08:32 2015 beched
print([8,0,27,0,20][int(input().split(' ')[2])-2])
36 symbols perl failed test 5 Wrong answer
27
instead of
15
Wed Jan 14 20:05:45 2015 vakorol
#!/usr/bin/perl -p
/.$/;$_=[20,0,8,27]->[$&<3?0:$&-6]
116 symbols php failed test 1 Wrong answer
<? $a=array_unique(explode(' ',fgets(STDIN)));foreach($a as$x){$s+=$x*!in_array($x-1,$a)*!in_array($x+1,$a);}echo$s;
instead of
0
Fri Jan 16 10:07:54 2015 BlackFan
<? $a=array_unique(explode(' ',fgets(STDIN)));foreach($a as$x){$s+=$x*!in_array($x-1,$a)*!in_array($x+1,$a);}echo$s;
77 symbols python3 failed test 1 Code error

Traceback (most recent call last): File "./code", line 3, in <module> for a in l:s+=a*(I-{a-1,a+1}==I) NameError: name 'I' is not defined

Fri Oct 9 14:36:23 2015 BogdanShevchenko
s=0
l=set(map(int,input().split()))
for a in l:s+=a*(I-{a-1,a+1}==I)
print(s)
40 symbols bash failed test 1 Code error

sed: can't read /^2/c20 /2 3/c27 : No such file or directory sed: can't read /^2/c20 /2 3/c0 : No such file or directory sed: can't read /^2/c20 /2 4/c8 : No such file or directory sed: can't read /^2/c20 /2 4/c27 : No such file or directory sed: can't read /^2/c20 /2 4/c0 : No such file or directory sed: can't read /^2/c20 /2 5/c8 : No such file or directory sed: can't read /^2/c20 /2 5/c27 : No such file or directory sed: can't read /^2/c20 /2 5/c0 : No such file or directory

Tue Aug 16 21:06:25 2016 hidefromkgb
sed $'/^2/c20\n/2 '{3..5}/c{8,27,0}$'\n'
15 symbols pyth failed test 1 Code error

Traceback (most recent call last): File "/usr/bin/pyth.py", line 713, in <module> exec(py_code_line, environment) File "<string>", line 3, in <module> TypeError: join() missing 1 required positional argument: 'a'

Wed Sep 28 07:19:30 2016 Sait2000
J{rz7s--JhMjtMj

View all solutions