Skip to content

Instantly share code, notes, and snippets.

@pjt33
pjt33 / GaussianABC.cs
Last active Apr 5, 2018
Gaussian ABC conjecture
View GaussianABC.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BigInteger = System.Numerics.BigInteger;
namespace Sandbox
{
// https://math.stackexchange.com/questions/2642142/complex-number-abc-conjecture
// https://stackoverflow.com/questions/2269810/whats-a-nice-method-to-factor-gaussian-integers
@pjt33
pjt33 / cs88476.py
Created Feb 23, 2018
Finding permutations with disjoint partial sums
View cs88476.py
#!/usr/bin/python3
def flatten(index_map):
flat = [0] * len(index_map)
for key in index_map.keys():
flat[index_map[key]] = key
return flat
def emit_solution(x, partial_solution):
View BigDecimalInterval.cs
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
namespace Sandbox
{
public class Rational
{
public Rational(BigInteger num, BigInteger denom)
@pjt33
pjt33 / A003122.py
Last active Feb 26, 2017
Calculate OEIS A003122 with heavy memoisation
View A003122.py
#!/usr/bin/python3
from functools import lru_cache
class Partition:
def __init__(self, maxPart, tail=None):
self.part = maxPart
self.tail = tail
if tail is None:
View A263542.cs
using System;
using System.Collections.Generic;
using System.Linq;
namespace Sandbox {
// NB This is not really "production-quality" code
class Program {
static void Main(string[] args) {
for (int m = 2; m < 7; m++) {
for (int n = 2; n <= m; n++) {
@pjt33
pjt33 / QuoridorCounter.java
Created Oct 10, 2014
Count Quoridor wall positions
View QuoridorCounter.java
import java.math.BigInteger;
import java.util.*;
public class QuoridorCounter {
public static void main(String[] args) {
List<String> rows = new ArrayList<String>();
char[] chs = new char[8];
for (int i = 0; i < 6561 /* 3^8 */; i++) {
int r = i;
for (int j = 0; j < 8; j++) {
View AbstractLattice.java
import java.awt.Point;
import java.util.*;
public abstract class AbstractLattice implements Tiling<AbstractLattice.LatticeCell> {
// Use the idea of expansion and vertex mapping from my earlier aperiod tiling implementation.
private Map<Point, Set<LatticeCell>> vertexNeighbourhood = new HashMap<Point, Set<LatticeCell>>();
private int scale = -1;
// Geometry
private final int dx0, dy0, dx1, dy1;
@pjt33
pjt33 / cairo-pentagonal.ps
Created Aug 9, 2014
Cairo pentagonal grid
View cairo-pentagonal.ps
%!PS-Adobe-2.0
%%Creator: Peter Taylor
% Force A4 portrait.
<</PageSize [595 842]>> setpagedevice
/hex {
currentpoint
8 14 rlineto
6 0 rlineto
8 -14 rlineto
View URLUtils.js
/*jslint regexp: true, maxerr: 50, indent: 2 */
(function (global) {
"use strict";
function URLUtils(url, baseURL) {
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@]*)(?::([^:@]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}
@pjt33
pjt33 / wumpus-a5.gs
Last active Aug 29, 2015
Hunt the Wumpus; refactors of Dennis' code
View wumpus-a5.gs
##
0:DBGID;
{['"#{$stderr.puts Garray.new($stack).ginspect.to_s.slice(1..-2)#'DBGID):DBGID'
}"']''*~;}:DEBUG;
##
#[5:C,]{{.{[~@]}:>~.{-1%}:<~}%.&}8*({[.<><.<><]}:&~-{99rand}$~5,{.<[.>.>]{&~}%.3{$?~!!}:Q~"You smell a wumpus.\n"{*print}:,~.4Q"You feel a breeze.\n",'"#{'C):C';STDIN.gets()}"'++~~.10/3%@3%=\5%{&2Q"You killed the wumpus."{\<{>}3rand*\1"Your arrow didn't hit anything.\n",0}if}{\;.&3Q"You fell into the pit."*}if 1$&3Q{;"You were killed by the wumpus."}*:n!}do];
#[5:C,]{{.{[~@]}:>~.{-1%}:<~}%.&}8*({[.<><.<><]}:&~-{99rand}$~5,{.<[.>.>].{&3{$?~!!}:Q~'You smell a wumpus.\n'{*print}:,~}/.{&4Q'You feel a breeze.\n',}/'"#{'C):C';STDIN.gets()}"'++~~.10/3%@=\5%{&2Q'You killed the wumpus.'{\<{>}3rand*\1"Your arrow didn't hit anything.\n",0}if}{\;.&3Q'You fell into the pit.'*}if 1$&3Q{;'You were killed by the wumpus.'}*:n!}do];
#[5:C,]{{.{[~@]}:>~.{-1%}:<~}%.&}8*({[.<><.<><]}:&~-{99rand}$~5,{.<[.>.>].{3{$\&\?~!!}:Q~'You smell a wumpus.\n'{*print}:,~}/.{4Q'You feel a breeze.\n',}/'"#{'C):C';STDIN.gets()}"'++~~.
You can’t perform that action at this time.