{"mdx_file":"2416a2a2-3b84-4a4f-9706-27ec64420715.mdx","tinygrad_starter_code":"ZnJvbSB0aW55Z3JhZC50ZW5zb3IgaW1wb3J0IFRlbnNvcgoKZGVmIG1hdHJpeF9kb3RfdmVjdG9yX3RnKGE6VGVuc29yLCBiOlRlbnNvcikgLT4gVGVuc29yOgogICAgIiIiCiAgICBDb21wdXRlIHRoZSBwcm9kdWN0IG9mIG1hdHJpeCBgYWAgYW5kIHZlY3RvciBgYmAgdXNpbmcgdGlueWdyYWQuCiAgICBXaWxsIGJlIHRpbnlncmFkIFRlbnNvcnMuCiAgICBSZXR1cm5zIGEgMS1EIFRlbnNvciBvZiBsZW5ndGggbSwgb3IgVGVuc29yKC0xKSBpZiBkaW1lbnNpb25zIG1pc21hdGNoLgogICAgIiIiCiAgICBwYXNzCg==","last_updated":"2026-11-10T18:23:19.610657+00:00","test_cases":[{"test":"print(matrix_dot_vector([[1, 2, 3], [2, 4, 5], [6, 8, 9]], [1, 2, 3]))","expected_output":"[14, 25, 49]"},{"test":"print(matrix_dot_vector([[1, 2], [2, 4], [6, 8], [12, 4]], [1, 2, 3]))","expected_output":"-1"}],"pytorch_difficulty":"easy","likes":"0","video":"https://youtu.be/DNoLs5tTGAw?si=vpkPobZMA8YY10WY","cuda_test_cases":[{"test":"#include <iostream>\n#include <vector>\n\nstd::vector<float> matrix_dot_vector(const std::vector<std::vector<float>>& matrix, const std::vector<float>& vec);\n\nint main() {\n    std::vector<std::vector<float>> matrix = {{1, 2, 3}, {2, 4, 5}, {6, 8, 9}};\n    std::vector<float> vec = {1, 2, 3};\n    auto result = matrix_dot_vector(matrix, vec);\n    std::cout << \"[\";\n    for (int i = 0; i < result.size(); i++) {\n        std::cout << result[i];\n        if (i < result.size() - 1) std::cout << \", \";\n    }\n    std::cout << \"]\" << std::endl;\n    return 0;\n}","expected_output":"[14, 25, 49]"},{"test":"#include <iostream>\n#include <vector>\n\nstd::vector<float> matrix_dot_vector(const std::vector<std::vector<float>>& matrix, const std::vector<float>& vec);\n\nint main() {\n    std::vector<std::vector<float>> matrix = {{1, 2}, {2, 4}, {6, 8}, {12, 4}};\n    std::vector<float> vec = {1, 2, 3};\n    auto result = matrix_dot_vector(matrix, vec);\n    std::cout << result[0] << std::endl;\n    return 0;\n}","expected_output":"-1"}],"example":{"input":"a = [[1, 2], [2, 4]], b = [1, 2]","output":"[5, 10]","reasoning":"Row 1: (1 * 1) + (2 * 2) = 1 + 4 = 5; Row 2: (2 * 1) + (4 * 2) = 2 + 8 = 10"},"pytorch_starter_code":"aW1wb3J0IHRvcmNoCgpkZWYgbWF0cml4X2RvdF92ZWN0b3IoYSwgYikgLT4gdG9yY2guVGVuc29yOgogICAgIiIiCiAgICBDb21wdXRlIHRoZSBwcm9kdWN0IG9mIG1hdHJpeCBgYWAgYW5kIHZlY3RvciBgYmAgdXNpbmcgUHlUb3JjaC4KICAgIElucHV0cyBjYW4gYmUgUHl0aG9uIGxpc3RzLCBOdW1QeSBhcnJheXMsIG9yIHRvcmNoIFRlbnNvcnMuCiAgICBSZXR1cm5zIGEgMS1EIHRlbnNvciBvZiBsZW5ndGggbSwgb3IgdGVuc29yKC0xKSBpZiBkaW1lbnNpb25zIG1pc21hdGNoLgogICAgIiIiCiAgICAjIFlvdXIgaW1wbGVtZW50YXRpb24gaGVyZQogICAgcGFzcwo=","learn_section":"CiMjIE1hdHJpeC1WZWN0b3IgRG90IFByb2R1Y3QKCkNvbnNpZGVyIGEgbWF0cml4ICRBJCBhbmQgYSB2ZWN0b3IgJHYkOgoKKipNYXRyaXggJEEkIChuIHggbSk6KioKJCQKQSA9IFxiZWdpbntwbWF0cml4fQphX3sxMX0gJiBhX3sxMn0gJiBcY2RvdHMgJiBhX3sxbX0gXFwKYV97MjF9ICYgYV97MjJ9ICYgXGNkb3RzICYgYV97Mm19IFxcClx2ZG90cyAmIFx2ZG90cyAmIFxkZG90cyAmIFx2ZG90cyBcXAphX3tuMX0gJiBhX3tuMn0gJiBcY2RvdHMgJiBhX3tubX0KXGVuZHtwbWF0cml4fQokJAoKKipWZWN0b3IgJHYkIChsZW5ndGggbSk6KioKJCQKdiA9IFxiZWdpbntwbWF0cml4fQp2XzEgXFwKdl8yIFxcClx2ZG90cyBcXAp2X20KXGVuZHtwbWF0cml4fQokJAoKVGhlIGRvdCBwcm9kdWN0ICRBIFxjZG90IHYkIHByb2R1Y2VzIGEgbmV3IHZlY3RvciBvZiBsZW5ndGggJG4kOgokJApBIFxjZG90IHYgPSBcYmVnaW57cG1hdHJpeH0KYV97MTF9dl8xICsgYV97MTJ9dl8yICsgXGNkb3RzICsgYV97MW19dl9tIFxcCmFfezIxfXZfMSArIGFfezIyfXZfMiArIFxjZG90cyArIGFfezJtfXZfbSBcXApcdmRvdHMgXFwKYV97bjF9dl8xICsgYV97bjJ9dl8yICsgXGNkb3RzICsgYV97bm19dl9tClxlbmR7cG1hdHJpeH0KJCQKCiMjIyBLZXkgUmVxdWlyZW1lbnQ6ClRoZSBudW1iZXIgb2YgY29sdW1ucyBpbiB0aGUgbWF0cml4ICgkbSQpIG11c3QgZXF1YWwgdGhlIGxlbmd0aCBvZiB0aGUgdmVjdG9yICgkbSQpLiBJZiBub3QsIHRoZSBvcGVyYXRpb24gaXMgdW5kZWZpbmVkLCBhbmQgdGhlIGZ1bmN0aW9uIHNob3VsZCByZXR1cm4gLTEu","cuda_starter_code":"I2luY2x1ZGUgPGN1ZGFfcnVudGltZS5oPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CgpfX2dsb2JhbF9fIHZvaWQgbWF0cml4X3ZlY3Rvcl9kb3Rfa2VybmVsKAogICAgY29uc3QgZmxvYXQqIG1hdHJpeCwKICAgIGNvbnN0IGZsb2F0KiB2ZWN0b3IsCiAgICBmbG9hdCogcmVzdWx0LAogICAgaW50IHJvd3MsCiAgICBpbnQgY29scwopIHsKICAgIC8vIEltcGxlbWVudCB0aGUga2VybmVsIHRvIGNvbXB1dGUgbWF0cml4LXZlY3RvciBkb3QgcHJvZHVjdAogICAgLy8gRWFjaCB0aHJlYWQgY29tcHV0ZXMgb25lIGVsZW1lbnQgb2YgdGhlIHJlc3VsdCB2ZWN0b3IKfQoKc3RkOjp2ZWN0b3I8ZmxvYXQ+IG1hdHJpeF9kb3RfdmVjdG9yKGNvbnN0IHN0ZDo6dmVjdG9yPHN0ZDo6dmVjdG9yPGZsb2F0Pj4mIG1hdHJpeCwgY29uc3Qgc3RkOjp2ZWN0b3I8ZmxvYXQ+JiB2ZWMpIHsKICAgIC8vIFJldHVybiBlbXB0eSB2ZWN0b3IgaWYgZGltZW5zaW9ucyBkb24ndCBtYXRjaAogICAgLy8gMS4gQWxsb2NhdGUgZGV2aWNlIG1lbW9yeQogICAgLy8gMi4gQ29weSBkYXRhIHRvIGRldmljZQogICAgLy8gMy4gTGF1bmNoIGtlcm5lbAogICAgLy8gNC4gQ29weSByZXN1bHQgYmFjawogICAgLy8gNS4gRnJlZSBtZW1vcnkgYW5kIHJldHVybiByZXN1bHQKICAgIHJldHVybiB7fTsKfQ==","contributor":[{"profile_link":"https://github.com/moe18","name":"Moe Chabot"}],"tinygrad_test_cases":[{"test":"from tinygrad.tensor import Tensor\nres = matrix_dot_vector_tg(\n    Tensor([[1,2,3],[2,4,5],[6,8,9]]),\n    Tensor([1,2,3])\n)\nprint(res.numpy().tolist())","expected_output":"[14.0, 25.0, 49.0]"},{"test":"from tinygrad.tensor import Tensor\nres = matrix_dot_vector_tg(\n    Tensor([[1,2,3],[2,4,5]]),\n    Tensor([1,2])\n)\nprint(res.item())","expected_output":"-1"}],"description":"V3JpdGUgYSBQeXRob24gZnVuY3Rpb24gdGhhdCBjb21wdXRlcyB0aGUgZG90IHByb2R1Y3Qgb2YgYSBtYXRyaXggYW5kIGEgdmVjdG9yLiBUaGUgZnVuY3Rpb24gc2hvdWxkIHJldHVybiBhIGxpc3QgcmVwcmVzZW50aW5nIHRoZSByZXN1bHRpbmcgdmVjdG9yIGlmIHRoZSBvcGVyYXRpb24gaXMgdmFsaWQsIG9yIC0xIGlmIHRoZSBtYXRyaXggYW5kIHZlY3RvciBkaW1lbnNpb25zIGFyZSBpbmNvbXBhdGlibGUuIEEgbWF0cml4IChhIGxpc3Qgb2YgbGlzdHMpIGNhbiBiZSBkb3R0ZWQgd2l0aCBhIHZlY3RvciAoYSBsaXN0KSBvbmx5IGlmIHRoZSBudW1iZXIgb2YgY29sdW1ucyBpbiB0aGUgbWF0cml4IGVxdWFscyB0aGUgbGVuZ3RoIG9mIHRoZSB2ZWN0b3IuIEZvciBleGFtcGxlLCBhbiBuIHggbSBtYXRyaXggcmVxdWlyZXMgYSB2ZWN0b3Igb2YgbGVuZ3RoIG0u","id":"1","tinygrad_difficulty":"easy","playground":{"dependencies":{},"enabled":true,"type":"react","settings":{"editorHeight":600,"showPreview":true,"theme":"dark","showEditor":false,"editorWidthPercentage":35,"showConsole":false},"files":{"/App.js":{"active":true,"code":"import React, { useState, useMemo } from 'react';\n\n// ============================================\n// Inline SVG Icons (replaces lucide-react)\n// ============================================\nconst Icons = {\n  Grid3X3: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"/><path d=\"M3 9h18\"/><path d=\"M3 15h18\"/><path d=\"M9 3v18\"/><path d=\"M15 3v18\"/>\n    </svg>\n  ),\n  ArrowRight: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <path d=\"M5 12h14\"/><path d=\"m12 5 7 7-7 7\"/>\n    </svg>\n  ),\n  X: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <path d=\"M18 6 6 18\"/><path d=\"m6 6 12 12\"/>\n    </svg>\n  ),\n  Check: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <polyline points=\"20 6 9 17 4 12\"/>\n    </svg>\n  ),\n  AlertCircle: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <circle cx=\"12\" cy=\"12\" r=\"10\"/><line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"12\"/><line x1=\"12\" y1=\"16\" x2=\"12.01\" y2=\"16\"/>\n    </svg>\n  ),\n  Play: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <polygon points=\"5 3 19 12 5 21 5 3\"/>\n    </svg>\n  ),\n  RotateCcw: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\"/><path d=\"M3 3v5h5\"/>\n    </svg>\n  ),\n  ChevronDown: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <polyline points=\"6 9 12 15 18 9\"/>\n    </svg>\n  ),\n  ChevronUp: ({ size = 24, color = 'currentColor' }) => (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke={color} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n      <polyline points=\"18 15 12 9 6 15\"/>\n    </svg>\n  ),\n};\n\n// ============================================\n// Design Tokens\n// ============================================\nconst theme = {\n  colors: {\n    primary: '#6366f1',\n    primaryHover: '#4f46e5',\n    secondary: '#ffffff',\n    background: '#000000',\n    surface: '#0a0a0a',\n    surfaceAlt: '#111111',\n    border: '#1f1f1f',\n    borderLight: '#2a2a2a',\n    text: '#ffffff',\n    textSecondary: '#a1a1aa',\n    textMuted: '#71717a',\n    success: '#22c55e',\n    error: '#ef4444',\n    highlight: '#6366f1',\n  },\n  font: \"'JetBrains Mono', monospace\",\n};\n\n// ============================================\n// Card Component\n// ============================================\nfunction Card({ children, className = '' }) {\n  return (\n    <div\n      style={{\n        background: theme.colors.surface,\n        border: `1px solid ${theme.colors.border}`,\n        borderRadius: '12px',\n        padding: '24px',\n      }}\n      className={className}\n    >\n      {children}\n    </div>\n  );\n}\n\n// ============================================\n// Matrix Cell\n// ============================================\nfunction MatrixCell({ value, onChange, highlighted, highlightColor, editable = true }) {\n  return (\n    <input\n      type=\"number\"\n      value={value}\n      onChange={(e) => onChange(parseFloat(e.target.value) || 0)}\n      disabled={!editable}\n      style={{\n        width: '48px',\n        height: '48px',\n        background: highlighted ? `${highlightColor}20` : theme.colors.surfaceAlt,\n        border: `2px solid ${highlighted ? highlightColor : theme.colors.border}`,\n        borderRadius: '8px',\n        color: highlighted ? highlightColor : theme.colors.text,\n        fontFamily: theme.font,\n        fontSize: '16px',\n        fontWeight: '600',\n        textAlign: 'center',\n        outline: 'none',\n        transition: 'all 0.2s ease',\n      }}\n    />\n  );\n}\n\n// ============================================\n// Vector Cell\n// ============================================\nfunction VectorCell({ value, onChange, highlighted, highlightColor, editable = true }) {\n  return (\n    <input\n      type=\"number\"\n      value={value}\n      onChange={(e) => onChange(parseFloat(e.target.value) || 0)}\n      disabled={!editable}\n      style={{\n        width: '48px',\n        height: '48px',\n        background: highlighted ? `${highlightColor}20` : theme.colors.surfaceAlt,\n        border: `2px solid ${highlighted ? highlightColor : theme.colors.border}`,\n        borderRadius: '8px',\n        color: highlighted ? highlightColor : theme.colors.text,\n        fontFamily: theme.font,\n        fontSize: '16px',\n        fontWeight: '600',\n        textAlign: 'center',\n        outline: 'none',\n        transition: 'all 0.2s ease',\n      }}\n    />\n  );\n}\n\n// ============================================\n// Result Bar\n// ============================================\nfunction ResultBar({ value, maxValue, index, highlighted }) {\n  const percentage = Math.min(Math.abs(value) / maxValue * 100, 100);\n  const isNegative = value < 0;\n  \n  return (\n    <div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>\n      <div\n        style={{\n          width: '36px',\n          height: '36px',\n          borderRadius: '8px',\n          background: highlighted ? theme.colors.primary : theme.colors.surfaceAlt,\n          border: `1px solid ${highlighted ? theme.colors.primary : theme.colors.border}`,\n          display: 'flex',\n          alignItems: 'center',\n          justifyContent: 'center',\n          fontFamily: theme.font,\n          fontSize: '14px',\n          fontWeight: '600',\n          color: highlighted ? theme.colors.secondary : theme.colors.textSecondary,\n        }}\n      >\n        {index + 1}\n      </div>\n      <div style={{ flex: 1 }}>\n        <div\n          style={{\n            height: '24px',\n            background: theme.colors.surfaceAlt,\n            borderRadius: '6px',\n            overflow: 'hidden',\n            position: 'relative',\n          }}\n        >\n          <div\n            style={{\n              position: 'absolute',\n              left: isNegative ? 'auto' : '0',\n              right: isNegative ? '50%' : 'auto',\n              width: `${percentage / 2}%`,\n              height: '100%',\n              background: highlighted \n                ? `linear-gradient(90deg, ${theme.colors.primary}, ${theme.colors.primaryHover})`\n                : theme.colors.borderLight,\n              borderRadius: '6px',\n              transition: 'width 0.3s ease',\n            }}\n          />\n          <div\n            style={{\n              position: 'absolute',\n              left: '50%',\n              top: '0',\n              bottom: '0',\n              width: '1px',\n              background: theme.colors.border,\n            }}\n          />\n        </div>\n      </div>\n      <div\n        style={{\n          minWidth: '60px',\n          textAlign: 'right',\n          fontFamily: theme.font,\n          fontSize: '16px',\n          fontWeight: '700',\n          color: highlighted ? theme.colors.primary : theme.colors.text,\n        }}\n      >\n        {value.toFixed(1)}\n      </div>\n    </div>\n  );\n}\n\n// ============================================\n// Calculation Step\n// ============================================\nfunction CalculationStep({ row, vector, rowIndex, isActive }) {\n  const products = row.map((val, i) => val * vector[i]);\n  const sum = products.reduce((a, b) => a + b, 0);\n  \n  if (!isActive) return null;\n  \n  return (\n    <div\n      style={{\n        background: theme.colors.surfaceAlt,\n        border: `1px solid ${theme.colors.primary}40`,\n        borderRadius: '8px',\n        padding: '16px',\n        marginTop: '16px',\n      }}\n    >\n      <div style={{ \n        fontSize: '12px', \n        color: theme.colors.textMuted, \n        marginBottom: '12px',\n        fontFamily: theme.font,\n        textTransform: 'uppercase',\n        letterSpacing: '0.5px',\n      }}>\n        Row {rowIndex + 1} Calculation\n      </div>\n      \n      <div style={{ \n        display: 'flex', \n        flexWrap: 'wrap',\n        alignItems: 'center', \n        gap: '8px',\n        fontFamily: theme.font,\n        fontSize: '14px',\n      }}>\n        {row.map((val, i) => (\n          <React.Fragment key={i}>\n            {i > 0 && <span style={{ color: theme.colors.textMuted }}>+</span>}\n            <span style={{ color: theme.colors.textSecondary }}>\n              (<span style={{ color: theme.colors.primary }}>{val}</span>\n              <span style={{ color: theme.colors.textMuted }}> × </span>\n              <span style={{ color: theme.colors.success }}>{vector[i]}</span>)\n            </span>\n          </React.Fragment>\n        ))}\n        <span style={{ color: theme.colors.textMuted }}>=</span>\n        {products.map((p, i) => (\n          <React.Fragment key={i}>\n            {i > 0 && <span style={{ color: theme.colors.textMuted }}>+</span>}\n            <span style={{ color: theme.colors.textSecondary }}>{p}</span>\n          </React.Fragment>\n        ))}\n        <span style={{ color: theme.colors.textMuted }}>=</span>\n        <span style={{ \n          color: theme.colors.text, \n          fontWeight: '700',\n          background: theme.colors.primary + '20',\n          padding: '2px 8px',\n          borderRadius: '4px',\n        }}>\n          {sum}\n        </span>\n      </div>\n    </div>\n  );\n}\n\n// ============================================\n// Main Component\n// ============================================\nexport default function MatrixVectorDot() {\n  const [matrix, setMatrix] = useState([\n    [1, 2, 3],\n    [4, 5, 6],\n    [7, 8, 9],\n  ]);\n  const [vector, setVector] = useState([1, 2, 3]);\n  const [activeRow, setActiveRow] = useState(null);\n  const [isAnimating, setIsAnimating] = useState(false);\n  const [showSteps, setShowSteps] = useState(false);\n  \n  const rows = matrix.length;\n  const cols = matrix[0].length;\n  const vectorLen = vector.length;\n  const isValid = cols === vectorLen;\n  \n  const result = useMemo(() => {\n    if (!isValid) return null;\n    return matrix.map(row => \n      row.reduce((sum, val, i) => sum + val * vector[i], 0)\n    );\n  }, [matrix, vector, isValid]);\n  \n  const maxResult = result ? Math.max(...result.map(Math.abs), 1) : 1;\n  \n  const updateMatrix = (rowIdx, colIdx, value) => {\n    const newMatrix = matrix.map((row, r) =>\n      row.map((cell, c) => (r === rowIdx && c === colIdx ? value : cell))\n    );\n    setMatrix(newMatrix);\n  };\n  \n  const updateVector = (idx, value) => {\n    const newVector = vector.map((v, i) => (i === idx ? value : v));\n    setVector(newVector);\n  };\n  \n  const addRow = () => setMatrix([...matrix, Array(cols).fill(0)]);\n  const removeRow = () => rows > 1 && setMatrix(matrix.slice(0, -1));\n  const addCol = () => {\n    setMatrix(matrix.map(row => [...row, 0]));\n    setVector([...vector, 0]);\n  };\n  const removeCol = () => {\n    if (cols > 1) {\n      setMatrix(matrix.map(row => row.slice(0, -1)));\n      setVector(vector.slice(0, -1));\n    }\n  };\n  \n  const animate = async () => {\n    setIsAnimating(true);\n    setShowSteps(true);\n    for (let i = 0; i < rows; i++) {\n      setActiveRow(i);\n      await new Promise(r => setTimeout(r, 800));\n    }\n    setActiveRow(null);\n    setIsAnimating(false);\n  };\n  \n  const reset = () => {\n    setMatrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);\n    setVector([1, 2, 3]);\n    setActiveRow(null);\n    setShowSteps(false);\n  };\n\n  return (\n    <div\n      style={{\n        minHeight: '100vh',\n        background: theme.colors.background,\n        color: theme.colors.text,\n        fontFamily: theme.font,\n        padding: '32px',\n      }}\n    >\n      <div style={{ maxWidth: '720px', margin: '0 auto' }}>\n        {/* Header */}\n        <div style={{ marginBottom: '32px' }}>\n          <div style={{ display: 'flex', alignItems: 'center', gap: '12px', marginBottom: '8px' }}>\n            <Icons.Grid3X3 size={24} color={theme.colors.primary} />\n            <h1 style={{ fontSize: '24px', fontWeight: '600', margin: 0 }}>\n              Matrix-Vector Dot Product\n            </h1>\n          </div>\n          <p style={{ color: theme.colors.textSecondary, fontSize: '14px', margin: 0 }}>\n            Each row of the matrix is dotted with the vector to produce a result\n          </p>\n        </div>\n        \n        {/* Dimension Controls */}\n        <Card>\n          <div style={{ \n            display: 'flex', \n            justifyContent: 'space-between', \n            alignItems: 'center',\n            marginBottom: '24px',\n          }}>\n            <div style={{ fontSize: '12px', color: theme.colors.textMuted, textTransform: 'uppercase', letterSpacing: '0.5px' }}>\n              Dimensions\n            </div>\n            <div style={{ display: 'flex', gap: '8px' }}>\n              <div style={{ \n                padding: '6px 12px', \n                background: theme.colors.surfaceAlt, \n                borderRadius: '6px',\n                fontSize: '13px',\n                color: theme.colors.textSecondary,\n              }}>\n                Matrix: {rows} × {cols}\n              </div>\n              <div style={{ \n                padding: '6px 12px', \n                background: theme.colors.surfaceAlt, \n                borderRadius: '6px',\n                fontSize: '13px',\n                color: theme.colors.textSecondary,\n              }}>\n                Vector: {vectorLen}\n              </div>\n            </div>\n          </div>\n          \n          <div style={{ display: 'flex', gap: '8px', flexWrap: 'wrap' }}>\n            {[\n              { label: '+ Row', action: addRow },\n              { label: '- Row', action: removeRow },\n              { label: '+ Col', action: addCol },\n              { label: '- Col', action: removeCol },\n            ].map(({ label, action }) => (\n              <button\n                key={label}\n                onClick={action}\n                style={{\n                  padding: '8px 16px',\n                  background: theme.colors.surfaceAlt,\n                  border: `1px solid ${theme.colors.border}`,\n                  borderRadius: '6px',\n                  color: theme.colors.textSecondary,\n                  fontFamily: theme.font,\n                  fontSize: '13px',\n                  cursor: 'pointer',\n                  transition: 'all 0.2s',\n                }}\n                onMouseEnter={(e) => {\n                  e.target.style.background = theme.colors.borderLight;\n                  e.target.style.color = theme.colors.text;\n                }}\n                onMouseLeave={(e) => {\n                  e.target.style.background = theme.colors.surfaceAlt;\n                  e.target.style.color = theme.colors.textSecondary;\n                }}\n              >\n                {label}\n              </button>\n            ))}\n          </div>\n        </Card>\n        \n        {/* Main Visualization */}\n        <Card style={{ marginTop: '16px' }}>\n          {/* Validity Status */}\n          <div\n            style={{\n              display: 'flex',\n              alignItems: 'center',\n              gap: '8px',\n              padding: '12px 16px',\n              background: isValid ? `${theme.colors.success}10` : `${theme.colors.error}10`,\n              border: `1px solid ${isValid ? theme.colors.success : theme.colors.error}30`,\n              borderRadius: '8px',\n              marginBottom: '24px',\n            }}\n          >\n            {isValid ? (\n              <Icons.Check size={16} color={theme.colors.success} />\n            ) : (\n              <Icons.AlertCircle size={16} color={theme.colors.error} />\n            )}\n            <span style={{ \n              fontSize: '13px', \n              color: isValid ? theme.colors.success : theme.colors.error \n            }}>\n              {isValid \n                ? `Valid: ${cols} columns = ${vectorLen} vector length`\n                : `Invalid: ${cols} columns ≠ ${vectorLen} vector length`\n              }\n            </span>\n          </div>\n          \n          {/* Matrix × Vector = Result */}\n          <div style={{ \n            display: 'flex', \n            alignItems: 'center', \n            gap: '24px',\n            flexWrap: 'wrap',\n            justifyContent: 'center',\n          }}>\n            {/* Matrix */}\n            <div>\n              <div style={{ \n                fontSize: '11px', \n                color: theme.colors.textMuted, \n                marginBottom: '8px',\n                textTransform: 'uppercase',\n                letterSpacing: '0.5px',\n              }}>\n                Matrix A\n              </div>\n              <div\n                style={{\n                  display: 'inline-flex',\n                  flexDirection: 'column',\n                  gap: '8px',\n                  padding: '12px',\n                  background: theme.colors.surfaceAlt,\n                  borderRadius: '8px',\n                  border: `1px solid ${theme.colors.border}`,\n                }}\n              >\n                {matrix.map((row, rowIdx) => (\n                  <div key={rowIdx} style={{ display: 'flex', gap: '8px' }}>\n                    {row.map((cell, colIdx) => (\n                      <MatrixCell\n                        key={colIdx}\n                        value={cell}\n                        onChange={(v) => updateMatrix(rowIdx, colIdx, v)}\n                        highlighted={activeRow === rowIdx}\n                        highlightColor={theme.colors.primary}\n                      />\n                    ))}\n                  </div>\n                ))}\n              </div>\n            </div>\n            \n            {/* Multiply Icon */}\n            <Icons.X size={20} color={theme.colors.textMuted} />\n            \n            {/* Vector */}\n            <div>\n              <div style={{ \n                fontSize: '11px', \n                color: theme.colors.textMuted, \n                marginBottom: '8px',\n                textTransform: 'uppercase',\n                letterSpacing: '0.5px',\n              }}>\n                Vector b\n              </div>\n              <div\n                style={{\n                  display: 'inline-flex',\n                  flexDirection: 'column',\n                  gap: '8px',\n                  padding: '12px',\n                  background: theme.colors.surfaceAlt,\n                  borderRadius: '8px',\n                  border: `1px solid ${theme.colors.border}`,\n                }}\n              >\n                {vector.map((val, idx) => (\n                  <VectorCell\n                    key={idx}\n                    value={val}\n                    onChange={(v) => updateVector(idx, v)}\n                    highlighted={activeRow !== null}\n                    highlightColor={theme.colors.success}\n                  />\n                ))}\n              </div>\n            </div>\n            \n            {/* Equals */}\n            <Icons.ArrowRight size={20} color={theme.colors.textMuted} />\n            \n            {/* Result */}\n            <div>\n              <div style={{ \n                fontSize: '11px', \n                color: theme.colors.textMuted, \n                marginBottom: '8px',\n                textTransform: 'uppercase',\n                letterSpacing: '0.5px',\n              }}>\n                Result\n              </div>\n              <div\n                style={{\n                  display: 'inline-flex',\n                  flexDirection: 'column',\n                  gap: '8px',\n                  padding: '12px',\n                  background: theme.colors.surfaceAlt,\n                  borderRadius: '8px',\n                  border: `1px solid ${theme.colors.border}`,\n                  minWidth: '60px',\n                }}\n              >\n                {isValid && result ? (\n                  result.map((val, idx) => (\n                    <div\n                      key={idx}\n                      style={{\n                        height: '48px',\n                        padding: '0 12px',\n                        display: 'flex',\n                        alignItems: 'center',\n                        justifyContent: 'center',\n                        background: activeRow === idx ? `${theme.colors.primary}20` : 'transparent',\n                        border: `2px solid ${activeRow === idx ? theme.colors.primary : 'transparent'}`,\n                        borderRadius: '8px',\n                        fontWeight: '700',\n                        fontSize: '16px',\n                        color: activeRow === idx ? theme.colors.primary : theme.colors.text,\n                        transition: 'all 0.2s',\n                      }}\n                    >\n                      {val}\n                    </div>\n                  ))\n                ) : (\n                  <div\n                    style={{\n                      height: '48px',\n                      padding: '0 12px',\n                      display: 'flex',\n                      alignItems: 'center',\n                      justifyContent: 'center',\n                      color: theme.colors.error,\n                      fontWeight: '700',\n                      fontSize: '16px',\n                    }}\n                  >\n                    -1\n                  </div>\n                )}\n              </div>\n            </div>\n          </div>\n          \n          {/* Calculation Steps */}\n          {showSteps && isValid && (\n            <div style={{ marginTop: '24px' }}>\n              {matrix.map((row, idx) => (\n                <CalculationStep\n                  key={idx}\n                  row={row}\n                  vector={vector}\n                  rowIndex={idx}\n                  isActive={activeRow === null || activeRow === idx}\n                />\n              ))}\n            </div>\n          )}\n          \n          {/* Controls - moved here, closer to animation */}\n          <div style={{ display: 'flex', gap: '12px', marginTop: '24px' }}>\n            <button\n              onClick={animate}\n              disabled={!isValid || isAnimating}\n              style={{\n                flex: 1,\n                display: 'flex',\n                alignItems: 'center',\n                justifyContent: 'center',\n                gap: '8px',\n                padding: '14px 24px',\n                background: isValid ? theme.colors.primary : theme.colors.surfaceAlt,\n                border: 'none',\n                borderRadius: '8px',\n                color: isValid ? theme.colors.secondary : theme.colors.textMuted,\n                fontFamily: theme.font,\n                fontSize: '14px',\n                fontWeight: '600',\n                cursor: isValid ? 'pointer' : 'not-allowed',\n                opacity: isAnimating ? 0.7 : 1,\n                transition: 'all 0.2s',\n              }}\n            >\n              <Icons.Play size={16} />\n              {isAnimating ? 'Animating...' : 'Animate Steps'}\n            </button>\n            \n            <button\n              onClick={() => setShowSteps(!showSteps)}\n              disabled={!isValid}\n              style={{\n                display: 'flex',\n                alignItems: 'center',\n                justifyContent: 'center',\n                gap: '8px',\n                padding: '14px 24px',\n                background: theme.colors.surfaceAlt,\n                border: `1px solid ${theme.colors.border}`,\n                borderRadius: '8px',\n                color: theme.colors.textSecondary,\n                fontFamily: theme.font,\n                fontSize: '14px',\n                fontWeight: '500',\n                cursor: isValid ? 'pointer' : 'not-allowed',\n              }}\n            >\n              {showSteps ? <Icons.ChevronUp size={16} /> : <Icons.ChevronDown size={16} />}\n              {showSteps ? 'Hide' : 'Show'} Math\n            </button>\n            \n            <button\n              onClick={reset}\n              style={{\n                display: 'flex',\n                alignItems: 'center',\n                justifyContent: 'center',\n                gap: '8px',\n                padding: '14px 24px',\n                background: theme.colors.surfaceAlt,\n                border: `1px solid ${theme.colors.border}`,\n                borderRadius: '8px',\n                color: theme.colors.textSecondary,\n                fontFamily: theme.font,\n                fontSize: '14px',\n                fontWeight: '500',\n                cursor: 'pointer',\n              }}\n            >\n              <Icons.RotateCcw size={16} />\n              Reset\n            </button>\n          </div>\n        </Card>\n        \n        {/* Result Bars */}\n        {isValid && result && (\n          <Card style={{ marginTop: '16px' }}>\n            <div style={{ \n              fontSize: '11px', \n              color: theme.colors.textMuted, \n              marginBottom: '16px',\n              textTransform: 'uppercase',\n              letterSpacing: '0.5px',\n            }}>\n              Result Visualization\n            </div>\n            <div style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>\n              {result.map((val, idx) => (\n                <ResultBar\n                  key={idx}\n                  value={val}\n                  maxValue={maxResult}\n                  index={idx}\n                  highlighted={activeRow === idx || activeRow === null}\n                />\n              ))}\n            </div>\n          </Card>\n        )}\n        \n        {/* Code Output */}\n        <Card style={{ marginTop: '16px' }}>\n          <div style={{ \n            fontSize: '11px', \n            color: theme.colors.textMuted, \n            marginBottom: '12px',\n            textTransform: 'uppercase',\n            letterSpacing: '0.5px',\n          }}>\n            Python Output\n          </div>\n          <pre\n            style={{\n              margin: 0,\n              padding: '16px',\n              background: theme.colors.background,\n              borderRadius: '8px',\n              fontSize: '13px',\n              overflow: 'auto',\n            }}\n          >\n            <code>\n              <span style={{ color: theme.colors.textMuted }}># Input</span>\n              {'\\n'}\n              <span style={{ color: theme.colors.primary }}>matrix_dot_vector</span>\n              <span style={{ color: theme.colors.text }}>(</span>\n              {'\\n'}\n              <span style={{ color: theme.colors.textSecondary }}>    {JSON.stringify(matrix)},</span>\n              {'\\n'}\n              <span style={{ color: theme.colors.success }}>    {JSON.stringify(vector)}</span>\n              {'\\n'}\n              <span style={{ color: theme.colors.text }}>)</span>\n              {'\\n\\n'}\n              <span style={{ color: theme.colors.textMuted }}># Output</span>\n              {'\\n'}\n              <span style={{ color: theme.colors.text }}>\n                {isValid ? JSON.stringify(result) : '-1'}\n              </span>\n            </code>\n          </pre>\n        </Card>\n      </div>\n    </div>\n  );\n}"}}},"difficulty":"easy","cuda_difficulty":"medium","lesson":{"height":720,"duration":145.6,"video_url":"https://storage.googleapis.com/deep-machine-learning-9d7d0.firebasestorage.app/lessons/problem_0001/v2/lesson.mp4","poster_url":"https://storage.googleapis.com/deep-machine-learning-9d7d0.firebasestorage.app/lessons/problem_0001/v2/poster.jpg","quiz":{"filled":[125.45,135.15],"resume":114.717,"answers":[8,11],"pause":113.917,"labels":["Row 1 answer","Row 2 answer"],"panel_y":0.68125,"boxes":[{"y":0.3225,"h":0.1125,"w":0.06328,"x":0.70742},{"y":0.4525,"h":0.1125,"w":0.06328,"x":0.70742}]},"version":2,"width":1280,"published_at":"2026-10-08T19:09:11+00:00","fx":{"show":"https://storage.googleapis.com/deep-machine-learning-9d7d0.firebasestorage.app/lessons/problem_0001/v2/show.mp3","retry":"https://storage.googleapis.com/deep-machine-learning-9d7d0.firebasestorage.app/lessons/problem_0001/v2/retry.mp3","ok":"https://storage.googleapis.com/deep-machine-learning-9d7d0.firebasestorage.app/lessons/problem_0001/v2/ok.mp3"},"mux":{"policy":"public","playback_id":"qSZEzip4t01cMeRS8r7GUQGstBCDiyODxZvcDa1B01IIo","asset_id":"4CNbjhjbZDibEwF02LLdALn802ZVgkUEiLeK01JLxmfi4g"}},"dislikes":"0","category":"Linear Algebra","starter_code":"def matrix_dot_vector(a: list[list[int|float]], b: list[int|float]) -> list[int|float]:\n\t# Return a list where each element is the dot product of a row of 'a' with 'b'.\n\t# If the number of columns in 'a' does not match the length of 'b', return -1.\n\tpass","title":"Matrix-Vector Dot Product","createdAt":"July 22, 2026 at 9:04:06 AM UTUTC-4","pytorch_test_cases":[{"test":"import torch\nres = matrix_dot_vector(\n    torch.tensor([[1,2,3],[2,4,5],[6,8,9]], dtype=torch.float),\n    torch.tensor([1,2,3], dtype=torch.float)\n)\nprint(res.numpy().tolist())","expected_output":"[14.0, 25.0, 49.0]"},{"test":"import torch\nres = matrix_dot_vector(\n    torch.tensor([[1,2,3],[2,4,5]], dtype=torch.float),\n    torch.tensor([1,2], dtype=torch.float)\n)\nprint(res.item())","expected_output":"-1"}]}