Skip to content

Instantly share code, notes, and snippets.

@joriki
joriki / Question4882568.java
Created March 18, 2024 10:57
Count the schedules for round-robin tournaments; see https://math.stackexchange.com/questions/4882568
import java.util.BitSet;
public class Question4882568 {
static boolean [] [] played;
static int count;
static int n;
public static void main (String [] args) {
for (n = 2;;n += 2) {
count = 0;
@joriki
joriki / Question4859023.java
Created February 8, 2024 08:26
Estimate the probability of a certain inequality being satisfied for uniformly distributed random variables; see https://math.stackexchange.com/questions/4859023.
public class Question4859023 {
final static long ntrials = 100000000L;
public static void main(String [] args) {
long count = 0;
for (long n = 0;n < ntrials;n++) {
double x1 = 5 * Math.random();
double x2 = 5 * Math.random();
double y1 = 5 * Math.random();
@joriki
joriki / Question4849448.java
Created January 23, 2024 14:21
Compute the value of a game of placing non-attacking kings on an n x n board; see https://math.stackexchange.com/questions/4849448.
import java.util.HashMap;
import java.util.Map;
public class Question4849448 {
final static int d = 8;
final static int n = d * d;
static long [] moves = new long [n];
static long [] [] transformedMoves = new long [n] [8];
@joriki
joriki / Question4840933.java
Last active January 11, 2024 08:52
Estimate the probability that the triangle formed by three uniformly random points on the sphere contains its circumcentre; see https://math.stackexchange.com/questions/4842652.
public class Question4840933 {
final static long ntrials = 2000000;
public static void main(String [] args) {
double [] [] x = new double [3] [3];
double [] c = new double [3];
long count = 0;
for (long n = 0;n < ntrials;n++) {
@joriki
joriki / OEISScanner.java
Created December 28, 2023 23:04
find palindromic U-shaped triangular arrays in OEIS; see https://math.stackexchange.com/questions/4835012
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
public class OEISScanner {
public static void main (String [] args) throws IOException {
// OEIS sequence data downloaded from https://oeis.org/stripped.gz
BufferedReader reader = new BufferedReader (new FileReader (args [0]));
@joriki
joriki / Question4636935.java
Created February 11, 2023 08:43
Simulate an urn where two balls of the colour drawn are added after each draw; see https://math.stackexchange.com/questions/4636935.
package info.joriki.math.stackexchange;
public class Question4636935 {
final static int ntrials = 10000;
public static void main(String [] args) {
int count = 0;
int total = 0;
for (int n = 0;n < ntrials;n++) {
int nblack = 1;
@joriki
joriki / Question4631555.java
Created February 6, 2023 12:54
Generate an orthogonal matrix and a corresponding vector that satisfy certain constraints; see https://math.stackexchange.com/questions/4631555.
import java.util.Arrays;
import java.util.Random;
public class Question4631555 {
final static int l = 4;
final static int n = (l * (l - 1)) / 2;
final static Random random = new Random();
public static void main(String [] args) {
@joriki
joriki / Question4629747.java
Created February 1, 2023 03:05
Maximize the score in a game where boxes are removed according to the sum of two dice; see https://math.stackexchange.com/questions/4629747.
package info.joriki.math.stackexchange;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import info.joriki.math.algebra.BigRational;
public class Question4629747 {
@joriki
joriki / Question4624075.java
Created January 25, 2023 15:11
Find bit strings with no pairwise XOR sums in common; see https://math.stackexchange.com/questions/4624075.
import java.util.Random;
public class Question4624075 {
final static int k = 34;
final static int n = 10;
final static int m = 1 << n;
final static int nvalues = (k * (k + 1)) / 2;
final static Random random = new Random();
@joriki
joriki / Question4622699.java
Last active March 29, 2024 20:55
Place party guests at dinner tables so they all meet each other; see https://math.stackexchange.com/questions/4622699.
import java.util.Random;
public class Question4622699 {
final static int nrounds = 7;
final static int ntables = 5;
final static int nchairs = 4;
final static int npeople = ntables * nchairs;
final static Random random = new Random();