Created
March 8, 2018 19:11
-
-
Save mpawliuk/ec91468365233b2d1faf57b4bbb56b21 to your computer and use it in GitHub Desktop.
A small Chromatic number thing for a redditor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
︠from sage.graphs.graph_coloring import vertex_coloring | |
# This is the list of English actors in the order they appear | |
english_actor_sequence = [ | |
1, 2, 3, 1, 5, 4, 2, 6, 1, 3, | |
2, 9, 6, 3, 10, 11, 3, 2, 12, 1, | |
13, 14, 12, 2, 7, 6, 1, 13, 11, 5, | |
13, 15, 7, 12, 10, 16, 17, 2, 3, 6, | |
12, 17, 15, 5, 4, 13, 2, 7, 1, 14, | |
10, 15, 9, 4, 2] | |
# Two French actors cannot take roles of English actors in consecutive scenes | |
actor_pairs = [(english_actor_sequence[i],english_actor_sequence[i+1]) for i in range(len(english_actor_sequence) - 1)] | |
# Create a graph where the English actors are nodes, the edges are whether two English actors are in consecutive scenes | |
# Multiedges are not needed | |
scene_graph = Graph(actor_pairs, multiedges=False) | |
# Show the graph before colouring | |
scene_graph.graphplot(layout='circular').show(figsize=[6,6]) | |
# Display the info | |
print 'You need %d French actors.' % vertex_coloring(scene_graph, value_only=True) | |
print 'These are the English roles the French actors will take: ' | |
for i in range(vertex_coloring(scene_graph, value_only=True)): | |
print 'French actor %d will play the parts: ' % (i+1) | |
print vertex_coloring(scene_graph)[i] | |
#Show the coloured graph | |
scene_graph.graphplot(layout='circular', partition=vertex_coloring(scene_graph)).show(figsize=[6,6]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code for this comment:
https://www.reddit.com/r/math/comments/82yzln/if_i_had_a_sequence_of_16_actors_some_recurring/
Here's the output:
Here's the picture:
https://cocalc.com/blobs//home/user/.sage/temp/project-fbeb3d9c-3251-4e88-9e27-82a1c37642e1/270/tmp_uijHct.svg?uuid=3877e5a6-2b20-41df-b57d-9d862c4d7394