Skip to content

Instantly share code, notes, and snippets.

@mgritter
mgritter / icon_nnmf.py
Last active October 24, 2016 04:11
Iteration 2 of using NNMF to blend pixel art
from scipy.misc import imread
import numpy as np
# These are flower images from the PROJCAM garden bundle.
path = "C:\Users\Mark\Documents\ProcJam\PROCJAM2016-Tess2D\PROCJAM2016-Tess2D\Garden\\"
names = [ "flower{:02d}.png".format( i ) for i in xrange( 0, 22 ) ]
original = [ imread( path + name ) for name in names ]
def flatten( image ):
@mgritter
mgritter / icon_nnmf.py
Last active October 24, 2016 06:01
Iteration 3 of NNMF project for blending pixel art
from scipy.misc import imread
import numpy as np
# These are flower images from the PROJCAM garden bundle.
path = "C:\Users\Mark\Documents\ProcJam\PROCJAM2016-Tess2D\PROCJAM2016-Tess2D\Garden\\"
names = [ "flower{:02d}.png".format( i ) for i in xrange( 0, 22 ) ]
original = [ imread( path + name ) for name in names ]
def flatten( image ):
0x0748bd33b4f11064f70cb9e2d56534cdb7dfa40c
import heapq
import math
from fractions import gcd
D = 33
n = 10000
mx = int( math.sqrt( n ) )
my = int( math.sqrt( n / D ) )
@mgritter
mgritter / main.rs
Created November 29, 2017 08:33
Advent of Code 2016 day 1 solution in Rust
const INPUT : &str = "R4, R4, L1, R3, L5, R2, R5, R1, L4, R3, L5, R2, L3, L4, L3, R1, R5, R1, L3, L1, R3, L1, R2, R2, L2, R5, L3, L4, R4, R4, R2, L4, L1, R5, L1, L4, R4, L1, R1, L2, R5, L2, L3, R2, R1, L194, R2, L4, R49, R1, R3, L5, L4, L1, R4, R2, R1, L5, R3, L5, L4, R4, R4, L2, L3, R78, L5, R4, R191, R4, R3, R1, L2, R1, R3, L1, R3, R4, R2, L2, R1, R4, L5, R2, L2, L4, L2, R1, R2, L3, R5, R2, L3, L3, R3, L1, L1, R5, L4, L4, L2, R5, R1, R4, L3, L5, L4, R5, L4, R5, R4, L3, L2, L5, R4, R3, L3, R1, L5, R5, R1, L3, R2, L5, R5, L3, R1, R4, L5, R4, R2, R3, L4, L5, R3, R4, L5, L5, R4, L4, L4, R1, R5, R3, L1, L4, L3, L4, R1, L5, L1, R2, R2, R4, R4, L5, R4, R1, L1, L1, L3, L5, L2, R4, L3, L5, L4, L1, R3";
#[derive(Debug)]
enum Heading {
North,
South,
East,
West
}
@mgritter
mgritter / enumeratemazes.py
Created March 6, 2018 22:53
Enumeration of spanning subgraphs of the NxN grid
# Problem:
# How many possible mazes are there on an NxN grid? Where a maze is a
# collection of links between grid nodes such that each node has 1-4 links
# and has a path to every other node.
# -- @relsqui, https://twitter.com/relsqui/status/970555868390465536
#
# This counting approach implements a method similar to that described in
# "Spanning Trees in Grid Graphs", Paul Raff, https://arxiv.org/pdf/0809.2551.pdf
#
# The key idea is to create a transition matrix counting the number of
@mgritter
mgritter / ghost.py
Created March 23, 2018 04:15
Solver for 'ghost' word game
words = set()
with open( "sowpods.txt", "r" ) as wordFile:
for x in wordFile:
words.add( x.rstrip() )
maxLen = max( len(x) for x in words )
alphabet = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
var shuffleGrammar = {
"origin": "#buildstack##element##element##element##element##element##element##element##element##element#",
"element" : "#stack#[stack:POP]",
"e1" : "[stack:1][e1:]",
"e2" : "[stack:2][e2:]",
"e3" : "[stack:3][e3:]",
"e4" : "[stack:4][e4:]",
"e5" : "[stack:5][e5:]",
"e6" : "[stack:6][e6:]",
"e7" : "[stack:7][e7:]",
@mgritter
mgritter / cubesquaresearch.py
Created June 25, 2018 03:34
Brute force search for squares that are the difference of a K'th power and a cube
import heapq
from fractions import gcd
import math
import sys
import time
def initialValue( maxA, b, power ):
y = b ** power
# Better too low than too high and miss one
a = min( int( math.ceil( math.pow( y, 1.0 / 3.0 ) ) ),
@mgritter
mgritter / blocksByDate.py
Created July 27, 2018 21:56
Find an interval within the Steem blockchain
#!/usr/bin/python3
from steem import Steem
from pprint import pprint
import sys
startTime = "2018-05-01T00:00:00"
endTime = "2018-05-31T23:59:59"
if len( sys.argv ) > 1: