Skip to content

Instantly share code, notes, and snippets.

Felix Pahl joriki

Block or report user

Report or block joriki

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joriki
joriki / SainteLaguë.java
Created Jun 17, 2019
Allocate seats according to Sainte-Laguë
View SainteLaguë.java
package jetzt.bewegung;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class SainteLaguë {
// Sitzzuteilung an die Landeslisten der CDU zur Europawahl 2019
@joriki
joriki / Question2923530.java
Created Sep 20, 2018
Count the number of chains that can be made from the river tiles in Carcassonne; see https://math.stackexchange.com/questions/2923530.
View Question2923530.java
public class Question2923530 {
static boolean [] [] used = new boolean [23] [23];
public static void main (String [] args) {
long count = 0;
used [11] [11] = true;
for (int bits = 0;bits < 1 << 10;bits++) {
int bitCount = 0;
for (int i = 0;i < 10;i++)
if ((bits & (1 << i)) != 0)
@joriki
joriki / Question2906823.java
Created Sep 6, 2018
Confirm that the probability for a random line in a square to be the diagonal of a square contained in the square is 2/3; see https://math.stackexchange.com/questions/2906823.
View Question2906823.java
public class Question2906823 {
final static int ntrials = 100000000;
public static void main (String [] args) {
int count = 0;
for (int n = 0;n < ntrials;n++) {
double x1 = Math.random ();
double y1 = Math.random ();
double x2 = Math.random ();
double y2 = Math.random ();
@joriki
joriki / Question2906613.java
Created Sep 5, 2018
Compute the probability for a two-dimensional random walk with duplication and vanishing to produce at least one duplicate at the origin; see https://math.stackexchange.com/questions/2906613.
View Question2906613.java
public class Question2906613 {
final static int maxn = 1026;
final static int [] [] ds = {
{0,1},
{-1,0},
{0,-1},
{1,0}
};
public static void main (String [] args) {
double [] [] a = new double [maxn + 1] [maxn + 1];
@joriki
joriki / Question2898079.java
Created Aug 29, 2018
Estimate the probability for a number with independently uniformly randomly chosen decimal digits to appear periodic at some point; see https://math.stackexchange.com/questions/2898079.
View Question2898079.java
public class Question2898079 {
public static void main (String [] args) {
long count = 0;
long power = 1;
for (int n = 1;;n++) {
power *= 10;
outer:
for (long k = 0;k < power;k++) {
String s = String.valueOf (k);
while (s.length () < n)
@joriki
joriki / Question2875705.java
Created Aug 8, 2018
Estimate the expected number of draws without replacement required to draw three balls of the same colour from 64 balls with 8 balls each of 8 colours; see https://math.stackexchange.com/questions/2875705.
View Question2875705.java
import java.util.Arrays;
import java.util.Random;
public class Question2875705 {
final static Random random = new Random ();
final static int ntrials = 100000000;
public static void main (String [] args) {
long total = 0;
int [] counts = new int [8];
@joriki
joriki / Question2858152.java
Last active Jul 22, 2018
Count the number of ways that binary entropy can be at least 7 in a file of 256 characters chosen from 256 symbols; see https://math.stackexchange.com/questions/2858152.
View Question2858152.java
import java.math.BigInteger;
public class Question2858152 {
final static int ncharacters = 256;
final static int nsymbols = 256;
final static int max = Math.max (nsymbols,ncharacters) + 1;
final static BigInteger [] integers = new BigInteger [max];
final static BigInteger [] powers = new BigInteger [max];
@joriki
joriki / Question2839811.java
Last active Jul 4, 2018
Calculate and check the probability for at least one of m buckets to contain at least k of n uniformly randomly placed balls; see https://math.stackexchange.com/questions/2839811.
View Question2839811.java
import java.math.BigInteger;
public class Question2839811 {
final static int n = 180;
final static int m = 10;
final static int k = 24;
// XOR shift pseudorandom number generator because Java's built-in generator has regularities that mess up the result
static long x = 4;
static long cache;
@joriki
joriki / Question2837955.java
Created Jul 2, 2018
Calculate the probability for the lamp at the origin to be lit after n steps of a random walk on the lamplighter group; see https://math.stackexchange.com/questions/2837955.
View Question2837955.java
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
public class Question2837955 {
static class State {
boolean lamp;
int x;
public State () {}
@joriki
joriki / Question2836730.java
Created Jun 30, 2018
Calculate the expected number of elements in a rooted ordered unlabeled binary tree of maximum depth d; see https://math.stackexchange.com/questions/2836730
View Question2836730.java
import java.math.BigInteger;
public class Question2836730 {
public static void main (String [] args) {
BigInteger a = BigInteger.ONE;
BigInteger s = BigInteger.ZERO;
for (int d = 1;;d++) {
BigInteger square = a.multiply (a);
BigInteger sn = s.multiply (a).multiply (BigInteger.TWO).add (square);
You can’t perform that action at this time.