mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 months ago
8 changed files with 6 additions and 21669 deletions
@ -1,71 +0,0 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import re |
|||
|
|||
# (type_id, pattern_id): (load_factor_a, coff, load_factor_b) |
|||
type data_type = dict[tuple[int, int], tuple[float, float, float]] |
|||
|
|||
|
|||
def load_data(lines: list[str]) -> data_type: |
|||
result = {} |
|||
key, items = (), [] |
|||
for line in lines: |
|||
if line.startswith('['): |
|||
match = re.match(r'^\[(\d+), (\d+)]$', line) |
|||
key = (int(match[1]), int(match[2])) |
|||
elif not line: |
|||
assert len(key) == 2 |
|||
assert items[0][0] == 1.0 |
|||
if len(items) == 1: |
|||
assert items[0][1] < 0.1 # skip low cases |
|||
else: |
|||
assert len(items) == 2 |
|||
result[key] = items[0][1], items[1][0], items[1][1] |
|||
key, items = (), [] |
|||
else: |
|||
match = re.match(r'^(\d\.\d{2}), (\d\.\d{6})$', line) |
|||
items.append((float(match[1]), float(match[2]))) |
|||
return result |
|||
|
|||
|
|||
def analyse_data(data: data_type) -> None: |
|||
data = {x: y for x, y in data.items() if y[0] >= 0.5} |
|||
|
|||
times = set([int(x * 1000 / y) / 1000 for x, _, y in data.values()]) |
|||
print(sorted(times)) |
|||
|
|||
type_a, type_b, type_c = [], [], [] |
|||
for group, (load_factor, coff, _) in data.items(): |
|||
if load_factor <= 0.55: |
|||
type_a.append((group, load_factor, coff)) |
|||
elif coff <= 1.3: |
|||
type_b.append((group, load_factor, coff)) |
|||
else: |
|||
type_c.append((group, load_factor, coff)) |
|||
|
|||
type_c = sorted(type_c, key=lambda x: x[2]) |
|||
for item in type_c: |
|||
print(item) |
|||
|
|||
# ((117, 0), 0.571359, 1.54) -> 4680 |
|||
# ((118, 0), 0.571298, 1.54) -> 37440 |
|||
# ((133, 0), 0.570803, 1.54) -> 149632 |
|||
# ((134, 0), 0.570558, 1.54) -> 299136 |
|||
|
|||
# ((63, 0), 0.568915, 1.55) -> 582 |
|||
# ((136, 0), 0.565568, 1.55) -> 296520 |
|||
|
|||
# ((112, 0), 0.563973, 1.56) -> 36960 |
|||
# ((113, 0), 0.563969, 1.56) -> 73920 |
|||
|
|||
# ((197, 0), 0.714286, 1.6) -> 5 |
|||
# ((197, 1), 0.714286, 1.6) -> 5 |
|||
# ((197, 2), 0.714286, 1.6) -> 5 |
|||
# ((197, 3), 0.714286, 1.6) -> 5 |
|||
# ((197, 4), 0.714286, 1.6) -> 5 |
|||
# ((197, 5), 0.714286, 1.6) -> 5 |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
raw = open('load_factor.txt').read().splitlines() |
|||
analyse_data(load_data(raw)) |
File diff suppressed because it is too large
@ -1,19 +0,0 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import json |
|||
|
|||
data_legacy = json.loads(open('legacy.json').read()) |
|||
data_next = json.loads(open('data.json').read()) |
|||
|
|||
assert len(data_legacy) == len(data_next) |
|||
|
|||
if __name__ == '__main__': |
|||
for info in data_legacy: |
|||
code = f'{info['code']}00' |
|||
info_next = data_next[code] |
|||
|
|||
assert info['min_solution_step'] == info_next['min_step'] |
|||
assert info['farthest_step'] == info_next['max_step'] |
|||
|
|||
assert info['min_solution_case'] == sorted([x[:7] for x in info_next['solutions']]) |
|||
assert info['farthest_case'] == sorted([x[:7] for x in info_next['furthest']]) |
@ -1,65 +0,0 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import re |
|||
import json |
|||
|
|||
|
|||
def split_item(raw: str) -> list[tuple[str, int]]: |
|||
assert raw[0] == '\n' |
|||
matched = [re.match(r'^([\dA-F]{9}) \((\d+)\)$', x) for x in raw[1:].splitlines()] |
|||
return [(x[1], int(x[2]) - 1) for x in matched] |
|||
|
|||
|
|||
def load_file(file_name: str) -> dict[str, dict]: |
|||
raw = open(file_name).read() |
|||
assert raw[0] == '[' |
|||
assert raw[-1] == '\n' |
|||
|
|||
result = {} |
|||
for item in raw[1:-1].split('\n['): |
|||
item = item.split('--------') |
|||
assert len(item) == 7 |
|||
assert item[-1] == '' |
|||
assert item[2] == item[4] |
|||
assert item[2] == item[5] |
|||
code = re.match(r'^([\dA-F]{9})]\n$', item[0])[1] |
|||
|
|||
min_solutions = split_item(item[1]) |
|||
assert len(min_solutions) in [0, 1] |
|||
solutions = split_item(item[3]) |
|||
assert len(set([x[1] for x in solutions])) in [0, 1] |
|||
assert len(set([x[0] for x in solutions])) == len(solutions) |
|||
|
|||
if not min_solutions: |
|||
min_step = -1 |
|||
assert len(solutions) == 0 |
|||
else: |
|||
min_step = solutions[0][1] |
|||
assert min_solutions[0] in solutions |
|||
|
|||
furthest = split_item(item[2]) |
|||
assert len(set([x[1] for x in furthest])) == 1 |
|||
assert len(set([x[0] for x in furthest])) == len(furthest) |
|||
|
|||
result[code] = { |
|||
'min_step': min_step, |
|||
'max_step': furthest[0][1], |
|||
'solutions': [x[0] for x in solutions], |
|||
'furthest': [x[0] for x in furthest], |
|||
} |
|||
return result |
|||
|
|||
|
|||
def load_all(files: list[str]) -> dict[str, dict]: |
|||
data = {} |
|||
[data.update(load_file(x)) for x in files] |
|||
data = {x: data[x] for x in sorted(data)} |
|||
return data |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
content = json.dumps(load_all([ |
|||
'data_149.txt', 'data_154.txt', 'data_159.txt', |
|||
'data_164.txt', 'data_169.txt', 'data_174.txt' |
|||
])) |
|||
print(content) |
Loading…
Reference in new issue