Last active
July 19, 2024 17:04
-
-
Save danielvarga/fc0ab97407937b69d63f5c37e50adfef to your computer and use it in GitHub Desktop.
looking into the 160 element solution for 2-Hamming-triangle free 10d cubes
This file contains hidden or 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
| # all code written by ChatGPT | |
| # https://chatgpt.com/share/44f5f3c4-3213-445c-a824-13acd249e91b | |
| import sys | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import networkx as nx | |
| from collections import Counter | |
| def process_input(): | |
| binary_list = [] | |
| for line in sys.stdin: | |
| try: | |
| number = int(line.strip()) | |
| binary_representation = f'{number:010b}' | |
| binary_digits = [bool(int(digit)) for digit in binary_representation] | |
| binary_list.append(binary_digits) | |
| except ValueError: | |
| print("Invalid input, please enter integers only.", file=sys.stderr) | |
| # Convert the list of lists to a NumPy array | |
| binary_array = np.array(binary_list, dtype=bool) | |
| return binary_array | |
| def build_hamming_graph(bools, s): | |
| # Initialize a graph | |
| G = nx.Graph() | |
| # Add nodes to the graph | |
| num_rows = bools.shape[0] | |
| G.add_nodes_from(range(num_rows)) | |
| # Calculate Hamming distance and add edges | |
| for i in range(num_rows): | |
| for j in range(i + 1, num_rows): | |
| hamming_distance = np.sum(bools[i] != bools[j]) | |
| if hamming_distance == s: | |
| G.add_edge(i, j) | |
| return G | |
| def get_connected_components_as_subgraphs(G): | |
| # Get the connected components as subgraphs | |
| components = [G.subgraph(c).copy() for c in nx.connected_components(G)] | |
| return components | |
| def degree_histogram(G): | |
| # Get the degrees of all vertices | |
| degrees = [d for n, d in G.degree()] | |
| # Count the occurrences of each degree | |
| degree_count = Counter(degrees) | |
| # Print the histogram | |
| for degree in sorted(degree_count): | |
| print(f"{degree_count[degree]} {degree}") | |
| def count_triangles(G): | |
| # Get the number of triangles for each node | |
| triangle_counts = nx.triangles(G) | |
| # Sum the number of triangles and divide by 3 to get the total number of unique triangles | |
| total_triangles = sum(triangle_counts.values()) // 3 | |
| return total_triangles | |
| if __name__ == "__main__": | |
| bools = process_input() | |
| assert bools.shape == (160, 10) | |
| print(bools.astype(int)) | |
| G = build_hamming_graph(bools, 2) | |
| components = get_connected_components_as_subgraphs(G) | |
| assert len(components) == 2 | |
| G1, G2 = components | |
| assert G1.number_of_nodes() == G2.number_of_nodes() == 80 | |
| assert nx.is_isomorphic(G1, G2) | |
| plt.figure(figsize=(8, 6)) | |
| pos = nx.spring_layout(G1) | |
| nx.draw(G1, pos, with_labels=True, node_color='lightblue', node_size=10, edge_color='gray') | |
| plt.show() | |
| degree_histogram(G1) | |
| assert count_triangles(G) == 0 |
This file contains hidden or 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
| 2 | |
| 3 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 36 | |
| 37 | |
| 42 | |
| 43 | |
| 46 | |
| 47 | |
| 76 | |
| 77 | |
| 80 | |
| 81 | |
| 90 | |
| 91 | |
| 124 | |
| 125 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 164 | |
| 165 | |
| 178 | |
| 179 | |
| 188 | |
| 189 | |
| 214 | |
| 215 | |
| 226 | |
| 227 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 314 | |
| 315 | |
| 322 | |
| 323 | |
| 326 | |
| 327 | |
| 332 | |
| 333 | |
| 352 | |
| 353 | |
| 372 | |
| 373 | |
| 378 | |
| 379 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 432 | |
| 433 | |
| 444 | |
| 445 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 488 | |
| 489 | |
| 494 | |
| 495 | |
| 510 | |
| 511 | |
| 514 | |
| 515 | |
| 552 | |
| 553 | |
| 562 | |
| 563 | |
| 580 | |
| 581 | |
| 592 | |
| 593 | |
| 606 | |
| 607 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 626 | |
| 627 | |
| 636 | |
| 637 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 660 | |
| 661 | |
| 672 | |
| 673 | |
| 702 | |
| 703 | |
| 706 | |
| 707 | |
| 714 | |
| 715 | |
| 756 | |
| 757 | |
| 762 | |
| 763 | |
| 768 | |
| 769 | |
| 772 | |
| 773 | |
| 782 | |
| 783 | |
| 792 | |
| 793 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 842 | |
| 843 | |
| 870 | |
| 871 | |
| 874 | |
| 875 | |
| 914 | |
| 915 | |
| 918 | |
| 919 | |
| 930 | |
| 931 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 960 | |
| 961 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 996 | |
| 997 | |
| 1016 | |
| 1017 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment