From 3e1b51bd84a5ecd75d414c7da9d3dfa1fd89f3e5 Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Sat, 8 Nov 2025 07:14:55 -0600 Subject: [PATCH] feat: handle cascading borrows in borrowing hints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve borrowing hints to properly show cascading borrows: - Detect when borrowing from 0 (cascade situation) - Show "10 - 1" for intermediate cascade steps - Show "n - 1" for source non-zero digit - Example: 300 - 157 shows "3 - 1" at hundreds, "10 - 1" at tens This makes the hints pedagogically correct for all subtraction cases, avoiding confusing "0 - 1" displays for young learners. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../create/worksheets/addition/typstHelpers.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/web/src/app/create/worksheets/addition/typstHelpers.ts b/apps/web/src/app/create/worksheets/addition/typstHelpers.ts index 7fd330e1..d22c5eca 100644 --- a/apps/web/src/app/create/worksheets/addition/typstHelpers.ts +++ b/apps/web/src/app/create/worksheets/addition/typstHelpers.ts @@ -435,10 +435,18 @@ export function generateSubtractionProblemStackFunction( let source-color = place-colors.at(i) // This place (giving) let dest-color = place-colors.at(i - 1) // Lower place (receiving) - // When showing hints, add small text showing what value to write + // When showing hints, determine what to display based on cascading if show-borrowing-hints and i <= m-highest { + // Determine the actual value to show in the hint + // For cascading: if this digit is 0, it received 10 from left and gives 1 to right + // So it shows "10 - 1". Otherwise it shows "original - 1" let original-digit = m-digits.at(i) - let reduced-digit = original-digit - 1 + + // Check if this is part of a cascade (is it 0 and needs to borrow?) + let is-cascade = original-digit == 0 + + // The display value is either the original digit or 10 (if cascading) + let display-value = if is-cascade { 10 } else { original-digit } (box(width: ${cellSizeIn}, height: ${cellSizeIn})[ // Show the borrow box with hint text at top @@ -449,7 +457,7 @@ export function generateSubtractionProblemStackFunction( top + center, dy: 2pt, box[ - #text(size: ${(cellSizePt * 0.25).toFixed(1)}pt, fill: white, stroke: 0.3pt + black, weight: "bold")[#str(original-digit) − ] + #text(size: ${(cellSizePt * 0.25).toFixed(1)}pt, fill: white, stroke: 0.3pt + black, weight: "bold")[#str(display-value) − ] #text(size: ${(cellSizePt * 0.25).toFixed(1)}pt, fill: white, stroke: 0.3pt + black, weight: "bold")[1] ] ) @@ -480,7 +488,7 @@ export function generateSubtractionProblemStackFunction( top + center, dy: 2pt, box[ - #text(size: ${(cellSizePt * 0.25).toFixed(1)}pt, fill: gray.darken(30%), weight: "bold")[#str(original-digit) − ] + #text(size: ${(cellSizePt * 0.25).toFixed(1)}pt, fill: gray.darken(30%), weight: "bold")[#str(display-value) − ] #text(size: ${(cellSizePt * 0.25).toFixed(1)}pt, fill: gray.darken(30%), weight: "bold")[1] ] )