Skip to content

Instantly share code, notes, and snippets.

@mpawliuk
Created March 8, 2018 19:11
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 mpawliuk/ec91468365233b2d1faf57b4bbb56b21 to your computer and use it in GitHub Desktop.
Save mpawliuk/ec91468365233b2d1faf57b4bbb56b21 to your computer and use it in GitHub Desktop.
A small Chromatic number thing for a redditor
︠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])
@mpawliuk
Copy link
Author

mpawliuk commented Mar 8, 2018

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:

You need 5 French actors.
These are the English roles the French actors will take: 
French actor 1 will play the parts: 
    [6, 10, 13, 17]
French actor 2 will play the parts: 
    [7, 3, 5, 16, 14, 9]
French actor 3 will play the parts: 
    [2, 15, 11]
French actor 4 will play the parts: 
    [12, 4]
French actor 5 will play the parts: 
    [1]

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment