def grid(*rows):
return np.array(rows, dtype=int)
def show(g):
return "\n".join(" ".join(str(v) for v in row) for row in g)
TASKS = {}
# --- T1 : miroir vertical, puis la couleur 3 devient 5 -----------------------
t1a_in = grid([3, 0, 2], [1, 3, 0], [0, 2, 3], [3, 3, 1])
t1a_out = make_recolor(3, 5)(flipud(t1a_in))
t1b_in = grid([3, 2, 2, 0], [0, 3, 1, 3], [2, 0, 3, 0])
t1b_out = make_recolor(3, 5)(flipud(t1b_in))
t1_test = grid([3, 1, 0, 3], [2, 3, 3, 0], [0, 0, 3, 2], [1, 3, 2, 3], [3, 3, 0, 1])
TASKS["T1 miroir teinte"] = {
"train": [(t1a_in, t1a_out), (t1b_in, t1b_out)], "test": t1_test,
"solution": ["flipud", "recolor:3:5"]}
# --- T2 : garder la couleur 4, puis cadrer sur le contenu --------------------
# (les 4 strictement interieurs : le cadrage n'est pas un no-op,
# et du contenu non-4 hors de la boite des 4 rend l'ordre masque->cadre obligatoire)
t2a_in = grid([1, 0, 7, 0], [0, 4, 0, 4], [0, 0, 4, 0], [2, 0, 0, 0])
t2a_out = crop_content(make_mask_keep(4)(t2a_in))
t2b_in = grid([9, 0, 0, 0, 8], [0, 4, 0, 0, 0], [0, 0, 4, 4, 0])
t2b_out = crop_content(make_mask_keep(4)(t2b_in))
t2_test = grid([5, 0, 0, 0], [0, 4, 0, 4], [0, 0, 4, 0], [6, 0, 0, 0])
TASKS["T2 isoler la forme"] = {
"train": [(t2a_in, t2a_out), (t2b_in, t2b_out)], "test": t2_test,
"solution": ["mask_keep:4", "crop_content"]}
# --- T3 : retourner, isoler les 4, cadrer (profondeur 3 exacte) --------------
t3a_in = grid([0, 4, 0, 2], [7, 0, 4, 0], [0, 4, 0, 0], [2, 0, 0, 4])
t3a_out = crop_content(make_mask_keep(4)(flipud(t3a_in)))
t3b_in = grid([4, 9, 0, 4, 0], [0, 0, 4, 0, 1], [6, 4, 0, 0, 0])
t3b_out = crop_content(make_mask_keep(4)(flipud(t3b_in)))
t3_test = grid([0, 4, 0, 8], [4, 0, 4, 0], [3, 0, 0, 0], [0, 4, 5, 4])
TASKS["T3 retourner-isoler-cadrer"] = {
"train": [(t3a_in, t3a_out), (t3b_in, t3b_out)], "test": t3_test,
"solution": ["flipud", "mask_keep:4", "crop_content"]}
for name, t in TASKS.items():
print(f"--- {name} | solution attendue : {' >> '.join(t['solution'])}")