Nicolas Cantu 9a975c73d7 Restructuration projet : applications, pour enfants, these
**Motivations:**
- Clarifier l'organisation du dépôt par domaine applicatif
- Séparer les contenus par public cible (adulte, enfant, thèse)

**Evolutions:**
- Nouvelle arborescence applications/ (collatz, IA)
- Dossier pour enfants/ pour les contenus jeunesse
- Dossier these/ pour le livre jeune adulte
- Scripts de pipeline Collatz (01-setup, 02-run-pipeline, 03-run-direct-pipeline)
- Candidats D18 palier2p30, registreK partagé en archives zip
- Plan de relecture scientifique mis à jour

**Pages affectées:**
- .cursor/plans/relecture-scientifique-collatz.md
- v0/ → applications/collatz/, applications/IA/, pour enfants/, these/
- IA_agents/ → pour enfants/
2026-03-02 00:18:40 +01:00

45 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
"""
collatz_k_utils.py
Utilitaires: lecture de listes depuis des fichiers Markdown,
écriture de rapports, etc.
"""
from __future__ import annotations
from pathlib import Path
import re
from typing import List, Optional
def extract_ints_from_markdown(path: str, header_regex: Optional[str] = None) -> List[int]:
"""
Extrait tous les entiers d'un fichier Markdown.
Si header_regex est fourni, extrait uniquement la section à partir du header.
"""
text = Path(path).read_text(encoding="utf-8")
if header_regex is not None:
m = re.search(header_regex, text, flags=re.S)
if not m:
raise ValueError(f"Section introuvable via regex: {header_regex}")
text = m.group(1)
return list(map(int, re.findall(r"\b\d+\b", text)))
def parse_markdown_table_to_rows(path: str) -> List[List[str]]:
"""
Parse simple des lignes de table Markdown commençant par '|'.
Retourne les champs (sans les '|', strip).
"""
rows: List[List[str]] = []
for ln in Path(path).read_text(encoding="utf-8").splitlines():
if not ln.startswith("|"):
continue
parts = [p.strip() for p in ln.strip().strip("|").split("|")]
rows.append(parts)
return rows
def write_text(path: str, content: str) -> None:
Path(path).write_text(content, encoding="utf-8")