Skip to content

Instantly share code, notes, and snippets.

@mjtb49
mjtb49 / LootTableRNG.java
Last active October 12, 2025 20:24
1.20-pre4 Loot Example
import com.google.common.base.Charsets;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.google.common.primitives.Longs;
import java.util.Random;
public class LootTableRNG {
private static final HashFunction MD5 = Hashing.md5();
# 1-70 are HA
[71, 78];{2: 2, 3: 1, 5: 1, 79: 1};{67: 1, 71: 1}
[79, 80];{2: 5, 3: 1, 5: 1, 11: 1};{67: 1, 79: 1}
# 81-96 are HA
[97, 120];{2: 2, 3: 1, 5: 1, 11: 1, 13: 1};{89: 1, 97: 1}
[113, 124];{2: 1, 5: 1, 7: 1, 163: 1};{101: 1, 113: 1}
# 125-148 are HA
[149, 156];{2: 1, 5: 1, 13: 1, 157: 1};{137: 1, 149: 1}
[151, 168];{2: 1, 5: 1, 13: 1, 173: 1};{149: 1, 151: 1}
# 169-172 are HA
This file has been truncated, but you can view the full file.
# format is a closed interval solved by that line; the prime powers to add; and the prime powers to remove.
# the first 64 entries report a maximal range, but the further entries may not. There is a good chance this list could be narrowed down
# significantly by determining what intervals the later entries actually cover.
[173,242];{2: 2, 3: 1, 7: 1, 17: 1, 19: 1};{157: 1, 173: 1}
[227,255];{2: 1, 5: 1, 17: 1, 263: 1};{197: 1, 227: 1}
[256,256];{3: 2, 5: 1, 7: 1, 17: 1, 19: 1, 257: 1};{2: 1, 227: 1, 239: 1, 241: 1}
[257,306];{2: 1, 3: 1, 5: 1, 7: 1, 307: 1};{251: 1, 257: 1}
[277,330];{2: 1, 3: 1, 5: 1, 7: 1, 331: 1};{251: 1, 277: 1}
[313,360];{2: 1, 5: 1, 19: 1, 397: 1};{241: 1, 313: 1}
[359,382];{2: 2, 3: 1, 23: 1, 383: 1, 397: 1};{337: 1, 347: 1, 359: 1}
[200000, 201600], p:(449, 457, 461), q:(199999, 199967, 199961)
[201600, 208848], p:(457, 461, 463), q:(201599, 201589, 201581)
[208844, 212520], p:(461, 463, 467), q:(208843, 208837, 208807)
[212508, 214368], p:(463, 467, 479), q:(212507, 212501, 212479)
[214364, 218088], p:(467, 479, 487), q:(214363, 214351, 214309)
[218088, 229440], p:(479, 487, 491), q:(218087, 218083, 218081)
[229434, 237168], p:(487, 491, 499), q:(229433, 229423, 229409)
[237164, 241080], p:(491, 499, 503), q:(237163, 237161, 237157)
[241080, 249000], p:(499, 503, 509), q:(241079, 241069, 241067)
[248988, 253008], p:(503, 509, 521), q:(248987, 248981, 248971)
29789
29791
29803
29819
29833
29837
29851
29863
29867
29873
3229381
3254791
3270961
3291751
3305611
3324091
3349501
3377221
3395701
3414181
import math
import mpmath
from fractions import Fraction
from sympy import lcm, divisor_sigma, isprime
mpmath.mp.dps = 100
N = 67 # N = 71 can be refuted with a numerator of 2007 and denominator of 2000
SCORE_NUMERATOR = 251 # original fraction had this 2009, but this works better
@mjtb49
mjtb49 / lazy_iterate_for_ruined_portals.py
Last active July 17, 2025 21:08
Illustrating how to iterate over seeds giving a particular ruined portal without having to think about lattices. To do this in the fastest way takes lattices, but a naive iteration is perfectly possible and not much slower, and this gist is to iterate that point.
# lcg constants. Replace A and B to change indices of targeted call.
import time
A = 25214903917
B = 11
M = 1 << 48
mask = M - 1
# Can mess with this
argument_to_next_int = 25 # must not be a perfect power of 2
import java.util.*;
public class AdditionUnderXOR {
static final int SS = 1000000;
enum Ore {
COAL(60005),
IRON(60006),
import random
import itertools as iter
KING_SQUARE = (0, 0)
KING_THREATENS = {(-1, -1), (-1, 0), (-1, 1),
(0, 1), (0, -1),
(1, -1), (1, 0), (1, 1)}
MATING_SQUARES = {(-1, -1), (-1, 0), (-1, 1),
(0, 1), (0, 0), (0, -1),
(1, -1), (1, 0), (1, 1)}