Skip to content

Instantly share code, notes, and snippets.

View orlp's full-sized avatar
⚠️
This user's social credit score is unknown.

Orson Peters orlp

⚠️
This user's social credit score is unknown.
View GitHub Profile
use std::collections::HashMap;
use rand::{Rng, seq::SliceRandom};
use std::time::Instant;
fn rand_input(rng: &mut impl Rng) -> String {
let theirs = ["A", "B", "C"].choose(rng).unwrap();
let ours = ["X", "Y", "Z"].choose(rng).unwrap();
format!("{theirs} {ours}\n")
}
@orlp
orlp / 1_18_seeds.csv
Created December 2, 2021 10:56
Minecraft 1.18 seeds
seed shx shy mushroom outpost fortress frozen warm desert
6549009348085030062 2272 -1244 232052 1899 860 1534 384 923
992588754612856117 -1960 -1800 218284 2314 240 2384 2072 1897
8115723686485296971 -1928 -736 211024 2050 830 2960 467 1272
-5535894614307895477 1980 -1384 205828 2028 819 555 1679 2017
-79422374837388415 2516 200 205212 2110 583 2079 966 1089
7770996459503435924 1912 -1764 202200 2134 927 2921 224 961
4966063911710165295 -2264 476 199088 2865 478 3348 339 782
-2080965392937654313 1856 1508 197172 2072 965 2482 1477 1650
3906848925020110572 -2000 684 194548 1396 112 2851 1137 1173
from collections import defaultdict
import sys
import pulp
class keydefaultdict(defaultdict):
def __missing__(self, key):
ret = self[key] = self.default_factory(key)
return ret
def horiz_disjoint(xvals):
@orlp
orlp / vose_alias_method.py
Last active November 19, 2020 02:55
A succint numpy implementation of Vose's Alias Method, an O(n) construction O(1) sampling time algorithm for a fixed, weighted distribution.
import numpy as np
from collections import deque
class VoseAliasMethod:
# Vose's Alias Method as described at https://www.keithschwarz.com/darts-dice-coins/.
def __init__(self, weights):
pmf = weights / np.sum(weights)
self.n = pmf.shape[0]
self.prob = np.zeros(self.n, dtype=np.float64)
self.alias = np.zeros(self.n, dtype=np.int64)
use std::collections::{HashSet, HashMap};
#[derive(Clone, Debug)]
struct CountBucket {
prev: i64,
next: i64,
indices: HashSet<usize>,
}
use slotmap::{SlotMap, SecondaryMap, new_key_type, Key};
use std::collections::HashSet;
new_key_type! {
struct BucketKey;
}
new_key_type! {
struct IndexKey;
}
@orlp
orlp / mazejudge.py
Last active January 17, 2021 10:58
import collections
import numpy as np
import scipy.sparse
import scipy.sparse.linalg
import sys
import imageio
import io
import base64
class MazeJudge:
import numpy as np
def expected_time_to_solve(N):
A = np.zeros((4*(N+2), 4*(N+2)))
# (n, forward) => (4n + 0), (n, backward) => (4n + 1), (n, inside) => (4n + 2), (n, facewall) => (4n + 3)
for i in range(4*(N+2)):
if i < 4:
A[i,4] = 1
elif i >= 4*(N+1):
A[i,i] = 1
import itertools as it
import networkx as nx
import math
K = 3
N = math.factorial(K) + K - 1
print("Constructing sets")
left = list(it.permutations(range(N)))
right = sorted({(p[:cloth] + p[cloth+K:], cloth) for p, cloth in it.product(it.permutations(range(N)), range(N-K+1))})

Villager mechanics in 1.14. All this data has been deduced by using the following commands:

/data get entity @e[type=minecraft:villager,limit=1,sort=nearest] Brain.memories
/execute as orlp at orlp run tellraw @s {"nbt":"Brain.memories","entity":"@e[type=villager,sort=nearest,limit=1]"}

A villager is awake from 0-11999 and tries to sleep between 12000 and 23999.

A villager will claim a bed if: