$rows = DB::table('questions')->where('qa_status','ai_generated')->where('source','like','% P6 %')->get();
$n=$rows->count();
$badParen=[]; $badDD=[]; $fibFrac=[]; $fibNoInput=[]; $mcqBad=[]; $rawBlank=[];
foreach ($rows as $r) {
$q=(string)$r->question;
if (substr_count($q,'\\(') !== substr_count($q,'\\)')) $badParen[]=$r->id;
if (substr_count($q,'$$') % 2 !== 0) $badDD[]=$r->id;
if (strpos($q,'[?]')!==false) $rawBlank[]=$r->id;
if ((int)$r->type_id === 2) {
foreach (['answer0','answer1','answer2','answer3'] as $c) {
$v=trim((string)$r->$c);
if ($v!=='' && !preg_match('/^-?\d+(\.\d+)?$/',$v)) { $fibFrac[]=$r->id.':'.$c.'='.$v; break; }
}
if (strpos($q,'id;
}
if ((int)$r->type_id === 1) {
$opts=array_filter([$r->answer0,$r->answer1,$r->answer2,$r->answer3], fn($x)=>$x!==null && $x!=='');
if (count($opts)<2 || $r->correct_answer===null) $mcqBad[]=$r->id;
}
}
$show=fn($a)=>count($a)?implode(',',array_slice($a,0,12)):'-';
echo "P6 ai_generated questions: $n\n";
echo "unbalanced \\(..\\): ".count($badParen)." [".$show($badParen)."]\n";
echo "odd \$\$ count: ".count($badDD)." [".$show($badDD)."]\n";
echo "raw [?] left: ".count($rawBlank)." [".$show($rawBlank)."]\n";
echo "FIB non-numeric answer: ".count($fibFrac)." [".$show($fibFrac)."]\n";
echo "FIB without : ".count($fibNoInput)." [".$show($fibNoInput)."]\n";
echo "MCQ missing opts/answer: ".count($mcqBad)." [".$show($mcqBad)."]\n";