Skip to content

Instantly share code, notes, and snippets.

PM 2Ring PM2Ring

  • Australia
Block or report user

Report or block PM2Ring

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View substring_palindromes.py
#!/usr/bin/env python3
''' Substring palindromes
Find the number of ways a string can be split in a non-overlapping way
such that p+q is a palindrome string. Two pairs (p,q) and (p',q') are
treated as different iff p is chosen from different position from p' or
q is chosen from diff position of q' .
For example, take the string abba. The possible substrings which are
@PM2Ring
PM2Ring / tk_bezier_track.py
Last active Oct 10, 2018
Cubic Bezier tracks with constant speed animation, using Tkinter
View tk_bezier_track.py
#!/usr/bin/env python3
''' Create a closed track from cubic Bezier curves, and animate a circle
following the track at constant speed.
https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves
https://gist.github.com/PM2Ring/d6a19f5062b39467ac669a4fb4715779
Press the Add button to add black control dots to the Canvas. The first
@PM2Ring
PM2Ring / tk_multi_counters.py
Created Oct 7, 2018
Use Tkinter's .after method to run several named counters in parallel.
View tk_multi_counters.py
#!/usr/bin/env python3
""" Use .after to run several named counters in parallel.
Each counter prints its name and value to the terminal,
once per second.
When the 'New counter' button is clicked, a new
counter is created, using the name in `name_entry`, and
a 'Stop' button with the same name is added to the GUI.
@PM2Ring
PM2Ring / cat2.svg
Created Aug 17, 2018
Discrete catenary with vectors
View cat2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / cat0.svg
Created Aug 13, 2018
Some discrete catenaries
View cat0.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@PM2Ring
PM2Ring / cheney.ps
Created Jun 28, 2018
Generalization of the 'Fitch' Cheney card trick
View cheney.ps
#! /usr/bin/env python3
''' Generalization of the 'Fitch' Cheney card trick
Written by PM 2Ring 2003.02.13
Converted to Python 2018.06.27
'''
import sys
import readline
@PM2Ring
PM2Ring / knight_tour1.py
Created May 26, 2018
Knight tour, using a generator
View knight_tour1.py
#!/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):
@PM2Ring
PM2Ring / knight_tour.py
Created May 25, 2018
Knight tour, using recursive backtracking
View knight_tour.py
#!/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))
@PM2Ring
PM2Ring / Fenwick_demo.py
Created Jan 2, 2018
A Python version of the Fenwick tree demo code from the Wikipedia article.
View Fenwick_demo.py
#! /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):
@PM2Ring
PM2Ring / random_bits_speed_test.py
Created Dec 9, 2017
Test speeds of various ways of creating a list of random bits
View random_bits_speed_test.py
#!/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]
You can’t perform that action at this time.