Skip to content

Instantly share code, notes, and snippets.

@pjt33
pjt33 / MO338802.cs
Created August 26, 2019 10:53
Perfectly nonlinear involutions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace Sandbox
{
class MO338802
{
public static void Main()
@pjt33
pjt33 / Carpsen.swift
Created January 14, 2019 14:00
Eratospheres in Swift
func eratosthenesSieve(to n: Int) -> [Int] {
guard 2 <= n else { return [] }
var composites = Array(repeating: false, count: n + 1)
var primes: [Int] = []
let d = Double(n)
let upperBound = Int((d / _log(d)) * (1.0 + 1.2762/_log(d)))
primes.reserveCapacity(upperBound)
let squareRootN = Int(d.squareRoot())
@pjt33
pjt33 / mathse3015816.py
Last active December 5, 2018 11:14
MSE 3015816
#!/usr/bin/python3
import math
def phi(n):
# Naïve prime factorisation
ps = set()
m = n
while m % 2 == 0:
@pjt33
pjt33 / math2962644.sage
Last active October 20, 2018 12:55
Number of real zeroes of iterated polynomial: x^3-2x+1
from sage.rings.polynomial.real_roots import *
x = polygen(ZZ)
def conv_p(p, n):
if n == 0:
return x
else:
return p(conv_p(p, n-1))
for n in range(1, 21): print add(map(lambda (a,b): b, real_roots(conv_p(x^3-2*x-1, n))))
@pjt33
pjt33 / GaussianABC.cs
Last active April 5, 2018 16:46
Gaussian ABC conjecture
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 February 23, 2018 20:05
Finding permutations with disjoint partial sums
#!/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):
@pjt33
pjt33 / BigDecimalInterval.cs
Last active November 23, 2017 15:27
A000329
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 February 26, 2017 17:54
Calculate OEIS A003122 with heavy memoisation
#!/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:
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 October 10, 2014 14:36
Count Quoridor wall positions
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++) {