Skip to content

Instantly share code, notes, and snippets.

View david-r-cox's full-sized avatar
👋

David Cox david-r-cox

👋
View GitHub Profile
@david-r-cox
david-r-cox / Dockerfile
Created January 3, 2023 02:37
Dockerfile for github.com/yuce/pyswip/pull/133 (swi-prolog-8.5.3-support)
FROM ubuntu:jammy-20221130
RUN apt update && apt install -y \
build-essential cmake ninja-build pkg-config \
ncurses-dev libreadline-dev libedit-dev \
libgoogle-perftools-dev \
libgmp-dev \
libssl-dev \
unixodbc-dev \
zlib1g-dev libarchive-dev \
libossp-uuid-dev \
@david-r-cox
david-r-cox / rho.py
Last active May 6, 2024 06:14
Python implementation of Pollard's Rho method for factoring integers
#!/usr/bin/python2.7
# David Cox 2016
from fractions import gcd
def pollards_rho(n):
x = 2; y = 2; d = 1
f = lambda x: (x**2 + 1) % n
while d == 1:
x = f(x); y = f(f(y))
d = gcd(abs(x-y), n)
@david-r-cox
david-r-cox / foobar.py
Created August 10, 2016 05:07
More code from my attempt Google's Foobar challenge
from math import sqrt, log, floor, fabs
# computes the distance between two points
def dist(A, B):
return sqrt( (A[0]-B[0])**2 + (A[1]-B[1])**2 )
# simple triangle class
class triangle:
def __init__(self, vertices):
self.A, self.B, self.C = vertices[0], vertices[1], vertices[2]
@david-r-cox
david-r-cox / mimic_text.py
Last active April 4, 2016 22:53
Mimic a body of text using a very simply Markov model
#!/usr/bin/python2.7
from random import choice
from sys import argv
def word_map(text):
''' Maps each word to a list of all words that follow it. '''
D = {w : [] for w in text}; D[''] = text
[D[w].append(text[i+1]) for i, w in enumerate(text) if i < len(text)-1]
return D

Keybase proof

I hereby claim:

  • I am davidcox143 on github.
  • I am davidcox (https://keybase.io/davidcox) on keybase.
  • I have a public key whose fingerprint is 715B 891A 68EA 8CC5 0170 9AD7 3834 95CA 461C C954

To claim this, I am signing this object: