Gather data

This commit is contained in:
mike
2026-01-07 00:30:47 +01:00
parent 5c5462085c
commit 243935e73a
4 changed files with 55 additions and 67 deletions

View File

@@ -123,7 +123,7 @@ public final class ExportFormat {
List<int[]> cells = new ArrayList<>();
for (int i = 0; i < s.len(); i++) {
cells.add(new int[]{ s.rs()[i], s.cs()[i] });
cells.add(new int[]{ s.r(i), s.c(i) });
}
// Canonicalize: always output right/down

View File

@@ -160,14 +160,14 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
static record Lemma(int index, String word, int length, int simpel, ArrayList<String> clue) {
static int LEMMA_COUNTER = 0;
public Lemma(int index, String word, int simpel, int score, String clu) {
public Lemma(int index, String word, int simpel, String clu) {
this(index, word, word.length(), simpel, new ArrayList<String>(10));
clue.add(clu);
}
public Lemma(String word, int simpel, int score, String clue) { this(LEMMA_COUNTER++, word, simpel, score, clue); }
char charAt(int idx) { return word.charAt(idx); }
@Override public int hashCode() { return index; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
char charAt(int idx) { return word.charAt(idx); }
@Override public int hashCode() { return index; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
}
public static record Dict(Lemma[] wordz,
@@ -237,7 +237,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
if (map.containsKey(s)) {
map.get(s).clue.add(rawClue);
} else {
map.put(s, new Lemma(s, simpel, score, rawClue));
map.put(s, new Lemma(s, simpel, rawClue));
}
}
} else {
@@ -277,7 +277,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
}
var first = lists.get(0);
var cur = Arrays.copyOf(first.data(), first.size());
var cur = first.data();//Arrays.copyOf(first.data(), first.size());
var curLen = cur.length;
for (var k = 1; k < lists.size(); k++) {
@@ -291,11 +291,14 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
return new CandidateInfo(cur, curLen);
}
static record Slot(String key, int clueR, int clueC, int dir, int[] rs, int[] cs, int len, boolean horiz) {
static record Slot(String key, int clueR, int clueC, int dir, long rs, long cs, int len, boolean horiz) {
public Slot(int clueR, int clueC, int d, int[] rs, int[] cs) {
this(clueR + "," + clueC + ":" + d, clueR, clueC, d, rs, cs, rs.length, d == 2 || d == 4);
public Slot(int clueR, int clueC, int d, long rs, long cs, int len) {
this(clueR + "," + clueC + ":" + d, clueR, clueC, d, rs, cs, len, d == 2 || d == 4);
}
public int r(int i) { return (int) ((rs >> (i << 2)) & 15); }
public int c(int i) { return (int) ((cs >> (i << 2)) & 15); }
}
ArrayList<Slot> extractSlots(Grid grid) {
@@ -311,21 +314,21 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
if (rr < 0 || rr >= H || cc < 0 || cc >= W) continue;
if (grid.isDigitAt(rr, cc)) continue;
var rs = new int[MAX_LEN + 1];
var cs = new int[MAX_LEN + 1];
var n = 0;
long packedRs = 0;
long packedCs = 0;
var n = 0;
while (rr >= 0 && rr < H && cc >= 0 && cc < W) {
if (grid.isDigitAt(rr, cc)) break;
rs[n] = rr;
cs[n] = cc;
packedRs |= (long) rr << (n << 2);
packedCs |= (long) cc << (n << 2);
n++;
rr += dr;
cc += dc;
if (n > MAX_LEN) break;
if (n >= 12) break;
}
slots.add(new Slot(r, c, d, Arrays.copyOf(rs, n), Arrays.copyOf(cs, n)));
slots.add(new Slot(r, c, d, packedRs, packedCs, n));
}
}
return slots;
@@ -369,7 +372,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
}
for (var i = 0; i < s.len; i++) {
int r = s.rs[i], c = s.cs[i];
int r = s.r(i), c = s.c(i);
if (s.horiz) covH[r][c] += 1;
else covV[r][c] += 1;
}
@@ -609,7 +612,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
static char[] patternForSlot(Grid grid, Slot s) {
var pat = new char[s.len];
for (var i = 0; i < s.len; i++) {
var ch = grid.getCharAt(s.rs[i], s.cs[i]);
var ch = grid.getCharAt(s.r(i), s.c(i));
if (isLetter(ch)) pat[i] = ch;
}
return pat;
@@ -617,7 +620,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
static int slotScore(int[][] cellCount, Slot s) {
var cross = 0;
for (var i = 0; i < s.len; i++) cross += (cellCount[s.rs[i]][s.cs[i]] - 1);
for (var i = 0; i < s.len; i++) cross += (cellCount[s.r(i)][s.c(i)] - 1);
return cross * 10 + s.len;
}
@@ -629,7 +632,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
var n = 0;
for (var i = 0; i < s.len; i++) {
int r = s.rs[i], c = s.cs[i];
int r = s.r(i), c = s.c(i);
char cur = grid.getCharAt(r, c);
var ch = w.charAt(i);
if (cur == C_DASH) {
@@ -666,7 +669,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
var assigned = new HashMap<String, Lemma>();
var cellCount = new int[H][W];
for (var s : slots) for (var i = 0; i < s.len; i++) cellCount[s.rs[i]][s.cs[i]]++;
for (var s : slots) for (var i = 0; i < s.len; i++) cellCount[s.r(i)][s.c(i)]++;
var t0 = System.currentTimeMillis();
final var lastLog = new java.util.concurrent.atomic.AtomicLong(t0);
@@ -764,7 +767,7 @@ public record SwedishGenerator(int W, int H, int SIZE, int MAX_LEN, int[] buff)
if (used.get(w.index())) return false;
for (var i = 0; i < pat.length; i++) {
// if ((pat[i] != w.charAt(i)) != (pat[i] != C_DASH)) throw new RuntimeException("word does not match pattern");
// if ((pat[i] != w.charAt(i)) != (pat[i] != C_DASH)) throw new RuntimeException("word does not match pattern");
if (pat[i] != C_DASH && pat[i] != w.charAt(i)) return false;
}