-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-majority-test.cjs
More file actions
63 lines (59 loc) · 2.12 KB
/
run-majority-test.cjs
File metadata and controls
63 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { spawn } = require('child_process');
const fs = require('fs');
const questions = [
'What is the capital of Australia?',
'What is the square root of 169?',
'In which year did World War II end in Europe?',
`Debug and fix this JavaScript code. It should print 55 (sum from 0 to 10), but prints 10:
\`\`\`javascript
let sum = 0;
for (let i = 0; i <= 10; i++) {
sum = i;
}
console.log(sum);
\`\`\``,
`Debug and fix this Python code. It should reverse 'hello' to 'olleh', but returns ['o', 'l', 'l', 'e', 'h']:
\`\`\`python
def reverse_string(s):
lst = list(s)
lst.reverse()
return lst
\`\`\``,
`Fix this JavaScript fizzbuzz code so that multiples of 15 print 'FizzBuzz' on one line:
\`\`\`javascript
for (let i = 1; i <= 20; i++) {
if (i % 3 === 0) {
console.log('Fizz');
}
if (i % 5 === 0) {
console.log('Buzz');
}
}
\`\`\``,
'A SaaS startup has 3 months runway left, current MRR $10k growing 10%/mo, churn 15%/mo. Top 3 actions? Pros/cons.',
'Formula for customer lifetime value (LTV) in subscription SaaS? Example.',
'Under EU GDPR, can a company scrape and use public LinkedIn profiles for AI training without consent?',
'Is it legal to use MIT licensed open source code in a proprietary commercial product without sharing source?'
];
async function runQuestion(q) {
return new Promise((resolve) => {
const child = spawn('node', ['majority-vote.cjs', q], {stdio: 'pipe'});
let out = '';
child.stdout.on('data', d => out += d);
child.stderr.on('data', d => out += `STDERR: ${d}`);
child.on('close', code => resolve(out));
child.on('error', e => resolve(`Error: ${e.message}`));
});
}
async function main() {
let md = '# Majority Vote Results\\n\\n';
for (let [index, q] of questions.entries()) {
md += `## Q${index+1}\\n**Question:** ${q.replace(/\\*\\*/g, '**')}\\n\\n`;
console.log(`Running Q${index+1}...`);
const result = await runQuestion(q);
md += `**Result:**\\n\\\`\`\`\\n${result.replace(/\\n/g, '\\n')}\\n\\\`\`\`\\n\\n`;
}
fs.writeFileSync('majority-results.md', md);
console.log('Results saved to majority-results.md');
}
main().catch(console.error);