UNPKG

local-leetcode-trainer

Version:

A complete local LeetCode practice environment with multi-language support - use your IDE, collaborate with AI, submit with confidence

158 lines (131 loc) โ€ข 4.95 kB
#!/usr/bin/env node const AITeachingEngine = require('./dynamic/ai-teaching-engine'); const path = require('path'); /** * Demo script to showcase the AI Teaching System */ async function demoAITeaching() { console.log('๐Ÿค– AI Teaching System Demo\n'); console.log('=' .repeat(50)); const engine = new AITeachingEngine(); // Demo 1: Two Sum (Easy) console.log('\n๐Ÿ“š Demo 1: Two Sum (Easy Problem)'); console.log('-'.repeat(40)); const twoSumPath = path.join(__dirname, 'dynamic', 'problems', 'easy', 'two-sum'); const script1 = engine.loadScript(twoSumPath); if (script1) { console.log('โœ… Teaching script loaded successfully!'); console.log('\n๐ŸŽฏ Introduction:'); console.log(engine.getIntroduction()); console.log('\n๐Ÿ’ญ Pre-coding guidance:'); console.log(engine.getPrePrompt()); // Simulate code analysis const bruteForceCode = ` function twoSum(nums, target) { for (let i = 0; i < nums.length; i++) { for (let j = i + 1; j < nums.length; j++) { if (nums[i] + nums[j] === target) { return [i, j]; } } } }`; console.log('\n๐Ÿ” Analyzing brute force approach...'); const hint1 = engine.getHint(bruteForceCode); if (hint1) { console.log('๐Ÿ’ก AI Hint:'); console.log(hint1); } // Simulate execution feedback console.log('\n๐Ÿงช Simulating test execution...'); const feedback = engine.processExecution(bruteForceCode, 'Test passed', '', true); if (feedback) { console.log('๐Ÿค– AI Feedback:'); console.log(feedback); } const successMsg = engine.getSuccessMessage(); if (successMsg) { console.log('\n๐ŸŽ‰ Success Message:'); console.log(successMsg); } } else { console.log('โŒ No teaching script found'); } // Demo 2: Longest Palindromic Substring (Medium) console.log('\n\n๐Ÿ“š Demo 2: Longest Palindromic Substring (Medium Problem)'); console.log('-'.repeat(55)); engine.reset(); // Reset for new problem const palindromePath = path.join(__dirname, 'dynamic', 'problems', 'medium', 'longest-palindromic-substring'); const script2 = engine.loadScript(palindromePath); if (script2) { console.log('โœ… Teaching script loaded successfully!'); console.log('\n๐ŸŽฏ Introduction:'); console.log(engine.getIntroduction()); // Simulate different code patterns const inefficientCode = ` function longestPalindrome(s) { for (let i = 0; i < s.length; i++) { for (let j = i; j < s.length; j++) { let substring = s.substring(i, j + 1); // check if palindrome... } } }`; console.log('\n๐Ÿ” Analyzing inefficient approach...'); const hint2 = engine.getHint(inefficientCode); if (hint2) { console.log('๐Ÿ’ก AI Hint:'); console.log(hint2); } // Simulate error handling console.log('\n๐Ÿ› Simulating boundary error...'); const errorFeedback = engine.processExecution(inefficientCode, '', 'TypeError: Cannot read property', false); if (errorFeedback) { console.log('๐Ÿค– AI Error Help:'); console.log(errorFeedback); } } else { console.log('โŒ No teaching script found'); } // Demo 3: Merge k Sorted Lists (Hard) console.log('\n\n๐Ÿ“š Demo 3: Merge k Sorted Lists (Hard Problem)'); console.log('-'.repeat(45)); engine.reset(); // Reset for new problem const mergePath = path.join(__dirname, 'dynamic', 'problems', 'hard', 'merge-k-sorted-lists'); const script3 = engine.loadScript(mergePath); if (script3) { console.log('โœ… Teaching script loaded successfully!'); console.log('\n๐ŸŽฏ Introduction:'); console.log(engine.getIntroduction()); console.log('\n๐Ÿ’ญ Strategic guidance:'); console.log(engine.getPrePrompt()); // Simulate struggling with the problem const strugglingCode = ` function mergeKLists(lists) { while (lists.length > 1) { // trying to merge but getting confused... } }`; // Simulate multiple attempts engine.processExecution(strugglingCode, '', '', false); engine.processExecution(strugglingCode, '', '', false); engine.processExecution(strugglingCode, '', '', false); console.log('\n๐Ÿค” After multiple failed attempts...'); const helpFeedback = engine.processExecution(strugglingCode, '', '', false); if (helpFeedback) { console.log('๐Ÿค– AI Encouragement:'); console.log(helpFeedback); } } else { console.log('โŒ No teaching script found'); } console.log('\n\n๐ŸŽ‰ Demo Complete!'); console.log('=' .repeat(50)); console.log('๐Ÿš€ Try it yourself with: lct ai-challenge two-sum'); console.log('๐Ÿ†˜ Get help anytime with: lct ai-help'); } // Run demo if called directly if (require.main === module) { demoAITeaching().catch(console.error); } module.exports = demoAITeaching;