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
#!/usr/bin/env python3 | |
''' Knight tour, using recursive backtracking | |
Version using a generator in a class | |
Written by PM 2Ring 2018.05.27 | |
''' | |
class Board: | |
def __init__(self, size): |
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
#!/usr/bin/env python3 | |
''' Knight tour, using recursive backtracking | |
Written by PM 2Ring 2018.05.25 | |
''' | |
moves = ((-2, -1), (-2, 1), (-1, -2), (-1, 2), | |
(1, -2), (1, 2), (2, -1), (2, 1)) |
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
#! /usr/bin/env python3 | |
''' Demo of the Fenwick tree, aka Binary Indexed Tree | |
See https://en.wikipedia.org/wiki/Fenwick_tree | |
Converted from C to Python by PM 2Ring | |
''' | |
def LSB(i): |
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
#!/usr/bin/env python3 | |
''' Test speeds of various ways of creating a list of random bits | |
Typical results on a 32bit 2GHz machine running Python 3.6.0 on Linux | |
null : [0.04344886299986683, 0.04375551599878236, 0.04837666000094032] | |
zipgen : [0.28622414100027527, 0.28712629300025583, 0.2921328890006407] | |
nextgen : [0.363577712998449, 0.3746541500004241, 0.3797654469999543] | |
randrange : [1.342143091998878, 1.3589175790002628, 1.3717609110008198] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
x = 632, y = 391, rule = B3/S23 | |
265b2o$265bo$257b2o3b2obo$256bo3bo3bo$240b2o13bo$240b2o13bo3bo2bo$231b | |
2o3bo6b2o10bo5bo$231bobo3bo5b3o10bo3bo4b2o12b2o$232b5o6b2o12b2o6bo13b | |
2o$233b3o4b2o9bobo9bobo$240b2o10b2o9b2o$252bo24bo$259b2o17bo$258bobo | |
17bo$260bo2$276b2o3b2o51b2o$279bo54bo$248bo27bo5bo40b2o7bobo$248b2o5b | |
2o20b2ob2o41bobo6b2o$247bobo5b2o21bobo30bo12b3o$279bo28b4o3b2o8b3o$ | |
279bo20b2o5b4o3b2o8b3o$300b2o5bo2bo3b2obob2o2bobo8b2o12b2o$307b4o4bobo | |
b2o2b2o9bo13b2o$308b4o3bob2o13bobo$240b2o69bo20b2o$241b2o$240bo34bobo$ | |
275b2o70b3o$276bo3b3o39b2o2b2o19b3o$266b2o11bo3bo37bo3b2o19bo3bo$266b | |
2o10bo5bo37b2obo77b2o$233bo44b2obob2o60b2o3b2o51bo$233b2o159b2o5bobo$ |
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
#!/usr/bin/env python3 | |
''' Detect if a list is a circular permutation of a given list | |
Written by PM 2Ring 2017.11.01 | |
''' | |
from random import seed, randrange | |
seed(42) |
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
#! /usr/bin/env python | |
''' Draw an Apollonian gasket. Non symmetrical version. | |
Recursively solves Descartes Theorem to find the circles tangent | |
to 3 circles that are tangent to each other. | |
Written by PM 2Ring 2008.09.14 | |
''' | |
import sys, colorsys |
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
#!/usr/bin/env python3 | |
''' Find combinations of integers from 3 lists that sum to the items in a target list | |
https://gist.github.com/PM2Ring/f051ab09f9074ab5a378fa30f4141352 | |
Written by PM 2Ring 2017.10.15 | |
''' | |
from itertools import product |
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
#! /usr/bin/env python3 | |
''' Test speeds of performing XOR on two bytes strings of equal length | |
Typical results on a 32bit 2GHz machine running Python 3.6.0 on Linux | |
Size: 2 Loops: 65536 | |
Verify True | |
xor_bytes_I : [0.36799076000170317, 0.3949565820003045, 0.40133740400051465] | |
xor_bytes_BLC : [0.41839819899905706, 0.4583157610031776, 0.4664555540002766] |