-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.py
63 lines (37 loc) · 968 Bytes
/
sms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 23 19:32:01 2016
@author:
"""
import networkx as nx
g = nx.Graph()
array=[100, 200, 300, 400]
sort=sorted(array);
def maximo(sort):
count=0
g.add_nodes_from(sort)
for i in xrange(len(sort)-1):
a=sort[i+1]
b=sort[i]
resta=a-b
if resta==1:
g.add_edge(b,a)
length=len(g.nodes())
for i in xrange(length):
node=sort[i]
nei=g.neighbors(node)
if(len(nei)==0):
#print node
g.remove_node(node)
count=count+1
length=len(g.nodes())
array=g.nodes()
for i in xrange(length):
node=array[i]
nei=g.neighbors(node)
if(len(nei)==1):
g.remove_node(node)
count=count+1
print g.nodes()
print count
respuesta= maximo (sort);