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 | |
''' Geodesic distance triangulation | |
Find two locations that are at given distances | |
from two fixed points, using the WGS84 reference ellipsoid | |
First approximate using spherical trig, then refine | |
using Newton's method. |
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 | |
''' Generate all factors of m | |
Written by PM 2Ring 2016.10.20 | |
''' | |
import sys | |
from itertools import product | |
from functools import reduce |
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 | |
''' Game of Life in Numpy | |
Written by PM 2Ring 2016.11.03 | |
''' | |
import numpy as np | |
from time import sleep |
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 | |
''' zbar demo | |
Handles local files and URLs | |
Not that PIL requires ImageMagick or GraphicsMagick to display images | |
Written by PM 2Ring 2016.11.11 | |
''' |
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 | |
''' Count bits in a 32 bit Python integer | |
Speed tests of various implementations, mostly | |
from http://stackoverflow.com/questions/9829578/fast-way-of-counting-bits-in-python | |
Some of these functions work on arbitrary input, but some are specifically for | |
32 bit integers, see the function sources for detail. |
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 | |
''' Solve systems of simultaneous linear congruences using the Chinese Remainder Theorem | |
Chinese Remainder Theorem: | |
If X = r_i mod m_i for i in 1..n, m_i pairwise coprime | |
Let | |
M_i = M // m_i, y_i = M_i^(-1) mod m_i, i.e., y_i * M_i = 1 mod m_i | |
Then | |
y_i * M_i = 0 mod m_j for j != 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 | |
# -*- coding: utf-8 -*- | |
''' Sum the digits of a non-negative integer | |
Speed tests of various implementations | |
Written by PM 2Ring & hiro protagonist 2016.12.19 | |
sum_digits_hiro is faster than sum_digits_pm_map until digits=20 |
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 | |
''' Generate word squares | |
Written by PM 2Ring 1999.01.18 | |
Translated from C to Python 2017.01.20 | |
''' | |
import sys | |
from bisect import bisect_left |
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 | |
''' Transform words into 1-based indices of their letters in alphabetical order. | |
Eg 'APPLE' gets these indices: [(1, 'A'), (2, 'E'), (3, 'L'), (4, 'P'), (5, 'P')] | |
So we encode 'APPLE' as (1, 4, 5, 3, 2) | |
See http://stackoverflow.com/questions/43233004/regex-expression-to-find-words-where-you-know-the-alphabetical-order-of-the-lett | |
Written by PM 2Ring 2017.04.06 |
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 python2 | |
''' Classic Flip game, with Help function & selectable goal | |
Written by PM 2Ring 2007.12.22 | |
Updated 2011.08.07 | |
''' | |
import pygtk | |
pygtk.require('2.0') | |
import gtk, sys, random |
OlderNewer