import React, { useState } from 'react'; const FactoringWidget: React.FC = () => { // ax^2 + bx + c const [a, setA] = useState(1); const [b, setB] = useState(5); const [c, setC] = useState(6); const product = a * c; const sum = b; // We won't solve it for them immediately, let them guess or think // But we will show if it's factorable over integers // Simple check for nice numbers const getFactors = () => { // Find two numbers p, q such that p*q = product and p+q = sum // Brute force range reasonable for typical SAT (up to +/- 100) for (let i = -100; i <= 100; i++) { if (i === 0) continue; const q = product / i; if (Math.abs(q - Math.round(q)) < 0.001) { // is integer if (i + q === sum) return [i, q].sort((x,y) => x-y); } } return null; }; const solution = getFactors(); return (
{/* Input Side */}

Polynomial: {a === 1 ? '' : a}x² {b >= 0 ? '+' : ''}{b}x {c >= 0 ? '+' : ''}{c}

setA(parseInt(e.target.value) || 0)} className="w-full p-2 border rounded font-mono font-bold text-center" />
setB(parseInt(e.target.value) || 0)} className="w-full p-2 border rounded font-mono font-bold text-center" />
setC(parseInt(e.target.value) || 0)} className="w-full p-2 border rounded font-mono font-bold text-center" />

AC Method (Diamond):

Find two numbers that multiply to a·c and add to b.

Product (ac) = {a} × {c} = {product}
Sum (b) = {sum}

{/* Visual Side */}
{/* X Shape */}
{/* Top (Product) */}
{product}
{/* Bottom (Sum) */}
{sum}
{/* Left (Factor 1) */}
{solution ? solution[0] : "?"}
{/* Right (Factor 2) */}
{solution ? solution[1] : "?"}
{solution ? (
Factors Found: {solution[0]} and {solution[1]} {a === 1 && (
(x {solution[0] >= 0 ? '+' : ''}{solution[0]})(x {solution[1] >= 0 ? '+' : ''}{solution[1]})
)}
) : (
No integer factors found. (Prime)
)}
); }; export default FactoringWidget;