stepwise / static /visuals /goodwill.js
Ashish-K's picture
Visual question sets: four rounds of independent review fixes (leaks, shortcuts, plausibility, teaching text) (part 2)
f47988a verified
Raw History Blame Contribute Delete
47.7 kB
// Visual class: Goodwill adjustment on reconstitution of a partnership (CBSE 12 Accountancy, Unit 1).
// Model -> solver -> sensible changes -> questions -> checks. The drawing (render.js) reads the same model.
import { Frac, shares, toRatio, ratioStr, inr, rupee, Checks } from "./core.js";
export const ID = "goodwill";
export const TITLE = "Goodwill when the partnership changes";
export const ATOMS = {
"055-GW-A01": "When partners change their profit-sharing ratio, some partners gain a share of future profit and others give up (sacrifice) a share; the firm itself carries on.",
"055-GW-A02": "A partner's sacrifice = old share − new share; a partner's gain = new share − old share.",
"055-GW-A03": "The sacrificing ratio is the ratio of the partners' sacrifices; the gaining ratio is the ratio of the partners' gains.",
"055-GW-A04": "The gaining partners compensate the sacrificing partners for goodwill: each amount = the firm's goodwill × that partner's gain (or sacrifice).",
"055-GW-A05": "Journal entry: Gaining partners' Capital A/cs Dr; To Sacrificing partners' Capital A/cs. The partner who gains pays, so the gainer is debited.",
"055-GW-A06": "A partner whose share does not change neither gains nor sacrifices, and does not appear in the goodwill entry.",
"055-GW-A07": "Under AS 26, goodwill is not raised (opened) in the books on a change in ratio, admission or retirement; it is adjusted only through the partners' accounts.",
"055-GW-A08": "When the partners' capitals are fixed, goodwill (like every other adjustment) goes through their Current A/cs, not their Capital A/cs.",
"055-GW-A09": "On admission, each old partner's sacrifice = old share − new share; the new partner's premium for goodwill = the firm's goodwill × the new partner's share.",
"055-GW-A10": "Premium brought in cash: Bank A/c Dr (capital + premium) To New partner's Capital A/c and To Premium for Goodwill A/c; then Premium for Goodwill A/c Dr To the sacrificing partners' Capital A/cs in the sacrificing ratio. Capital and premium are two separate sums of cash.",
"055-GW-A11": "On retirement, the retiring partner is credited with the firm's goodwill × their old share; the remaining partners are debited in their gaining ratio.",
"055-GW-A12": "On retirement, each remaining partner's gain = new share − old share. The retiring partner's credit depends only on their own old share, not on how the others split it.",
"055-GW-A13": "Changing the value of goodwill changes every amount in proportion, but not who is debited or credited.",
};
export const MISCONCEPTIONS = {
"055-GW-M01": { wrong: "The gaining partner is credited and the sacrificing partner debited (the entry is reversed).", atoms: ["055-GW-A05"] },
"055-GW-M02": { wrong: "Goodwill A/c is opened in the books and credited to the partners.", atoms: ["055-GW-A07"] },
"055-GW-M03": { wrong: "The compensation is shared in the old (or new) profit-sharing ratio instead of the sacrificing or gaining ratio.", atoms: ["055-GW-A03", "055-GW-A04"] },
"055-GW-M04": { wrong: "Each amount is goodwill × the partner's new share, instead of goodwill × his gain or sacrifice.", atoms: ["055-GW-A04"] },
"055-GW-M05": { wrong: "Goodwill goes through Capital A/cs even when capitals are fixed.", atoms: ["055-GW-A08"] },
"055-GW-M06": { wrong: "The new partner's premium is taken out of his capital, so the cash brought in is only the capital figure.", atoms: ["055-GW-A10"] },
"055-GW-M07": { wrong: "The retiring partner's goodwill credit depends on the remaining partners' new ratio.", atoms: ["055-GW-A12"] },
"055-GW-M08": { wrong: "A partner whose share is unchanged still appears in the goodwill entry.", atoms: ["055-GW-A06"] },
};
const NAMES = ["Aman", "Bela", "Chirag", "Divya", "Esha", "Farhan", "Gauri", "Harsh", "Isha", "Jatin", "Kavya", "Laksh", "Meera", "Nikhil", "Ojas", "Pari", "Rohan", "Sana", "Tanvi", "Vikram",
"Arjun", "Bhavna", "Dev", "Ira", "Kabir", "Lata", "Manav", "Nisha", "Omkar", "Priya", "Rahul", "Simran", "Tarun", "Uma", "Varun", "Yamini", "Zoya", "Neel", "Ritu", "Sameer"];
const SURNAMES = ["Sharma", "Kapoor", "Verma", "Mehta", "Rao", "Gupta", "Iyer", "Bose", "Nair", "Malhotra", "Saxena", "Pillai", "Chawla", "Desai", "Banerjee", "Kulkarni", "Reddy", "Joshi", "Sethi", "Menon", "Ahuja", "Das", "Bhatt", "Khanna"];
const TRADES = ["Traders", "Electricals", "Textiles", "Furnishers", "Stationers", "Foods", "Pharma", "Hardware", "Sports", "Opticals", "Spices", "Motors", "Ceramics", "Books", "Dairy", "Printers", "Footwear", "Travels", "Paints", "Handlooms"];
const GOODWILL = [30000, 36000, 40000, 45000, 48000, 54000, 60000, 72000, 75000, 84000, 90000, 96000, 100000, 108000, 120000, 126000, 144000, 150000, 180000, 200000, 210000, 240000, 252000, 270000, 300000, 360000, 420000, 450000, 480000, 504000, 540000, 600000];
const CAPITALS = [100000, 120000, 150000, 160000, 180000, 200000, 240000, 250000, 300000];
export const SCENARIOS = {
change: "Change in ratio among existing partners",
unchanged: "Change in ratio where one partner's share stays the same",
fixed: "Change in ratio with fixed capitals",
admission: "Admission of a partner who brings premium in cash",
retirement: "Retirement of a partner",
};
// ---------- solver ----------
const acct = (inst, i) => `${inst.partners[i]}'s ${inst.capitals === "fixed" ? "Current" : "Capital"} A/c`;
export function solve(inst) {
const n = inst.partners.length;
const oldS = shares(inst.old), newS = shares(inst.new);
const delta = newS.map((s, i) => s.sub(oldS[i])); // + gain, − sacrifice
const amt = delta.map((d) => d.abs().mul(inst.goodwill)); // Frac rupees
const role = delta.map((d) => (d.sign() > 0 ? "gain" : d.sign() < 0 ? "sacrifice" : "same"));
const gainers = [...Array(n).keys()].filter((i) => role[i] === "gain");
const sacrificers = [...Array(n).keys()].filter((i) => role[i] === "sacrifice");
const sacRatio = toRatio(sacrificers.map((i) => delta[i].abs()));
const gainRatio = toRatio(gainers.map((i) => delta[i]));
const entries = [];
if (inst.scenario === "admission") {
const k = inst.incoming; const premium = amt[k].val(); const capital = inst.newCapital;
entries.push({ dr: [{ acct: "Bank A/c", amt: capital + premium }], cr: [{ acct: `${inst.partners[k]}'s Capital A/c`, amt: capital }, { acct: "Premium for Goodwill A/c", amt: premium }],
narr: `Being capital and premium for goodwill brought in cash by ${inst.partners[k]}` });
entries.push({ dr: [{ acct: "Premium for Goodwill A/c", amt: premium }], cr: sacrificers.map((i) => ({ acct: acct(inst, i), amt: amt[i].val() })),
narr: `Being premium for goodwill credited to the sacrificing partners in their sacrificing ratio ${ratioStr(sacRatio)}` });
} else {
entries.push({ dr: gainers.map((i) => ({ acct: acct(inst, i), amt: amt[i].val() })), cr: sacrificers.map((i) => ({ acct: acct(inst, i), amt: amt[i].val() })),
narr: inst.scenario === "retirement" ? `Being ${inst.partners[inst.retiring]}'s share of goodwill debited to the remaining partners in their gaining ratio ${ratioStr(gainRatio)}`
: `Being adjustment for goodwill on change in profit-sharing ratio` });
}
return { oldS, newS, delta, amt, role, gainers, sacrificers, sacRatio, gainRatio, entries };
}
// Second, independent route used only as a check: post every entry to a ledger and confirm that each
// partner's net credit equals goodwill × (old share − new share), the "raise in old ratio, write off in
// new ratio" result. (That route is NOT a method students may use under AS 26 — it is our cross-check.)
export function ledgerCheck(inst, sol) {
const bal = {};
for (const e of sol.entries) { for (const l of e.dr) bal[l.acct] = (bal[l.acct] || 0) - l.amt; for (const l of e.cr) bal[l.acct] = (bal[l.acct] || 0) + l.amt; }
const problems = [];
inst.partners.forEach((p, i) => {
let got = bal[acct(inst, i)] || 0;
let want = sol.oldS[i].sub(sol.newS[i]).mul(inst.goodwill).val();
if (inst.scenario === "admission" && i === inst.incoming) { // pays his premium in cash, so his capital shows only the capital
got = (bal[`${p}'s Capital A/c`] || 0) - inst.newCapital; want = 0;
const cashIn = -(bal["Bank A/c"] || 0), shouldBe = inst.newCapital + sol.newS[i].mul(inst.goodwill).val();
if (cashIn !== shouldBe) problems.push(`bank ${cashIn} vs ${shouldBe}`);
if (bal["Premium for Goodwill A/c"]) problems.push("premium account not cleared");
}
if (Math.abs(got - want) > 1e-9) problems.push(`${p}: ledger ${got} vs ${want}`);
});
for (const e of sol.entries) { const d = e.dr.reduce((t, l) => t + l.amt, 0), c = e.cr.reduce((t, l) => t + l.amt, 0); if (d !== c) problems.push(`entry unbalanced ${d} vs ${c}`); }
if (inst.scenario !== "admission" && (bal["Premium for Goodwill A/c"] || bal["Goodwill A/c"])) problems.push("goodwill account left open");
return problems;
}
// ---------- sensibility checks on an instance ----------
export function checkInstance(inst) {
const c = new Checks(`goodwill:${inst.scenario}`);
const sol = solve(inst); const n = inst.partners.length;
const live = (r, skip) => r.filter((_, i) => i !== skip);
c.ok("2-4 partners, distinct names", n >= 2 && n <= 4 && new Set(inst.partners).size === n, "partner count/names");
const lowest = (r) => r.reduce((g, x) => { let a = g, b = x; while (b) [a, b] = [b, a % b]; return a; }, 0) === 1;
c.ok("old ratio in lowest terms", lowest(inst.old), `old ${ratioStr(inst.old)}`);
c.ok("new ratio in lowest terms", lowest(inst.new), `new ${ratioStr(inst.new)}`);
c.ok("ratio terms small (1-9), totals ≤ 20", [...live(inst.old, inst.incoming), ...live(inst.new, inst.retiring)].every((x) => x >= 1 && x <= 9) && inst.old.reduce((a, b) => a + b) <= 20 && inst.new.reduce((a, b) => a + b) <= 20, "ratio too large or a zero share for a continuing partner");
c.ok("the ratio actually changes", sol.delta.some((d) => d.sign() !== 0), "old = new");
c.ok("sacrificing and gaining ratios use small terms (≤ 9)", [...sol.sacRatio, ...sol.gainRatio].every((x) => x <= 9), `sacrificing ${ratioStr(sol.sacRatio)}, gaining ${ratioStr(sol.gainRatio)}`);
const shift = sol.gainers.reduce((t, i) => t + sol.delta[i].val(), 0);
if (["change", "unchanged", "fixed"].includes(inst.scenario)) {
c.ok("plausible renegotiation (total shift 1/12 to 1/3)", shift >= 1 / 12 - 1e-9 && shift <= 1 / 3 + 1e-9, `shift ${shift.toFixed(3)}`);
c.ok("ratio terms ≤ 6", [...inst.old, ...inst.new].every((x) => x <= 6), "terms too large for a plausible deed");
}
if (["change", "unchanged", "fixed"].includes(inst.scenario)) c.ok("no partner more than doubles their share", sol.newS.every((f, i) => inst.old[i] === 0 || f.val() <= 2 * sol.oldS[i].val() + 1e-9), "share more than doubles");
if (inst.scenario === "admission") c.ok("goodwill and capital are different figures", inst.goodwill !== inst.newCapital, "goodwill equals capital");
c.ok("no continuing partner gives up more than half of their old share", sol.oldS.every((f, i) => inst.new[i] === 0 || inst.old[i] === 0 || sol.newS[i].val() >= f.val() / 2 - 1e-9), "share swing too large");
c.ok("every goodwill amount at least ₹2,000", sol.amt.every((a) => a.val() === 0 || a.val() >= 2000), "a trivial amount");
c.ok("every continuing share at least 1/10", sol.oldS.every((f, i) => inst.old[i] === 0 || f.val() >= 0.1) && sol.newS.every((f, i) => inst.new[i] === 0 || f.val() >= 0.1), "a share under 1/10");
if (inst.scenario === "retirement") c.ok("retiring share at most 1/2", sol.oldS[inst.retiring].val() <= 0.5, "retiring partner held over half");
if (inst.scenario === "admission") c.ok("new partner's share 1/6 to 1/3", sol.newS[inst.incoming].val() >= 1 / 6 - 1e-9 && sol.newS[inst.incoming].val() <= 1 / 3 + 1e-9, "implausible share for an incoming partner");
c.ok("goodwill round and in range", inst.goodwill % 1000 === 0 && inst.goodwill >= 30000 && inst.goodwill <= 600000, `goodwill ${inst.goodwill}`);
c.ok("every amount whole hundreds of rupees", sol.amt.every((a) => a.isInt() && a.val() % 100 === 0), `amounts ${sol.amt.map(String)}`);
c.ok("at least one gainer and one sacrificer", sol.gainers.length >= 1 && sol.sacrificers.length >= 1, "no gainer or no sacrificer");
const same = sol.role.filter((r) => r === "same").length;
if (inst.scenario === "unchanged") c.ok("exactly one partner unchanged", same === 1, `${same} unchanged`);
else c.ok("no partner unchanged", same === 0, `${same} unchanged (use the 'unchanged' scenario)`);
if (inst.scenario === "fixed") c.ok("capitals fixed", inst.capitals === "fixed", "fixed scenario needs fixed capitals");
if (inst.scenario === "admission") {
const k = inst.incoming;
c.ok("incoming partner had no old share", inst.old[k] === 0, "incoming old share");
c.ok("every old partner sacrifices", inst.partners.every((_, i) => i === k || sol.role[i] === "sacrifice"), "an old partner gains on admission");
c.ok("capital round and plausible", inst.newCapital % 10000 === 0 && inst.newCapital >= 50000 && inst.newCapital <= 500000, `capital ${inst.newCapital}`);
c.ok("premium at most 60% of capital brought", sol.amt[k].val() <= 0.6 * inst.newCapital, "premium too large next to the capital");
}
if (inst.scenario === "retirement") {
const r = inst.retiring;
c.ok("retiring partner has no new share", inst.new[r] === 0, "retiring new share");
c.ok("every remaining partner gains", inst.partners.every((_, i) => i === r || sol.role[i] === "gain"), "a remaining partner sacrifices on retirement");
c.ok("at least two remain", n - 1 >= 2, "only one partner left (that is a sole proprietor)");
}
const lp = ledgerCheck(inst, sol);
c.ok("ledger cross-check agrees", lp.length === 0, lp.join("; "));
return c;
}
// ---------- instance sampling ----------
function ratios(k, maxTerm = 6, maxSum = 15) {
const out = [];
const rec = (pre) => { if (pre.length === k) { const s = pre.reduce((a, b) => a + b, 0); const g = pre.reduce((a, b) => { while (b) [a, b] = [b, a % b]; return a; }, 0); if (s <= maxSum && g === 1) out.push(pre); return; } for (let x = 1; x <= maxTerm; x++) rec([...pre, x]); };
rec([]); return out;
}
const goodwillFor = (r, deltas) => { const ok = GOODWILL.filter((g) => deltas.every((d) => { const a = d.abs().mul(g); return a.isInt() && a.val() % 100 === 0; })); return ok.length ? r.pick(ok) : null; };
export function sample(r, scenario, tries = 400, stats = null) {
for (let t = 0; t < tries; t++) {
const inst = build(r, scenario); if (!inst) { if (stats) stats["could not build"] = (stats["could not build"] || 0) + 1; continue; }
const c = checkInstance(inst); if (c.passed) return inst;
if (stats) for (const f of c.failures) stats[f.name] = (stats[f.name] || 0) + 1;
}
return null;
}
function build(r, scenario) {
const n = scenario === "admission" ? r.pick([2, 2, 3]) : scenario === "retirement" ? 3 : r.pick([2, 3, 3]);
const names = r.shuffle(NAMES).slice(0, scenario === "admission" ? n + 1 : n).sort();
const firm = `${r.pick(SURNAMES)} ${r.pick(TRADES)}`; const caps = scenario === "fixed" ? "fixed" : r.next() < 0.15 && scenario !== "admission" ? "fixed" : "fluctuating";
if (scenario === "admission") {
const old = [...r.pick(ratios(n, 5, 10)), 0];
const oS = shares(old);
const pool = ratios(n + 1, 9, 20).filter((nr) => { const s = shares(nr); const k = s[n].val(); return k >= 1 / 6 - 1e-9 && k <= 1 / 3 + 1e-9 && s.every((x, i) => i === n || x.cmp(oS[i]) < 0); });
if (!pool.length) return null;
const newR = r.pick(pool);
const inst = { cls: ID, scenario, firm, partners: names, old, new: newR, incoming: n, capitals: "fluctuating" };
const d = shares(newR).map((s, i) => s.sub(shares(old)[i]));
inst.goodwill = goodwillFor(r, d); if (!inst.goodwill) return null;
inst.newCapital = r.pick(CAPITALS.filter((c) => 0.6 * c >= d[n].mul(inst.goodwill).val())); if (!inst.newCapital) return null;
return inst;
}
if (scenario === "retirement") {
const old = r.pick(ratios(3, 5, 10)); const ret = r.int(0, 2);
const remain = r.pick(ratios(2, 5, 10)); const newR = []; let j = 0; for (let i = 0; i < 3; i++) newR.push(i === ret ? 0 : remain[j++]);
const inst = { cls: ID, scenario, firm, partners: names, old, new: newR, retiring: ret, capitals: "fluctuating" };
inst.goodwill = goodwillFor(r, shares(newR).map((s, i) => s.sub(shares(old)[i]))); return inst.goodwill ? inst : null;
}
const old = r.pick(ratios(n, 5, 10)); const newR = r.pick(ratios(n, 6, 12));
const inst = { cls: ID, scenario, firm, partners: names, old, new: newR, capitals: caps };
inst.goodwill = goodwillFor(r, shares(newR).map((s, i) => s.sub(shares(old)[i]))); return inst.goodwill ? inst : null;
}
// ---------- text helpers ----------
export const fmtEntry = (e) => [...e.dr.map((l) => `${l.acct} Dr. ${inr(l.amt)}`), ...e.cr.map((l) => `To ${l.acct} ${inr(l.amt)}`)].join("; ");
export function describe(inst) {
const P = inst.partners; const caps = inst.capitals === "fixed" ? " Their capitals are fixed." : "";
if (inst.scenario === "admission") {
const k = inst.incoming; const old = P.filter((_, i) => i !== k);
return `${old.join(", ").replace(/, ([^,]*)$/, " and $1")} of ${inst.firm} share profits ${ratioStr(inst.old.slice(0, k))}. They admit ${P[k]}; the new ratio is ${ratioStr(inst.new)} (${P.join(" : ")}). The firm's goodwill is valued at ${rupee(inst.goodwill)}. ${P[k]} brings ${rupee(inst.newCapital)} as capital and her share of goodwill as premium, in cash.`.replace(" her share", ` ${pron(P[k])} share`);
}
if (inst.scenario === "retirement") {
const ret = inst.retiring; const rem = P.filter((_, i) => i !== ret);
return `${P.join(", ").replace(/, ([^,]*)$/, " and $1")} of ${inst.firm} share profits ${ratioStr(inst.old)}. ${P[ret]} retires, and ${rem.join(", ").replace(/, ([^,]*)$/, " and $1")} will share future profits ${ratioStr(inst.new.filter((_, i) => i !== ret))}. The firm's goodwill is valued at ${rupee(inst.goodwill)}.${caps}`;
}
return `${P.join(", ").replace(/, ([^,]*)$/, " and $1")} of ${inst.firm} share profits ${ratioStr(inst.old)}. With effect from 1 April 2026 they agree to share ${ratioStr(inst.new)}. The firm's goodwill is valued at ${rupee(inst.goodwill)}.${caps}`;
}
const FEMALE = new Set(["Bela", "Divya", "Esha", "Gauri", "Isha", "Kavya", "Meera", "Pari", "Sana", "Tanvi", "Bhavna", "Ira", "Lata", "Nisha", "Priya", "Simran", "Uma", "Yamini", "Zoya", "Ritu"]);
const pron = (n) => (FEMALE.has(n) ? "her" : "his");
const roleWord = (r) => (r === "gain" ? "a gaining partner" : r === "sacrifice" ? "a sacrificing partner" : "unaffected");
const shareStr = (f) => (f.sign() === 0 ? "0" : f.toString());
// ---------- sensible changes ----------
// Each change alters ONE component, names the rule it tests, and must change something that rule decides.
export function changes(inst, r) {
const out = []; const base = solve(inst); const n = inst.partners.length;
const cand = (pred) => {
const k = inst.scenario === "retirement" ? 2 : n;
let best = null, bestD = 1e9;
for (const rr of r.shuffle(ratios(k))) {
let nr = rr;
if (inst.scenario === "retirement") { nr = []; let j = 0; for (let i = 0; i < n; i++) nr.push(i === inst.retiring ? 0 : rr[j++]); }
const ni = { ...inst, new: nr }; const s = shares(nr);
if (s.every((x, i) => x.eq(shares(inst.new)[i]))) continue;
const g = GOODWILL.includes(inst.goodwill) ? inst.goodwill : null; if (!g) continue;
if (!checkInstance(ni).passed && !pred.allowScenarioSwitch) continue;
if (!pred(ni, solve(ni))) continue;
const dist = s.reduce((t, x, i) => t + Math.abs(x.val() - shares(inst.new)[i].val()), 0); // stay close: a plausible renegotiation
if (dist < bestD) { best = ni; bestD = dist; }
}
return best;
};
if (["change", "fixed", "unchanged"].includes(inst.scenario)) {
// 1. flip: one partner moves from gaining to sacrificing (or back)
const x = r.pick(base.gainers.concat(base.sacrificers));
const flipped = cand((ni, s) => s.role[x] !== base.role[x] && s.role[x] !== "same" && s.role.filter((q) => q === "same").length === base.role.filter((q) => q === "same").length);
if (flipped) out.push({ id: "flip", partner: x, inst: flipped, rule: "055-GW-A05", why: "the direction of the entry depends on whether the partner gains or sacrifices", text: `Suppose instead the new ratio is ${ratioStr(flipped.new)}.` });
// 2. equalise: one partner keeps exactly his old share
if (inst.scenario !== "unchanged" && n >= 3) {
const eq = cand(Object.assign((ni, s) => s.role.filter((q) => q === "same").length === 1, { allowScenarioSwitch: true }));
if (eq) { const y = solve(eq).role.indexOf("same"); const ni = { ...eq, scenario: "unchanged" }; if (checkInstance(ni).passed) out.push({ id: "equalise", partner: y, inst: ni, rule: "055-GW-A06", why: "a partner whose share does not change drops out of the entry", text: `Suppose instead the new ratio is ${ratioStr(ni.new)}.` }); }
}
}
// 3. goodwill value changes (round, plausible: between half and double)
const gs = GOODWILL.filter((g) => g !== inst.goodwill && g >= inst.goodwill / 2 && g <= inst.goodwill * 2 && (g >= inst.goodwill * 1.25 || g <= inst.goodwill * 0.8) && checkInstance({ ...inst, goodwill: g }).passed);
if (gs.length) { const g = r.pick(gs); out.push({ id: "goodwill", partner: r.pick(inst.scenario === "admission" ? base.sacrificers : base.gainers), inst: { ...inst, goodwill: g }, rule: "055-GW-A13", why: "amounts scale with goodwill, directions do not", text: `Suppose the goodwill is valued at ${rupee(g)} instead.` }); }
// 4. capitals become fixed
if (inst.capitals !== "fixed" && inst.scenario !== "admission") out.push({ id: "fixed", partner: base.gainers[0], inst: { ...inst, capitals: "fixed", scenario: inst.scenario === "change" ? "fixed" : inst.scenario }, rule: "055-GW-A08", why: "fixed capitals move the adjustment to current accounts", text: `Suppose the partners' capitals are fixed.` });
// 5. retirement: remaining partners split differently — the retiring partner's credit must NOT move
if (inst.scenario === "retirement") {
const ni = cand(() => true);
if (ni) out.push({ id: "resplit", partner: inst.retiring, inst: ni, rule: "055-GW-A12", why: "the retiring partner's credit depends only on their old share", text: `Suppose instead the remaining partners agree to share ${ratioStr(ni.new.filter((_, i) => i !== inst.retiring))}.` });
}
// 6. admission: the new partner takes a bigger or smaller share — premium and sacrifices move
if (inst.scenario === "admission") {
const k = inst.incoming;
const ni = cand((nn, s) => !shares(nn.new)[k].eq(shares(inst.new)[k]) && checkInstance(nn).passed);
if (ni) out.push({ id: "newshare", partner: r.pick(solve(ni).sacrificers.filter((i) => base.sacrificers.includes(i))) ?? 0, inst: ni, rule: "055-GW-A09", why: "the premium is goodwill × the new partner's share", text: `Suppose instead the new ratio is ${ratioStr(ni.new)}.` });
}
return out.filter((ch) => checkInstance(ch.inst).passed);
}
// ---------- wrong entries (for distractors and "find the error"), each breaking exactly one rule ----------
function wrongEntries(inst, sol) {
const P = inst.partners; const out = [];
const main = sol.entries[sol.entries.length - 1];
if (inst.scenario !== "admission") {
out.push({ mis: "055-GW-M01", rule: "direction", e: { dr: main.cr, cr: main.dr }, why: "reversed: the gaining partner credited" });
// shared in old ratio: gainers debited the full compensation, but credit spread over all non-gainers in OLD ratio
const total = main.dr.reduce((t, l) => t + l.amt, 0);
const others = [...P.keys()].filter((i) => sol.role[i] !== "gain");
const oldOthers = others.map((i) => inst.old[i]); const osum = oldOthers.reduce((a, b) => a + b, 0);
const cr = others.map((i, j) => ({ acct: acct(inst, i), amt: (total * oldOthers[j]) / osum }));
if (cr.every((l) => Number.isInteger(l.amt))) out.push({ mis: sol.role.includes("same") ? "055-GW-M08" : "055-GW-M03", rule: sol.role.includes("same") ? "unchanged" : "ratio", e: { dr: main.dr, cr }, why: "credit split in the old ratio" });
out.push({ mis: "055-GW-M02", rule: "as26", e: { dr: [{ acct: "Goodwill A/c", amt: main.cr.reduce((t, l) => t + l.amt, 0) }], cr: main.cr }, why: "goodwill raised in the books and credited to the sacrificers" });
const capNames = (l) => ({ ...l, acct: l.acct.replace(inst.capitals === "fixed" ? "Current" : "Capital", inst.capitals === "fixed" ? "Capital" : "Current") });
if (inst.capitals === "fixed") out.push({ mis: "055-GW-M05", rule: "fixed", e: { dr: main.dr.map(capNames), cr: main.cr.map(capNames) }, why: "capital accounts used with fixed capitals" });
// goodwill × new share for the gainers, passed on to the sacrificers in the sacrificing ratio (balanced, so only the amount rule breaks)
const drN = main.dr.map((l) => { const i = P.findIndex((p) => l.acct.startsWith(p + "'s")); return { ...l, amt: sol.newS[i].mul(inst.goodwill).val() }; });
const totN = drN.reduce((t, l) => t + l.amt, 0); const sacT = sol.sacrificers.reduce((t, i) => t + sol.delta[i].abs().val(), 0);
const crN = sol.sacrificers.map((i) => ({ acct: acct(inst, i), amt: Math.round((totN * sol.delta[i].abs().val()) / sacT * 100) / 100 }));
if ([...drN, ...crN].every((l) => Number.isInteger(l.amt) && l.amt % 100 === 0)) out.push({ mis: "055-GW-M04", rule: "amount", e: { dr: drN, cr: crN }, why: "amounts = goodwill × new share" });
if (inst.scenario === "retirement" && sol.gainers.length >= 2) { // remaining partners debited in their OLD ratio instead of the gaining ratio
const tot = main.cr.reduce((t, l) => t + l.amt, 0); const os = sol.gainers.reduce((t, i) => t + inst.old[i], 0);
const dr = sol.gainers.map((i) => ({ acct: acct(inst, i), amt: (tot * inst.old[i]) / os }));
if (dr.every((l) => Number.isInteger(l.amt))) out.push({ mis: "055-GW-M03", rule: "ratio", e: { dr, cr: main.cr }, why: "remaining partners debited in their old ratio" });
}
} else {
const prem = sol.entries[1];
out.push({ mis: "055-GW-M01", rule: "direction", e: { dr: prem.cr, cr: prem.dr }, why: "reversed" });
out.push({ mis: "055-GW-M02", rule: "as26", e: { dr: [{ acct: "Goodwill A/c", amt: prem.dr[0].amt }], cr: prem.cr }, why: "goodwill raised instead of using the premium" });
const total = prem.dr[0].amt; const olds = [...P.keys()].filter((i) => i !== inst.incoming); const osum = olds.reduce((t, i) => t + inst.old[i], 0);
const cr = olds.map((i) => ({ acct: acct(inst, i), amt: (total * inst.old[i]) / osum }));
if (cr.every((l) => Number.isInteger(l.amt))) out.push({ mis: "055-GW-M03", rule: "ratio", e: { dr: prem.dr, cr }, why: "old ratio instead of sacrificing ratio" });
}
return out;
}
// Rule checkers: used to prove a "wrong" entry breaks exactly the rule it claims to break.
function rulesBroken(inst, sol, e) {
const broken = new Set(); const main = sol.entries[sol.entries.length - 1];
const all = [...e.dr, ...e.cr];
if (all.some((l) => l.acct === "Goodwill A/c")) broken.add("as26");
const owner = (l) => inst.partners.findIndex((p) => l.acct.startsWith(p + "'s"));
if (e.dr.some((l) => owner(l) >= 0 && sol.role[owner(l)] === "sacrifice") || e.cr.some((l) => owner(l) >= 0 && sol.role[owner(l)] === "gain")) broken.add("direction");
if (all.some((l) => owner(l) >= 0 && sol.role[owner(l)] === "same")) broken.add("unchanged");
if (inst.capitals === "fixed" && inst.scenario !== "admission" && all.some((l) => l.acct.includes("Capital A/c"))) broken.add("fixed");
// split: on each side the partners' amounts must be in proportion to their gains / sacrifices
const inEntry = (lines) => lines.filter((l) => owner(l) >= 0 && sol.role[owner(l)] !== "same");
const propOK = (lines) => { const ps = inEntry(lines); if (ps.length < 2) return true;
const k = ps[0].amt / sol.amt[owner(ps[0])].val(); return ps.every((l) => Math.abs(l.amt - k * sol.amt[owner(l)].val()) < 0.5); };
if (!propOK(e.dr) || !propOK(e.cr)) broken.add("ratio");
const T = sol.sacrificers.reduce((t, i) => t + sol.amt[i].val(), 0); // the whole compensation
const sideTotal = (lines) => inEntry(lines).reduce((t, l) => t + l.amt, 0);
if ([e.dr, e.cr].some((side) => inEntry(side).length && sideTotal(side) !== T)) broken.add("amount");
if (e.dr.reduce((t, l) => t + l.amt, 0) !== e.cr.reduce((t, l) => t + l.amt, 0)) broken.add("unbalanced");
return broken;
}
const RULE_TEXT = {
direction: "The gaining partner must be debited and the sacrificing partner credited; this entry is the wrong way round.",
as26: "Goodwill must not be raised in the books (AS 26); it is adjusted only through the partners' accounts.",
ratio: "The total is right, but it is not split in the sacrificing ratio (credits) or the gaining ratio (debits).",
amount: "The split is right, but the total compensation is incorrect: it should be goodwill × the total sacrifice.",
fixed: "With fixed capitals the adjustment must go through the partners' Current A/cs.",
unchanged: "A partner whose share has not changed should not appear in the entry.",
};
// ---------- questions ----------
const ruleText = (inst, k) => (inst.scenario === "admission" && k === "direction" ? "The premium must be credited to the sacrificing partners, not debited to them; this entry is the wrong way round." : RULE_TEXT[k]);
const atomsFor = (rule) => ({ direction: ["055-GW-A05"], as26: ["055-GW-A07"], ratio: ["055-GW-A03", "055-GW-A04"], amount: ["055-GW-A04"], fixed: ["055-GW-A08"], unchanged: ["055-GW-A06"] }[rule] || []);
function mcq(r, { key, distractors }) { // shuffle key + distractors; keep reasons aligned
const all = r.shuffle([{ text: key, key: true }, ...distractors]);
return { options: all.map((o) => o.text), answer: all.findIndex((o) => o.key), distractors: all.filter((o) => !o.key).map((o) => ({ text: o.text, why: o.why, misconception_id: o.mis })) };
}
const fig = (inst, show, extra = {}) => ({ cls: ID, inst, show, ...extra });
export function questions(inst, r) {
const qs = []; const sol = solve(inst); const P = inst.partners; const D = describe(inst);
const wrong = wrongEntries(inst, sol);
// Q1 role of one partner: options form a 2x2 grid (consistent direction x amount), so no feature gives the key away
const x = r.pick(inst.scenario === "admission" ? sol.sacrificers : sol.gainers.concat(sol.sacrificers));
{
const role = sol.role[x]; const a = sol.amt[x].val();
const dirKey = role === "gain" ? "a gaining partner, debited" : "a sacrificing partner, credited";
const dirWrong = role === "gain" ? "a sacrificing partner, credited" : "a gaining partner, debited";
const cand = [
...sol.gainers.concat(sol.sacrificers).filter((j) => j !== x && sol.amt[j].val() !== a).map((j) => ({ v: sol.amt[j].val(), why: `took ${P[j]}'s amount` })),
{ v: sol.newS[x].mul(inst.goodwill).val(), why: "goodwill × new share instead of × the change" },
{ v: sol.oldS[x].mul(inst.goodwill).val(), why: "goodwill × old share instead of × the change" },
].filter((c) => c.v !== a && c.v > 0 && Number.isInteger(c.v));
const smaller = cand.filter((c) => c.v < a), larger = cand.filter((c) => c.v > a);
const pickFrom = smaller.length && (r.next() < 0.5 || !larger.length) ? smaller : larger; // key is not always the smaller amount
if (pickFrom.length) {
const alt = r.pick(pickFrom); const a2 = alt.v; const why2 = alt.why;
qs.push({ type: "mcq", kind: "role", group: "core", rule: "055-GW-A05", prompt: `${D} Which describes ${P[x]}'s part in the goodwill adjustment?`,
...mcq(r, { key: `${dirKey} ${rupee(a)}`, distractors: [
{ text: `${dirKey} ${rupee(a2)}`, why: why2, mis: "055-GW-M04" },
{ text: `${dirWrong} ${rupee(a)}`, why: "gain and sacrifice mixed up, so the entry is reversed", mis: "055-GW-M01" },
{ text: `${dirWrong} ${rupee(a2)}`, why: `reversed, and ${why2}`, mis: "055-GW-M01" }] }),
explanation: `${P[x]}'s share goes from ${shareStr(sol.oldS[x])} to ${shareStr(sol.newS[x])}, a ${role === "gain" ? "gain" : "sacrifice"} of ${sol.delta[x].abs()}. ${role === "gain" ? "The partner who gains pays, so" : "The partner who sacrifices is compensated, so"} ${P[x]} is ${role === "gain" ? "debited" : "credited"} with ${rupee(inst.goodwill)} × ${sol.delta[x].abs()} = ${rupee(a)}.`,
atom_ids: ["055-GW-A02", "055-GW-A04", "055-GW-A05"], misconception_id: "055-GW-M01", figure: fig(inst, ["ratios"]), difficulty: 2, signature: `role:${inst.scenario}` });
}
}
// Q2 pick the correct entry: options are a 2x2 grid (direction x split): key, reversed, wrong split, reversed wrong split
{
const keyE = sol.entries[sol.entries.length - 1];
const rev = (e) => ({ dr: e.cr, cr: e.dr });
const split = r.shuffle(wrong).find((w) => { const b = rulesBroken(inst, sol, w.e); return b.size === 1 && b.has("ratio") && w.e.dr.every((l) => l.acct !== "Goodwill A/c"); });
if (split) {
const opts = [{ e: rev(keyE), why: "reversed: gainers credited, sacrificers debited", mis: "055-GW-M01" }, { e: split.e, why: split.why, mis: split.mis }, { e: rev(split.e), why: `reversed, and ${split.why}`, mis: "055-GW-M01" }];
const texts = new Set([fmtEntry(keyE), ...opts.map((o) => fmtEntry(o.e))]);
if (texts.size === 4) {
const lead = inst.scenario === "admission" ? `${D} Which entry correctly deals with the premium after it has been received?` : `${D} Which journal entry records the adjustment for goodwill?`;
qs.push({ type: "mcq", kind: "entry", group: "core", rule: inst.scenario === "admission" ? "055-GW-A10" : "055-GW-A05", prompt: lead,
...mcq(r, { key: fmtEntry(keyE), distractors: opts.map((o) => ({ text: fmtEntry(o.e), why: o.why, mis: o.mis })) }),
explanation: `${sol.gainers.length ? `Gaining: ${sol.gainers.map((i) => `${P[i]} (+${sol.delta[i]})`).join(", ")}. ` : ""}Sacrificing: ${sol.sacrificers.map((i) => `${P[i]} (−${sol.delta[i].abs()})`).join(", ")}. ${inst.scenario === "admission" ? `The premium is passed to the sacrificing partners in their sacrificing ratio ${ratioStr(sol.sacRatio)}` : "The gainer pays: gaining partners are debited, sacrificing partners credited, each with goodwill × the change"}${inst.capitals === "fixed" ? ", through Current A/cs because capitals are fixed" : ""}.`,
atom_ids: ["055-GW-A03", "055-GW-A04", "055-GW-A05"], misconception_id: "055-GW-M01", figure: fig(inst, ["ratios"]), difficulty: 2, signature: `entry:${inst.scenario}` });
}
}
}
// Q3 numeric: amount credited to a sacrificing partner
{
const y = r.pick(inst.scenario === "admission" ? sol.sacrificers : sol.gainers.concat(sol.sacrificers)); const g = sol.role[y] === "gain";
qs.push({ type: "numeric", kind: "amount", group: "core", rule: "055-GW-A04", prompt: `${D} For what amount is ${P[y]}'s account adjusted for goodwill (debited or credited)? Give the amount in rupees.`,
answer: sol.amt[y].val(), tolerance: 0, unit: "₹",
explanation: `${P[y]}'s ${g ? "gain" : "sacrifice"} = ${g ? `${shareStr(sol.newS[y])} − ${shareStr(sol.oldS[y])}` : `${shareStr(sol.oldS[y])} − ${shareStr(sol.newS[y])}`} = ${sol.delta[y].abs()}. Amount = ${rupee(inst.goodwill)} × ${sol.delta[y].abs()} = ${rupee(sol.amt[y].val())}, ${g ? "debited (the gainer pays)" : "credited (the sacrificer is compensated)"}.`,
atom_ids: ["055-GW-A02", "055-GW-A04"], misconception_id: "055-GW-M04", figure: fig(inst, ["ratios-old-new"]), difficulty: 2, signature: `amount:${inst.scenario}` });
}
// Q4 sacrificing / gaining ratio
{
const isRet = inst.scenario === "retirement"; const which = isRet || sol.gainers.length > 1 ? "gain" : "sac";
const idx = which === "gain" ? sol.gainers : sol.sacrificers; const keyR = which === "gain" ? sol.gainRatio : sol.sacRatio;
if (idx.length >= 2) {
const oldR = toRatio(idx.map((i) => sol.oldS[i])), newR = toRatio(idx.map((i) => sol.newS[i]));
const cands = [{ r: oldR, why: "used the old ratio", mis: "055-GW-M03" }, { r: newR, why: "used the new ratio", mis: "055-GW-M03" }, { r: idx.map(() => 1), why: "assumed equal", mis: "055-GW-M03" }, { r: toRatio(idx.map((i) => sol.newS[i].add(sol.oldS[i]))), why: "added the shares instead of subtracting", mis: "055-GW-M03" }, { r: toRatio(idx.map((i) => sol.amt[i].mul(sol.newS[i]))), why: "weighted by the new shares", mis: "055-GW-M03" }];
const seen = new Set([ratioStr(keyR)]); const ds = [];
for (const c of cands) { const s = ratioStr(c.r); if (!seen.has(s)) { seen.add(s); ds.push({ text: s, why: c.why, mis: c.mis }); } }
const sidesObvious = inst.scenario === "admission" || inst.scenario === "retirement";
const names = (ix) => ix.map((i) => P[i]).join(", ").replace(/, ([^,]*)$/, " and $1");
let prompt = `${D} What is the ${which === "gain" ? "gaining" : "sacrificing"} ratio of ${names(idx)}?`; let key = ratioStr(keyR); let dd = ds.slice(0, 3);
if (!sidesObvious) {
const other = which === "gain" ? sol.sacrificers : sol.gainers; const otherR = which === "gain" ? sol.sacRatio : sol.gainRatio;
prompt = `${D} Which partners ${which === "gain" ? "gain" : "sacrifice"}, and in what ratio?`; key = `${names(idx)}, ${ratioStr(keyR)}`;
const swap = { text: other.length >= 2 ? `${names(other)}, ${ratioStr(otherR)}` : `${P[other[0]]} only`, why: "mixed up gainers and sacrificers", mis: "055-GW-M01" };
dd = [swap, ...ds.slice(0, 2).map((d) => ({ ...d, text: `${names(idx)}, ${d.text}` }))];
}
if (ds.length >= 3) qs.push({ type: "mcq", kind: "ratio", group: "core", rule: "055-GW-A03", prompt,
...mcq(r, { key, distractors: dd }),
explanation: `${idx.map((i) => `${P[i]}: ${which === "gain" ? `${shareStr(sol.newS[i])} − ${shareStr(sol.oldS[i])}` : `${shareStr(sol.oldS[i])} − ${shareStr(sol.newS[i])}`} = ${sol.delta[i].abs()}`).join("; ")}. Ratio ${ratioStr(keyR)}.`,
atom_ids: ["055-GW-A02", "055-GW-A03"].concat(isRet ? ["055-GW-A12"] : []), misconception_id: "055-GW-M03", figure: fig(inst, ["ratios-old-new"]), difficulty: 2, signature: `ratio:${inst.scenario}` });
}
}
// Q5 find the error: show one wrong entry; the options are rule statements
{
const cands = r.shuffle(wrong).filter((w) => { const b = rulesBroken(inst, sol, w.e); return b.size === 1 && b.has(w.rule); });
if (cands.length) {
const w = cands[0]; const others = Object.keys(RULE_TEXT).filter((k) => k !== w.rule && !rulesBroken(inst, sol, w.e).has(k));
const owner = (l) => P.findIndex((p) => l.acct.startsWith(p + "'s"));
const partnerLines = (side) => side.filter((l) => owner(l) >= 0).length;
const fits = { // a statement is a fair distractor only if the entry shown has the feature it talks about
direction: partnerLines(w.e.dr) > 0 && partnerLines(w.e.cr) > 0,
as26: w.e.dr.concat(w.e.cr).some((l) => l.acct === "Goodwill A/c"),
ratio: partnerLines(w.e.dr) >= 2 || partnerLines(w.e.cr) >= 2,
amount: partnerLines(w.e.dr) + partnerLines(w.e.cr) > 0,
fixed: inst.capitals === "fixed",
unchanged: sol.role.includes("same"),
};
const usable = others.filter((k) => fits[k]);
const ds = [...r.shuffle(usable).slice(0, 2).map((k) => ({ text: ruleText(inst, k), why: "this rule is kept in the shown entry", mis: "055-GW-M01" })),
{ text: "Nothing is wrong: this entry is correct.", why: "did not check the entry against the ratios", mis: "055-GW-M01" }];
if (usable.length < 2) ds.splice(0, 0, ...r.shuffle(others.filter((k) => !fits[k] && k !== "fixed" && k !== "unchanged")).slice(0, 2 - usable.length).map((k) => ({ text: ruleText(inst, k), why: "rule not involved", mis: "055-GW-M01" })));
qs.push({ type: "mcq", kind: "error", group: "core", rule: atomsFor(w.rule)[0], prompt: `${D} An accountant passed this entry: ${fmtEntry(w.e)}. What is wrong with it?`,
...mcq(r, { key: ruleText(inst, w.rule), distractors: ds }),
explanation: `${ruleText(inst, w.rule)} The correct entry: ${fmtEntry(sol.entries[sol.entries.length - 1])}.`,
atom_ids: atomsFor(w.rule), misconception_id: w.mis, figure: fig(inst, ["ratios", "entry"], { entry: w.e }), difficulty: 3, signature: `error:${w.rule}` });
}
}
// Q6 admission: cash brought in (Garv's netting error)
if (inst.scenario === "admission") {
const k = inst.incoming; const prem = sol.amt[k].val();
qs.push({ type: "numeric", kind: "cash", rule: "055-GW-A10", prompt: `${D} How much cash does ${P[k]} bring into the firm in total? Give the amount in rupees.`, answer: inst.newCapital + prem, tolerance: 0, unit: "₹",
explanation: `Premium = ${rupee(inst.goodwill)} × ${shareStr(sol.newS[k])} = ${rupee(prem)}. Capital and premium are separate sums: ${rupee(inst.newCapital)} + ${rupee(prem)} = ${rupee(inst.newCapital + prem)}. The premium is not taken out of the capital.`,
atom_ids: ["055-GW-A09", "055-GW-A10"], misconception_id: "055-GW-M06", figure: fig(inst, ["ratios-old-new"]), difficulty: 2, signature: "cash" });
}
// Q7 retirement: retiring partner's credit
if (inst.scenario === "retirement") {
const ret = inst.retiring;
qs.push({ type: "numeric", kind: "retire", group: "core", rule: "055-GW-A11", prompt: `${D} By how much is ${P[ret]}'s account credited for goodwill? Give the amount in rupees.`, answer: sol.amt[ret].val(), tolerance: 0, unit: "₹",
explanation: `${P[ret]} gives up the whole old share ${shareStr(sol.oldS[ret])}: ${rupee(inst.goodwill)} × ${shareStr(sol.oldS[ret])} = ${rupee(sol.amt[ret].val())}, debited to ${sol.gainers.map((i) => P[i]).join(" and ")} in their gaining ratio ${ratioStr(sol.gainRatio)}.`,
atom_ids: ["055-GW-A11"], misconception_id: "055-GW-M07", figure: fig(inst, ["ratios-old-new"]), difficulty: 2, signature: "retire" });
}
return qs.map((q) => ({ ...q, marks: 1 }));
}
// "What if" questions built from a sensible change: predict, then the figure animates to the new state.
export function whatIfQuestions(inst, r) {
const qs = []; const base = solve(inst); const P = inst.partners; const D = describe(inst);
for (const ch of changes(inst, r)) {
const ni = ch.inst; const s = solve(ni); const x = ch.partner;
const ac = (ins) => (ins.capitals === "fixed" ? " in the Current A/c" : " in the Capital A/c");
const state = (sol, i, ins) => sol.role[i] === "same" ? `does not appear in the entry` : `${sol.role[i] === "gain" ? "is debited" : "is credited"} ${rupee(sol.amt[i].val())}${ac(ins)}`;
const key = state(s, x, ni); const before = state(base, x, inst);
const dirOf = (sl, i) => (sl.role[i] === "gain" ? "is debited" : "is credited"); const flip = (d) => (d === "is debited" ? "is credited" : "is debited");
const amtAlt = [base.amt[x].val(), s.newS[x].mul(ni.goodwill).val(), s.oldS[x].mul(ni.goodwill).val()].find((v) => v > 0 && v !== s.amt[x].val());
let pool;
if (ch.id === "fixed") { // grid: direction x account
const d = dirOf(s, x), A = rupee(s.amt[x].val());
pool = [{ text: `${d} ${A} in the Capital A/c`, why: "kept capital accounts with fixed capitals", mis: "055-GW-M05" }, { text: `${flip(d)} ${A} in the Current A/c`, why: "reversed", mis: "055-GW-M01" }, { text: `${flip(d)} ${A} in the Capital A/c`, why: "reversed, and capital accounts", mis: "055-GW-M01" }];
} else if (s.role[x] === "same") {
const d = dirOf(base, x);
pool = [{ text: before, why: "assumed nothing changes", mis: "055-GW-M08" }, { text: `${flip(d)} ${rupee(base.amt[x].val())}${ac(ni)}`, why: "reversed", mis: "055-GW-M01" }, amtAlt ? { text: `${d} ${rupee(amtAlt === base.amt[x].val() ? s.newS[x].mul(ni.goodwill).val() : amtAlt)}${ac(ni)}`, why: "wrong amount", mis: "055-GW-M04" } : null].filter(Boolean);
} else { // grid: direction x amount
const d = dirOf(s, x);
pool = amtAlt ? [{ text: `${d} ${rupee(amtAlt)}${ac(ni)}`, why: amtAlt === base.amt[x].val() ? "assumed the amount does not change" : "wrong multiplier", mis: ch.id === "resplit" ? "055-GW-M07" : "055-GW-M04" },
{ text: `${flip(d)} ${rupee(s.amt[x].val())}${ac(ni)}`, why: "reversed direction", mis: "055-GW-M01" }, { text: `${flip(d)} ${rupee(amtAlt)}${ac(ni)}`, why: "reversed, wrong amount", mis: "055-GW-M01" }] : [];
}
const seen = new Set([key]); const ds = [];
for (const p of pool) if (p.text && !/₹0\b/.test(p.text) && !seen.has(p.text)) { seen.add(p.text); ds.push(p); }
if (ds.length < 3) continue;
const q = { type: "mcq", kind: "whatif", group: "core", rule: ch.rule, change: ch.id, prompt: `${D} ${ch.text} What happens to ${P[x]} in the goodwill entry? ${P[x]}…`,
...mcq(r, { key, distractors: ds.slice(0, 3) }),
explanation: `Before: ${P[x]} ${before}. After: ${P[x]}'s share goes from ${shareStr(s.oldS[x])} to ${shareStr(s.newS[x])}, so ${P[x]} ${key}. Rule: ${ni.capitals === "fixed" && ch.rule === "055-GW-A05" ? ATOMS[ch.rule].split("Capital A/cs").join("Current A/cs") : ATOMS[ch.rule]}`,
atom_ids: [ch.rule], misconception_id: ds[0].mis, figure: fig(inst, ["ratios", "entry-correct"], { after: ni }), difficulty: 3, marks: 1, signature: `whatif:${ch.id}` };
// the change must actually move the answer the rule decides (except where the point is that it does NOT move)
q.changeMoves = key !== before; q.changeShouldMove = ch.id !== "resplit";
qs.push(q);
}
return qs;
}
export function checkClassQuestion(q) { // class-specific checks on top of core.checkQuestion
const c = new Checks(q.id);
const inst = q.figure.inst; c.ok("instance passes", checkInstance(inst).passed, "instance fails sensibility checks");
if (q.kind === "whatif") {
c.ok("change alters the tested answer (or proves it does not)", q.changeMoves === q.changeShouldMove, q.changeShouldMove ? "the change did not move the answer" : "the retiring credit moved");
c.ok("changed instance passes", checkInstance(q.figure.after).passed, "changed instance not sensible");
}
if (q.kind === "error") {
const b = rulesBroken(inst, solve(inst), q.figure.entry);
c.ok("shown wrong entry breaks exactly one rule", b.size === 1, `breaks ${[...b].join(",") || "none"}`);
}
if (q.type === "mcq") {
// no distractor may coincide with the computed truth under a different but equivalent wording
c.ok("key not repeated in a distractor", !q.distractors.some((d) => d.text === q.options[q.answer]), "duplicate of key");
}
for (const v of [describe(inst)]) for (const p of inst.partners) c.ok(`stem names ${p}`, v.includes(p), "partner missing from stem");
c.ok("stem gives the goodwill value", q.prompt.includes(rupee(inst.goodwill)), "goodwill not stated");
return c;
}