Skip to content

Instantly share code, notes, and snippets.

@messa
Created October 17, 2013 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save messa/7027317 to your computer and use it in GitHub Desktop.
Save messa/7027317 to your computer and use it in GitHub Desktop.
TVS 4. cv
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
fin = ("2",)
dvojice = """
0 1
1 2
1 3
3 4
4 5
4 6
5 1
6 7
6 8
7 12
8 9
8 10
9 11
10 11
11 6
12 4
""".strip()
dvojice = [line.split() for line in dvojice.splitlines()]
print dvojice
items = dvojice
result_items = list()
while items:
new_items = list()
for item in items:
for i2 in items:
if item[1:] == i2[:-1]:
new_item = item + i2[-1:]
if i2[-1] in fin:
result_items.append(new_item)
new_items.append(new_item)
elif len(set(new_item)) != len(new_item):
result_items.append(new_item)
else:
new_items.append(new_item)
print new_items
items = new_items
print "-----"
for ri in sorted([tuple(item) for item in result_items], key=lambda item: (len(item), [int(i) for i in item])):
print ",".join(ri)
[['0', '1'], ['1', '2'], ['1', '3'], ['3', '4'], ['4', '5'], ['4', '6'], ['5', '1'], ['6', '7'], ['6', '8'], ['7', '12'], ['8', '9'], ['8', '10'], ['9', '11'], ['10', '11'], ['11', '6'], ['12', '4']]
[['0', '1', '2'], ['0', '1', '3'], ['1', '3', '4'], ['3', '4', '5'], ['3', '4', '6'], ['4', '5', '1'], ['4', '6', '7'], ['4', '6', '8'], ['5', '1', '2'], ['5', '1', '3'], ['6', '7', '12'], ['6', '8', '9'], ['6', '8', '10'], ['7', '12', '4'], ['8', '9', '11'], ['8', '10', '11'], ['9', '11', '6'], ['10', '11', '6'], ['11', '6', '7'], ['11', '6', '8'], ['12', '4', '5'], ['12', '4', '6']]
[['0', '1', '3', '4'], ['1', '3', '4', '5'], ['1', '3', '4', '6'], ['3', '4', '5', '1'], ['3', '4', '6', '7'], ['3', '4', '6', '8'], ['4', '5', '1', '2'], ['4', '5', '1', '3'], ['4', '6', '7', '12'], ['4', '6', '8', '9'], ['4', '6', '8', '10'], ['5', '1', '3', '4'], ['6', '7', '12', '4'], ['6', '8', '9', '11'], ['6', '8', '10', '11'], ['7', '12', '4', '5'], ['7', '12', '4', '6'], ['8', '9', '11', '6'], ['8', '10', '11', '6'], ['9', '11', '6', '7'], ['9', '11', '6', '8'], ['10', '11', '6', '7'], ['10', '11', '6', '8'], ['11', '6', '7', '12'], ['11', '6', '8', '9'], ['11', '6', '8', '10'], ['12', '4', '5', '1'], ['12', '4', '6', '7'], ['12', '4', '6', '8']]
[['0', '1', '3', '4', '5'], ['0', '1', '3', '4', '6'], ['1', '3', '4', '6', '7'], ['1', '3', '4', '6', '8'], ['3', '4', '5', '1', '2'], ['3', '4', '6', '7', '12'], ['3', '4', '6', '8', '9'], ['3', '4', '6', '8', '10'], ['4', '6', '8', '9', '11'], ['4', '6', '8', '10', '11'], ['5', '1', '3', '4', '6'], ['6', '7', '12', '4', '5'], ['7', '12', '4', '5', '1'], ['7', '12', '4', '6', '8'], ['8', '9', '11', '6', '7'], ['8', '10', '11', '6', '7'], ['9', '11', '6', '7', '12'], ['9', '11', '6', '8', '10'], ['10', '11', '6', '7', '12'], ['10', '11', '6', '8', '9'], ['11', '6', '7', '12', '4'], ['12', '4', '5', '1', '2'], ['12', '4', '5', '1', '3'], ['12', '4', '6', '8', '9'], ['12', '4', '6', '8', '10']]
[['0', '1', '3', '4', '6', '7'], ['0', '1', '3', '4', '6', '8'], ['1', '3', '4', '6', '7', '12'], ['1', '3', '4', '6', '8', '9'], ['1', '3', '4', '6', '8', '10'], ['3', '4', '6', '8', '9', '11'], ['3', '4', '6', '8', '10', '11'], ['5', '1', '3', '4', '6', '7'], ['5', '1', '3', '4', '6', '8'], ['6', '7', '12', '4', '5', '1'], ['7', '12', '4', '5', '1', '2'], ['7', '12', '4', '5', '1', '3'], ['7', '12', '4', '6', '8', '9'], ['7', '12', '4', '6', '8', '10'], ['8', '9', '11', '6', '7', '12'], ['8', '10', '11', '6', '7', '12'], ['9', '11', '6', '7', '12', '4'], ['10', '11', '6', '7', '12', '4'], ['11', '6', '7', '12', '4', '5'], ['12', '4', '6', '8', '9', '11'], ['12', '4', '6', '8', '10', '11']]
[['0', '1', '3', '4', '6', '7', '12'], ['0', '1', '3', '4', '6', '8', '9'], ['0', '1', '3', '4', '6', '8', '10'], ['1', '3', '4', '6', '8', '9', '11'], ['1', '3', '4', '6', '8', '10', '11'], ['5', '1', '3', '4', '6', '7', '12'], ['5', '1', '3', '4', '6', '8', '9'], ['5', '1', '3', '4', '6', '8', '10'], ['6', '7', '12', '4', '5', '1', '2'], ['6', '7', '12', '4', '5', '1', '3'], ['7', '12', '4', '6', '8', '9', '11'], ['7', '12', '4', '6', '8', '10', '11'], ['8', '9', '11', '6', '7', '12', '4'], ['8', '10', '11', '6', '7', '12', '4'], ['9', '11', '6', '7', '12', '4', '5'], ['10', '11', '6', '7', '12', '4', '5'], ['11', '6', '7', '12', '4', '5', '1']]
[['0', '1', '3', '4', '6', '8', '9', '11'], ['0', '1', '3', '4', '6', '8', '10', '11'], ['5', '1', '3', '4', '6', '8', '9', '11'], ['5', '1', '3', '4', '6', '8', '10', '11'], ['8', '9', '11', '6', '7', '12', '4', '5'], ['8', '10', '11', '6', '7', '12', '4', '5'], ['9', '11', '6', '7', '12', '4', '5', '1'], ['10', '11', '6', '7', '12', '4', '5', '1'], ['11', '6', '7', '12', '4', '5', '1', '2'], ['11', '6', '7', '12', '4', '5', '1', '3']]
[['8', '9', '11', '6', '7', '12', '4', '5', '1'], ['8', '10', '11', '6', '7', '12', '4', '5', '1'], ['9', '11', '6', '7', '12', '4', '5', '1', '2'], ['9', '11', '6', '7', '12', '4', '5', '1', '3'], ['10', '11', '6', '7', '12', '4', '5', '1', '2'], ['10', '11', '6', '7', '12', '4', '5', '1', '3']]
[['8', '9', '11', '6', '7', '12', '4', '5', '1', '2'], ['8', '9', '11', '6', '7', '12', '4', '5', '1', '3'], ['8', '10', '11', '6', '7', '12', '4', '5', '1', '2'], ['8', '10', '11', '6', '7', '12', '4', '5', '1', '3']]
[]
-----
0,1,2
5,1,2
4,5,1,2
1,3,4,5,1
3,4,5,1,2
3,4,5,1,3
4,5,1,3,4
4,6,7,12,4
5,1,3,4,5
6,7,12,4,6
6,8,9,11,6
6,8,10,11,6
7,12,4,6,7
8,9,11,6,8
8,10,11,6,8
9,11,6,8,9
10,11,6,8,10
11,6,8,9,11
11,6,8,10,11
12,4,5,1,2
12,4,6,7,12
7,12,4,5,1,2
6,7,12,4,5,1,2
11,6,7,12,4,5,1,2
9,11,6,7,12,4,5,1,2
10,11,6,7,12,4,5,1,2
8,9,11,6,7,12,4,5,1,2
8,10,11,6,7,12,4,5,1,2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment