diff --git a/src/components/BulgarianSolitaire.tsx b/src/components/BulgarianSolitaire.tsx index 255e985..36f3a88 100644 --- a/src/components/BulgarianSolitaire.tsx +++ b/src/components/BulgarianSolitaire.tsx @@ -14,7 +14,7 @@ interface Box { } const BulgarianSolitaire: React.FC = ({ showSocialShare }) => { - const [n, setN] = useState(3); + const [n, setN] = useState(15); const [boxes, setBoxes] = useState([]); const [columns, setColumns] = useState([]); const [isPlaying, setIsPlaying] = useState(false); @@ -27,7 +27,7 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare const [selectedBoxForMove, setSelectedBoxForMove] = useState(null); const [showInstructions, setShowInstructions] = useState(false); - const totalBoxes = (n * (n + 1)) / 2; + const totalBoxes = n; // Initialize boxes and columns when n changes useEffect(() => { @@ -175,9 +175,15 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare const isTriangularConfiguration = (cols: number[][]) => { const nonEmptyCols = cols.filter(col => col.length > 0).sort((a, b) => a.length - b.length); - if (nonEmptyCols.length !== n) return false; - for (let i = 0; i < n; i++) { + // Check if n is a triangular number and if columns form the staircase pattern + // Find k such that k*(k+1)/2 = n + const k = Math.floor((-1 + Math.sqrt(1 + 8 * n)) / 2); + if (k * (k + 1) / 2 !== n) return false; // n is not a triangular number + + if (nonEmptyCols.length !== k) return false; + + for (let i = 0; i < k; i++) { if (nonEmptyCols[i].length !== i + 1) return false; } return true; @@ -330,12 +336,12 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare {/* Controls */}
- + setN(value[0])} - min={2} - max={6} + min={3} + max={45} step={1} className="w-32" disabled={isPlaying} @@ -451,13 +457,13 @@ const BulgarianSolitaire: React.FC = ({ showSocialShare {showInstructions && (
    -
  • Choose a value for n (2-6) using the slider
  • +
  • Choose a value for n (3-45) using the slider
  • Drag the {totalBoxes} boxes from the container into any of the columns
  • Drag boxes between columns to rearrange them as needed
  • Drag boxes back to the container or double-click any box in a column to move it to the last-used column
  • Once all boxes are placed in columns, click "Play" to start the simulation
  • Watch as the algorithm takes one box from each non-empty column to form a new column
  • -
  • The process continues until reaching the triangular configuration: columns of sizes 1, 2, 3, ..., n
  • +
  • Spoiler: For triangular numbers, the process continues until reaching the staircase configuration: columns of sizes 1, 2, 3, ..., n.
)}