diff --git a/results.json b/results.json index 6a84764..23183cb 100644 --- a/results.json +++ b/results.json @@ -42,5 +42,16 @@ "7_scheduler": 12.446870330999955, "8_json_validator": 2.8953664760000537, "9_stream_visualizer": 5.022439357000054 + }, + "moonshotai/kimi-k2-thinking": { + "1_dijkstra": 34.72660079400001, + "2_convex_hull": 42.421906253, + "3_lis": 52.291474074000014, + "4_determinant": 37.432558806, + "5_markdown_parser": 35.437114885999996, + "6_csv_processor": 91.85763109999999, + "7_scheduler": 184.65146969499997, + "8_json_validator": 81.96185510699998, + "9_stream_visualizer": 31.27018206100003 } } \ No newline at end of file diff --git a/tests/1_dijkstra/outputs/moonshotai_kimi-k2-thinking.js b/tests/1_dijkstra/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..5746577 --- /dev/null +++ b/tests/1_dijkstra/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,35 @@ +async function findShortestPath(graph, start, end) { + let PriorityQueue; + try { + const mod = await import('https://esm.sh/js-priority-queue@1.0.0'); + PriorityQueue = mod.default || mod; + } catch { + throw new Error('Failed to load priority queue library'); + } + + if (!(start in graph) || !(end in graph)) return Infinity; + if (start === end) return 0; + + const dist = { [start]: 0 }; + const pq = new PriorityQueue({ + comparator: (a, b) => a[1] - b[1], + initialValues: [[start, 0]] + }); + + while (pq.length) { + const [node, d] = pq.dequeue(); + if (node === end) return d; + if (d > (dist[node] ?? Infinity)) continue; + + for (const [neighbor, weight] of Object.entries(graph[node])) { + const newDist = d + weight; + if (newDist < (dist[neighbor] ?? Infinity)) { + dist[neighbor] = newDist; + pq.queue([neighbor, newDist]); + } + } + } + + return Infinity; +} +export default findShortestPath; \ No newline at end of file diff --git a/tests/2_convex_hull/outputs/moonshotai_kimi-k2-thinking.js b/tests/2_convex_hull/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..ef9c731 --- /dev/null +++ b/tests/2_convex_hull/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,24 @@ +async function findConvexHull(points) { + const { default: _ } = await import('https://cdn.jsdelivr.net/npm/lodash@4/esm/lodash.js'); + + if (!points || points.length < 3) return [...(points || [])]; + + const pts = _.sortBy(_.uniqWith(points, (a, b) => a.x === b.x && a.y === b.y), ['x', 'y']); + + const cross = (o, a, b) => (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); + + const build = arr => { + const h = []; + for (const p of arr) { + while (h.length >= 2 && cross(h[h.length - 2], h[h.length - 1], p) <= 0) h.pop(); + h.push(p); + } + return h; + }; + + const lower = build(pts); + const upper = build([...pts].reverse()); + + return [...lower.slice(0, -1), ...upper.slice(0, -1)]; +} +export default findConvexHull; \ No newline at end of file diff --git a/tests/3_lis/outputs/moonshotai_kimi-k2-thinking.js b/tests/3_lis/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..aaa7cca --- /dev/null +++ b/tests/3_lis/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,7 @@ +async function findLISLength(nums){ + const{bisectLeft}=await import('https://cdn.skypack.dev/d3-array'); + const tails=[]; + for(const n of nums)tails[bisectLeft(tails,n)]=n; + return tails.length; +} +export default findLISLength; \ No newline at end of file diff --git a/tests/4_determinant/outputs/moonshotai_kimi-k2-thinking.js b/tests/4_determinant/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..72358f4 --- /dev/null +++ b/tests/4_determinant/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,8 @@ +let math; +async function calculateDeterminant(m) { + const n = m?.length; + if (!n || m.some(r => !Array.isArray(r) || r.length !== n)) throw new Error('Invalid matrix'); + math ||= await import('https://cdn.jsdelivr.net/npm/mathjs@11.11.0/+esm'); + return math.det(m); +} +export default calculateDeterminant; \ No newline at end of file diff --git a/tests/5_markdown_parser/outputs/moonshotai_kimi-k2-thinking.js b/tests/5_markdown_parser/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..25d0bfd --- /dev/null +++ b/tests/5_markdown_parser/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,9 @@ +const parseMarkdown = async m => { + try { + const {marked} = await import('https://esm.sh/marked'); + return marked.parse(m); + } catch (e) { + return `
${e.message}
`; + } +}; +export default parseMarkdown; \ No newline at end of file diff --git a/tests/6_csv_processor/outputs/moonshotai_kimi-k2-thinking.js b/tests/6_csv_processor/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..0d546af --- /dev/null +++ b/tests/6_csv_processor/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,19 @@ +async function processCSV(csv, cfg) { + const [{ default: Papa }, { default: _ }] = await Promise.all([ + import('https://cdn.jsdelivr.net/npm/papaparse@5.4.1/+esm'), + import('https://cdn.jsdelivr.net/npm/lodash@4.17.21/+esm') + ]); + + const filtered = Papa.parse(csv, { header: true, dynamicTyping: true }).data + .filter(r => r[cfg.filterColumn] == cfg.filterValue); + + return Object.entries(_.groupBy(filtered, cfg.groupBy)).map(([k, v]) => { + const sum = v.reduce((s, r) => s + (Number(r[cfg.aggregateColumn]) || 0), 0); + return { + [cfg.groupBy]: k, + result: cfg.operation === 'count' ? v.length : + cfg.operation === 'avg' ? sum / v.length : sum + }; + }); +} +export default processCSV; \ No newline at end of file diff --git a/tests/7_scheduler/outputs/moonshotai_kimi-k2-thinking.js b/tests/7_scheduler/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..faf0f7a --- /dev/null +++ b/tests/7_scheduler/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,37 @@ +export async function findAvailableSlots(a, b, { durationMinutes: d, searchRange: r, workHours: h }) { + const { parseISO, addMinutes, isWithinInterval, compareAsc, startOfDay, setHours, setMinutes } = await import('https://esm.sh/date-fns'); + + const toDate = (s) => parseISO(s); + const all = [...a, ...b].map(({ start: s, end: e }) => ({ s: toDate(s), e: toDate(e) })); + all.sort((a, b) => compareAsc(a.s, b.s)); + + const busy = []; + for (const i of all) { + if (!busy.length || compareAsc(i.s, busy.at(-1).e) > 0) busy.push({ s: i.s, e: i.e }); + else if (compareAsc(i.e, busy.at(-1).e) > 0) busy.at(-1).e = i.e; + } + + const range = { s: toDate(r.start), e: toDate(r.end) }; + const [[sh, sm], [eh, em]] = [h.start, h.end].map(t => t.split(':').map(Number)); + + const slots = []; + let cur = range.s; + + while (compareAsc(cur, range.e) < 0) { + const end = addMinutes(cur, d); + if (compareAsc(end, range.e) > 0) break; + + const day = startOfDay(cur); + const work = { s: setHours(setMinutes(day, sm), sh), e: setHours(setMinutes(day, em), eh) }; + + const inWork = isWithinInterval(cur, work) && isWithinInterval(end, work); + const isFree = !busy.some(b => compareAsc(cur, b.e) < 0 && compareAsc(end, b.s) > 0); + + if (inWork && isFree) slots.push({ start: cur.toISOString(), end: end.toISOString() }); + + cur = end; + } + + return slots; +} +export default findAvailableSlots; \ No newline at end of file diff --git a/tests/8_json_validator/outputs/moonshotai_kimi-k2-thinking.js b/tests/8_json_validator/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..64b8c47 --- /dev/null +++ b/tests/8_json_validator/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,17 @@ +const cache = new WeakMap(); +let ajv; + +async function validateJSON(json, schema) { + try { + if (!ajv) { + const { default: Ajv } = await import('https://cdn.jsdelivr.net/npm/ajv@8/dist/ajv.mjs'); + ajv = new Ajv({ allErrors: true, strict: false }); + } + const validator = cache.get(schema) || (cache.set(schema, ajv.compile(schema)), cache.get(schema)); + const valid = validator(json); + return { valid, errors: valid ? [] : validator.errors.map(e => `${e.instancePath} ${e.message}`.trim()) }; + } catch (error) { + return { valid: false, errors: [error.message] }; + } +} +export default validateJSON; \ No newline at end of file diff --git a/tests/9_stream_visualizer/outputs/moonshotai_kimi-k2-thinking.js b/tests/9_stream_visualizer/outputs/moonshotai_kimi-k2-thinking.js new file mode 100644 index 0000000..df51844 --- /dev/null +++ b/tests/9_stream_visualizer/outputs/moonshotai_kimi-k2-thinking.js @@ -0,0 +1,9 @@ +export async function createStreamVisualizer(i,o){ + const d=await import('d3'),{maxPoints:m,alpha:a,width:w,height:h,yDomain:y}=o,p=[],c=d.scaleLinear,f=d.line; + let e; + for await(const{timestamp:t,value:v}of i){e=e===undefined?v:a*v+(1-a)*e;p.push({timestamp:t,value:v,ema:e});p.length>m&&p.shift()} + if(!p.length)return{data:[],path:''}; + const x=c().domain([p[0].timestamp,p.at(-1).timestamp]).range([0,w]),z=c().domain(y).range([h,0]),g=f().x(d=>x(d.timestamp)).y(d=>z(d.ema)).curve(d.curveLinear); + return{data:p,path:g(p)} +} +export default createStreamVisualizer; \ No newline at end of file