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 (
AC Method (Diamond):
Find two numbers that multiply to a·c and add to b.
Product (ac) = {a} × {c} = {product}
Sum (b) = {sum}