Challenge: sum of squares. Let's break 299
|
01-25-2018, 01:47 AM
Post: #37
|
|||
|
|||
RE: Challenge: sum of squares. Let's break 299
In trying to make the code faster, I fear I may have rendered it harder to read. Sorry about that. This is based on a variation of genetic algorithms applied to graph paths but without mutation.
I'll use the solution for length 25 as an example since it's small enough to fit on a screen. First generate your square numbers and use those to calculate edges and nodes: Code:
Then create a dictionary of sets to store the edges. Code:
{1: {3, 8, 15, 24}, 2: {7, 14, 23}, 3: {1, 6, 13, 22}, 4: {5, 12, 21}, 5: {4, 11, 20}, 6: {3, 10, 19}, 7: {2, 9, 18}, 8: {1, 17}, 9: {7, 16}, 10: {6, 15}, 11: {5, 14, 25}, 12: {4, 13, 24}, 13: {3, 12, 23}, 14: {2, 11, 22}, 15: {1, 10, 21}, 16: {9, 20}, 17: {8, 19}, 18: {7}, 19: {6, 17}, 20: {5, 16}, 21: {4, 15}, 22: {3, 14}, 23: {2, 13}, 24: {1, 12, 25}, 25: {11, 24}} (see the bottleneck at 18?) 17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)