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


14 symbols pyth
Wed Sep 28 07:23:04 2016 Sait2000
s--J{rz7hMJtMJ
15 symbols pyth
Wed Sep 28 07:20:03 2016 Sait2000
J{rz7s--JhMJtMJ
16 symbols pyth
Wed Sep 21 03:40:39 2016 Sait2000
J{rz7sf!@J,hTtTJ
18 symbols pyth
Mon Sep 19 16:33:51 2016 Sait2000
JS.{rz7sf!@J,hTtTJ
18 symbols pyth
Mon Sep 19 16:33:51 2016 Sait2000
JS.{rz7sf!@J,hTtTJ
31 symbols bash
Mon Oct 17 07:53:28 2016 Sait2000
sed '/9/c27
/7/c0
/4/c20
/8/c8'
32 symbols bash
Mon Oct 17 07:49:22 2016 Sait2000
sed '/9/c27
/8$/c8
/8/c20
/ /c0'
36 symbols bash
Mon Oct 17 07:46:48 2016 Sait2000
sed '/^2/c20
/2 3/c8
/2 4/c27
/ /c0'
38 symbols bash
Tue Aug 16 21:58:09 2016 hidefromkgb
sed '/^2/c20
/2 3/c8
/2 4/c27
/2 5/c0'
42 symbols bash
Tue Aug 16 20:56:15 2016 hidefromkgb
sed $'/^2/c20\n/2 3/c8\n/2 4/c27\n/2 5/c0'
70 symbols perl
Thu Oct 2 14:08:28 2014 vakorol
#!/usr/bin/perl -p
$l=($n=$&)-1,$g=$n+1,!/$l|$g/&&($s+=$n)&&s/$n//g while/\d+/g;$_=$s+0
72 symbols python3
Fri Jan 15 22:10:17 2016 Sait2000
L=set(map(int,input().split()))
print(sum(a*(L-{a-1,a+1}==L)for a in L))
73 symbols perl
Thu Jul 24 02:33:30 2014 dionys
#!/usr/bin/perl -pa
@@[@F]=@F;$_=0;pop@@?($@=@@,pop@@?do{0while pop@@}:($_+=$@)):0while@@
77 symbols python3
Fri Oct 9 14:37:23 2015 BogdanShevchenko
s=0
L=set(map(int,input().split()))
for a in L:s+=a*(L-{a-1,a+1}==L)
print(s)
81 symbols python3
Fri Feb 27 05:14:13 2015 bluebear94
s=0
l=set(map(int,input().split()))
for a in l:s+=a*({a-1,a+1}&l==set())
print(s)
82 symbols python2
Fri Aug 8 03:42:13 2014 PFischbeck
l=set(map(int,raw_input().split()))
print sum([a*({a-1,a+1}&l==set()) for a in l])
84 symbols python2
Fri Aug 8 03:37:32 2014 PFischbeck
s=0
l=set(map(int,raw_input().split()))
for a in l:s+=a*({a-1,a+1}&l==set())
print s
85 symbols python3
Sun Sep 14 18:59:07 2014 z423x5c6
a=set(map(int,input().split()))
print(sum([i for i in a if 1-((i-1in a)|(i+1in a))]))
86 symbols perl
Thu Jul 24 00:46:48 2014 dionys
#!/usr/bin/perl -pa
$a[$_]=1for@F;$_=0;while(@a){if(pop@a){$i=@a;if(pop@a){0while pop@a}else{$_+=$i}}}
86 symbols python3
Sat Aug 9 00:48:02 2014 z423x5c6
a=set(map(int,input().split()))
print(sum([i for i in a if not((i-1in a)|(i+1in a))]))

View all solutions