Skip to content

Instantly share code, notes, and snippets.

@mgritter
mgritter / getUpvotes.py
Created August 1, 2018 20:30
Calculate recent upvote efficiency on Steem
from steem import Steem
from steem.account import Account
import pickle
import os
userlist = 'top-users.txt'
#userlist = 'some-users.txt'
outputFile = 'rewards-shares.txt'
with open( userlist, "r" ) as f:
@mgritter
mgritter / getTweets.py
Created September 12, 2018 01:47
Retrieve a year's worth of timeline and save it to a Pandas dataframe
#!/usr/bin/python3
from twython import Twython
import json
import pprint
import pandas
from datetime import datetime, timedelta
from email.utils import parsedate_tz
with open( "secret.json", "r" ) as f:
@mgritter
mgritter / rsa_with_psuedoprimes.cpp
Created September 25, 2018 04:48
Exploring how quickly RSA breaks if one of the primes is a psuedoprime
// To compile: g++ -o rsa_with_psuedoprimes rsa_with_psuedoprimes.cpp -lgmpxx -lgmp
#include <iostream>
#include <gmp.h>
gmp_randstate_t random;
void
randomPrime( mpz_t out, int nBits ) {
mpz_init( out );
do {
@mgritter
mgritter / factor91-3sat.dimacs
Last active November 17, 2018 20:16
SUBSETSUM instance corresponding to factoring 91
c Problem generated from carry-save[n-bit] multiplication circuit
c by Paul Purdom and Amr Sabry
c
c Circuit for product = 91 [True,False,True,True,False,True,True]
c Variables for output [msb,...,lsb]: [116,115,110,105,100,96,68,37,19,11]
c Variables for first input [msb,...,lsb]: [6,5,4,3,2,1]
c Variables for second input [msb,...,lsb]: [10,9,8,7]
c
c
p cnf 116 434
@mgritter
mgritter / reduce_to_change.py
Created November 17, 2018 20:22
Implementation of 3SAT to SUBSETSUM reduction (and also via 3D Matching)
## Factoring to 3-SAT
## https://www.cs.indiana.edu/cgi-pub/sabry/cnf.html
import math
class ThreeSatInstance(object):
def __init__( self, numVariables ):
self.numVariables = numVariables
self.clauses = []
@mgritter
mgritter / rule110.py
Created November 21, 2018 22:14
rule 110 CA implementation
rule110_dict = {
"111" : "0",
"110" : "1",
"101" : "1",
"100" : "0",
"011" : "1",
"010" : "1",
"001" : "1",
"000" : "0",
@mgritter
mgritter / countkclubs.py
Created November 25, 2018 06:48
count the number of K-clubs in a set of graphs
#!/usr/bin/python3
import sys
import networkx as nx
from networkx.algorithms.distance_measures import diameter
from itertools import zip_longest, combinations
class HistogramSet(object):
def __init__( self ):
@mgritter
mgritter / cover.py
Created March 16, 2019 18:59
Cover's probability test for irrationality
import mpmath
from fractions import Fraction
def earliestDecimalMatch( f, nDigits ):
"""Return the earliest fraction in the enumeration
0/1, 1/1, 1/2, 1/3, 2/3, 1/4, 2/4, 3/4, 1/5, ...
that matches the value of f to nDigits of accuracy."""
# 3 digits: 0.333 * 1000 = 333
# Clueless search: try every possible denominator from smallest to largest
class ArrayProblem(object):
def __init__( self, array, target ):
self.array = array
self.target = target
# These counters will be exclusive, the
# range being considered is array[left:right]
self.left = 0
self.right = 0
@mgritter
mgritter / dethilbert.py
Created October 28, 2019 02:13
A sequence of determinants of points along a Hilbert curve
#!/usr/bin/python3
import matplotlib.pyplot as plt
# Code adapted from https://en.wikipedia.org/wiki/Hilbert_curve
def rot( n, x, y, rx, ry ):
if ry == 0:
if rx == 1:
x = (n-1) - x
y = (n-1) - y