Spaces:
Running
Running
File size: 31,485 Bytes
c987dd2 | 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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Extract Rust Starter Code from Local Files\n",
"\n",
"This notebook reads Rust `.rs` files from the local `rust_solutions/` directory,\n",
"extracts starter code stubs (comments + `impl Solution` with function bodies replaced by placeholder), and saves to `starter_codes.jsonl`.\n",
"\n",
"Expected file format: `0001.Two Sum.rs` where the leading digits are the problem_id.\n",
"\n",
"Output format:\n",
"```rust\n",
"// Definition for singly-linked list.\n",
"// #[derive(PartialEq, Eq, Clone, Debug)]\n",
"// pub struct ListNode { ... }\n",
"\n",
"impl Solution {\n",
" pub fn add_two_numbers(\n",
" mut l1: Option<Box<ListNode>>,\n",
" mut l2: Option<Box<ListNode>>,\n",
" ) -> Option<Box<ListNode>> {\n",
" // OUR CODE GOES HERE\n",
" }\n",
"}\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import re\n",
"from pathlib import Path\n",
"\n",
"RUST_SOLUTIONS_DIR = Path(\"/media/tm23/NewVolume/rust_dataset/complexity_reasoning_data/rust_solutions/\")\n",
"OUTPUT_FILE = Path(\"/media/tm23/NewVolume/rust_dataset/complexity_reasoning_data/starter_codes.jsonl\")\n",
"\n",
"print(f\"Reading from: {RUST_SOLUTIONS_DIR}\")\n",
"print(f\"Output to: {OUTPUT_FILE}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def find_matching_brace(text: str, open_pos: int) -> int:\n",
" \"\"\"Find the position of the closing brace matching the opening brace at open_pos.\"\"\"\n",
" depth = 0\n",
" i = open_pos\n",
" while i < len(text):\n",
" if text[i] == '{':\n",
" depth += 1\n",
" elif text[i] == '}':\n",
" depth -= 1\n",
" if depth == 0:\n",
" return i\n",
" i += 1\n",
" return -1\n",
"\n",
"\n",
"def extract_problem_id(filename: str) -> int | None:\n",
" \"\"\"Extract problem_id from filename like '0001.Two Sum.rs' -> 1\"\"\"\n",
" match = re.match(r\"^(\\d+)\", filename)\n",
" return int(match.group(1)) if match else None\n",
"\n",
"\n",
"def extract_starter_code(content: str) -> tuple[str, str] | None:\n",
" \"\"\"\n",
" Extract Rust starter code stub from solution.\n",
" Preserves initial comments/struct definitions and impl Solution block\n",
" with function bodies replaced by placeholder comment.\n",
" \n",
" Returns:\n",
" tuple of (function_name, starter_code) or None if no impl Solution found\n",
" \"\"\"\n",
" if \"impl Solution\" not in content:\n",
" return None\n",
"\n",
" impl_match = re.search(r\"impl\\s+Solution\\s*\\{\", content)\n",
" if not impl_match:\n",
" return None\n",
"\n",
" impl_start = impl_match.start()\n",
" brace_pos = impl_match.end() - 1\n",
"\n",
" impl_end = find_matching_brace(content, brace_pos)\n",
" if impl_end == -1:\n",
" return None\n",
"\n",
" impl_block_content = content[brace_pos + 1:impl_end]\n",
"\n",
" fn_pattern = re.compile(r\"(?:pub\\s+)?fn\\s+(\\w+)\\s*\\([^)]*\\)(?:\\s*->\\s*[^{]+)?\\s*\\{\")\n",
" fn_matches = list(fn_pattern.finditer(impl_block_content))\n",
"\n",
" if not fn_matches:\n",
" return None\n",
"\n",
" pub_fn_match = re.search(r\"pub\\s+fn\\s+(\\w+)\", impl_block_content)\n",
" first_fn_name = pub_fn_match.group(1) if pub_fn_match else fn_matches[0].group(1)\n",
"\n",
" starter_impl_content = impl_block_content\n",
" for fn_match in reversed(fn_matches):\n",
" fn_body_start = fn_match.end()\n",
" fn_body_end = find_matching_brace(starter_impl_content, fn_body_start - 1)\n",
" if fn_body_end == -1:\n",
" continue\n",
" replacement = \"\\n // OUR CODE GOES HERE\\n }\"\n",
" starter_impl_content = starter_impl_content[:fn_body_start] + replacement + starter_impl_content[fn_body_end + 1:]\n",
"\n",
" pre_impl = content[:impl_start].strip()\n",
"\n",
" if pre_impl:\n",
" starter_code = pre_impl + \"\\n\\nimpl Solution {\" + starter_impl_content + \"\\n}\"\n",
" else:\n",
" starter_code = \"impl Solution {\" + starter_impl_content + \"\\n}\"\n",
"\n",
" return first_fn_name, starter_code\n",
"\n",
"\n",
"def extract_all_starter_codes():\n",
" \"\"\"Extract starter codes from all .rs files in the directory.\"\"\"\n",
" results = []\n",
" \n",
" if not RUST_SOLUTIONS_DIR.exists():\n",
" print(f\"\\u274c Directory does not exist: {RUST_SOLUTIONS_DIR}\")\n",
" print(\"Please place .rs files in this directory with format: 0001.Two Sum.rs\")\n",
" return results\n",
" \n",
" rs_files = list(RUST_SOLUTIONS_DIR.glob(\"*.rs\"))\n",
" print(f\"Found {len(rs_files)} .rs files\")\n",
" \n",
" for rs_file in sorted(rs_files):\n",
" problem_id = extract_problem_id(rs_file.name)\n",
" if problem_id is None:\n",
" print(f\" Skipping (no problem_id): {rs_file.name}\")\n",
" continue\n",
" \n",
" content = rs_file.read_text()\n",
" result = extract_starter_code(content)\n",
" \n",
" if result is None:\n",
" print(f\" Skipping (no impl Solution): {rs_file.name}\")\n",
" continue\n",
" \n",
" fn_name, starter_code = result\n",
" results.append({\n",
" \"problem_id\": problem_id,\n",
" \"function_name\": fn_name,\n",
" \"starter_code\": starter_code\n",
" })\n",
" print(f\" Extracted: {problem_id} -> {fn_name}()\")\n",
" \n",
" return results\n",
"\n",
"\n",
"results = extract_all_starter_codes()\n",
"print(f\"\\n\\u2705 Extracted {len(results)} starter codes\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(OUTPUT_FILE, \"w\") as f:\n",
" for item in results:\n",
" f.write(json.dumps(item) + \"\\n\")\n",
"\n",
"print(f\"\\u2705 Saved to {OUTPUT_FILE}\")\n",
"\n",
"print(\"\\n\" + \"=\"*50)\n",
"print(\"First 3 entries:\")\n",
"for item in results[:3]:\n",
" print(f\"\\n--- Problem {item['problem_id']}: {item['function_name']} ---\")\n",
" print(item['starter_code'][:600])\n",
" print(\"...\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Dataset IDs: 2044\n",
"Starter code IDs: 1104\n",
"Python test IDs: 2641\n",
"\n",
"Missing starter code (1166): [4, 8, 16, 18, 29, 30, 31, 37, 44, 51, 52, 68, 72, 87, 89, 91, 93, 99, 127, 131, 132, 141, 160, 161, 162, 163, 164, 171, 172, 174, 186, 188, 219, 220, 221, 223, 224, 227, 233, 234, 239, 245, 246, 247, 248, 249, 259, 261, 266, 270, 276, 293, 299, 305, 309, 310, 311, 313, 314, 316, 318, 319, 320, 323, 328, 329, 330, 331, 332, 340, 349, 357, 358, 360, 363, 365, 369, 370, 375, 376, 377, 383, 387, 393, 400, 407, 408, 410, 412, 413, 414, 419, 422, 424, 434, 435, 436, 444, 447, 453, 455, 464, 466, 476, 480, 482, 487, 503, 506, 507, 514, 516, 517, 518, 520, 522, 523, 525, 527, 531, 533, 537, 541, 544, 545, 554, 555, 562, 563, 575, 576, 600, 609, 628, 629, 630, 634, 636, 638, 640, 644, 647, 657, 664, 678, 680, 683, 684, 685, 689, 692, 698, 699, 700, 701, 714, 721, 723, 727, 741, 742, 743, 747, 750, 753, 754, 755, 757, 760, 761, 765, 779, 781, 782, 788, 801, 805, 807, 809, 810, 813, 815, 825, 826, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 846, 848, 849, 856, 864, 867, 879, 880, 881, 888, 889, 897, 898, 899, 902, 903, 906, 910, 913, 914, 915, 916, 918, 921, 923, 924, 926, 927, 928, 935, 938, 941, 945, 947, 948, 961, 962, 963, 964, 967, 968, 970, 971, 974, 979, 980, 982, 983, 987, 991, 1001, 1002, 1003, 1004, 1005, 1006, 1012, 1018, 1023, 1024, 1025, 1026, 1027, 1035, 1039, 1041, 1043, 1051, 1053, 1054, 1055, 1059, 1099, 1100, 1103, 1104, 1105, 1108, 1111, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1129, 1130, 1131, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1144, 1145, 1147, 1150, 1151, 1152, 1153, 1154, 1156, 1160, 1162, 1163, 1165, 1167, 1169, 1170, 1175, 1176, 1177, 1178, 1180, 1181, 1182, 1183, 1185, 1187, 1190, 1191, 1192, 1196, 1198, 1201, 1203, 1207, 1208, 1209, 1210, 1213, 1214, 1215, 1217, 1219, 1220, 1221, 1222, 1223, 1224, 1228, 1230, 1231, 1232, 1233, 1234, 1235, 1238, 1239, 1240, 1243, 1245, 1246, 1247, 1248, 1250, 1252, 1253, 1254, 1255, 1256, 1258, 1259, 1260, 1262, 1263, 1268, 1269, 1271, 1272, 1273, 1275, 1287, 1288, 1296, 1299, 1300, 1301, 1306, 1310, 1311, 1314, 1315, 1318, 1319, 1320, 1330, 1331, 1335, 1338, 1343, 1346, 1347, 1349, 1358, 1360, 1361, 1362, 1363, 1365, 1368, 1370, 1371, 1373, 1374, 1375, 1376, 1377, 1379, 1382, 1386, 1388, 1389, 1395, 1400, 1401, 1402, 1405, 1406, 1409, 1410, 1418, 1419, 1424, 1425, 1427, 1434, 1438, 1444, 1446, 1452, 1456, 1461, 1462, 1463, 1469, 1471, 1473, 1474, 1477, 1478, 1480, 1481, 1482, 1486, 1487, 1492, 1503, 1508, 1514, 1521, 1530, 1535, 1536, 1542, 1546, 1547, 1548, 1550, 1551, 1552, 1553, 1560, 1563, 1566, 1567, 1569, 1573, 1574, 1575, 1577, 1580, 1585, 1589, 1593, 1601, 1602, 1604, 1605, 1609, 1614, 1615, 1625, 1627, 1631, 1639, 1652, 1653, 1654, 1655, 1659, 1663, 1664, 1665, 1669, 1673, 1674, 1675, 1681, 1682, 1685, 1686, 1687, 1688, 1690, 1691, 1692, 1696, 1698, 1703, 1705, 1707, 1711, 1712, 1713, 1714, 1716, 1720, 1721, 1722, 1725, 1730, 1734, 1736, 1737, 1738, 1739, 1745, 1761, 1762, 1766, 1772, 1782, 1787, 1793, 1794, 1798, 1801, 1802, 1803, 1806, 1808, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1824, 1826, 1829, 1833, 1834, 1835, 1836, 1838, 1839, 1840, 1842, 1846, 1847, 1849, 1850, 1851, 1852, 1854, 1856, 1857, 1859, 1860, 1861, 1864, 1866, 1869, 1871, 1872, 1874, 1876, 1882, 1883, 1884, 1887, 1893, 1895, 1900, 1903, 1904, 1905, 1921, 1922, 1925, 1926, 1927, 1928, 1931, 1933, 1940, 1941, 1942, 1948, 1953, 1955, 1957, 1958, 1961, 1962, 1963, 1964, 1968, 1974, 1976, 1977, 1980, 1981, 1983, 1985, 1986, 1987, 1989, 1996, 1997, 2001, 2002, 2007, 2008, 2014, 2015, 2017, 2018, 2019, 2021, 2022, 2023, 2025, 2029, 2031, 2033, 2036, 2038, 2039, 2046, 2047, 2049, 2050, 2052, 2056, 2058, 2062, 2065, 2067, 2068, 2070, 2071, 2073, 2075, 2076, 2081, 2085, 2090, 2092, 2094, 2095, 2096, 2098, 2101, 2109, 2113, 2116, 2123, 2127, 2129, 2131, 2133, 2135, 2137, 2138, 2139, 2144, 2145, 2146, 2148, 2149, 2150, 2156, 2161, 2164, 2170, 2171, 2179, 2182, 2187, 2189, 2190, 2192, 2194, 2195, 2198, 2204, 2207, 2213, 2214, 2218, 2222, 2225, 2226, 2229, 2231, 2233, 2234, 2237, 2239, 2245, 2246, 2247, 2248, 2256, 2258, 2259, 2260, 2261, 2262, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2272, 2274, 2275, 2282, 2284, 2285, 2288, 2290, 2291, 2295, 2297, 2301, 2305, 2306, 2307, 2310, 2312, 2317, 2320, 2326, 2328, 2330, 2332, 2338, 2340, 2343, 2345, 2352, 2355, 2361, 2365, 2367, 2368, 2369, 2376, 2378, 2385, 2386, 2387, 2393, 2397, 2398, 2400, 2402, 2403, 2406, 2407, 2409, 2416, 2417, 2420, 2421, 2422, 2423, 2425, 2426, 2427, 2428, 2430, 2431, 2439, 2440, 2445, 2447, 2449, 2450, 2453, 2454, 2456, 2457, 2458, 2459, 2461, 2462, 2463, 2464, 2466, 2467, 2468, 2470, 2472, 2473, 2476, 2478, 2484, 2486, 2487, 2488, 2489, 2493, 2495, 2501, 2503, 2505, 2507, 2508, 2509, 2510, 2519, 2521, 2522, 2523, 2527, 2531, 2532, 2533, 2542, 2543, 2547, 2548, 2551, 2552, 2555, 2556, 2557, 2559, 2560, 2563, 2564, 2565, 2568, 2569, 2571, 2572, 2577, 2581, 2583, 2585, 2592, 2593, 2594, 2596, 2597, 2599, 2601, 2602, 2603, 2604, 2606, 2608, 2611, 2613, 2617, 2638, 2640, 2641, 2645, 2646, 2647, 2653, 2657, 2658, 2659, 2662, 2663, 2673, 2681, 2684, 2685, 2698, 2699, 2702, 2708, 2711, 2713, 2714, 2718, 2719, 2730, 2731, 2736, 2737, 2743, 2744, 2745, 2746, 2747, 2748, 2750, 2760, 2761, 2762, 2763, 2765, 2766, 2767, 2768, 2769, 2770, 2771, 2772, 2773, 2779, 2784, 2786, 2788, 2789, 2801, 2802, 2806, 2807, 2808, 2809, 2813, 2814, 2815, 2816, 2817, 2819, 2824, 2825, 2826, 2827, 2830, 2831, 2832, 2833, 2834, 2835, 2836, 2838, 2841, 2842, 2844, 2846, 2847, 2848, 2849, 2850, 2852, 2855, 2856, 2857, 2859, 2860, 2861, 2862, 2863, 2865, 2866, 2867, 2868, 2869, 2870, 2871, 2875, 2876, 2892, 2895, 2896, 2897, 2908, 2909, 2912, 2913, 2914, 2915, 2917, 2918, 2919, 2920, 2923, 2924, 2925, 2926, 2927, 2928, 2930, 2931, 2932, 2933, 2934, 2935, 2937, 2938, 2939, 2940, 2944, 2951, 2952, 2953, 2956, 2957, 2958, 2959, 2962, 2964, 2965, 2968, 2969, 2970, 2972, 2973, 2980, 2981, 2982, 2983, 2992, 2996, 2997, 3003, 3004, 3007, 3011, 3012, 3014, 3015, 3016, 3024, 3026, 3028, 3029, 3032, 3033, 3034, 3038, 3039, 3040, 3042, 3043, 3044, 3045, 3048, 3062, 3063, 3065, 3067, 3071, 3072, 3073, 3076, 3077, 3078, 3079, 3080, 3081, 3082, 3083, 3084, 3086, 3088, 3090, 3092, 3093, 3096, 3098, 3099, 3101, 3102, 3104, 3105, 3106, 3107, 3108, 3109, 3112, 3113, 3114, 3115, 3116, 3117, 3120, 3121, 3122, 3123, 3125, 3127, 3128, 3131, 3132, 3133, 3134, 3135, 3137, 3138, 3141, 3142, 3143, 3144, 3146, 3148, 3149, 3151, 3152, 3153, 3154, 3155, 3157, 3158, 3159, 3160, 3162, 3163, 3164, 3165, 3167, 3168, 3171, 3173, 3174, 3175, 3176, 3177, 3178, 3179, 3180, 3181, 3183, 3184, 3185, 3189, 3191, 3192, 3193, 3196, 3199, 3200, 3205, 3206, 3207, 3208, 3209, 3210, 3211, 3213, 3215, 3221, 3222, 3223, 3229, 3232, 3233, 3237, 3238, 3239, 3240]\n",
"\n",
"Missing python tests (0): []\n",
"\n",
"Will be converted (878): [1, 2, 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 90, 92, 94, 96, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 118, 119, 120, 121, 122, 123, 124, 125, 128, 129, 130, 135, 136, 137, 143, 144, 145, 148, 151, 165, 166, 167, 169, 187, 189, 190, 198, 199, 200, 205, 206, 207, 209, 213, 214, 215, 216, 217, 222, 226, 228, 231, 236, 238, 240, 242, 252, 253, 260, 268, 274, 275, 278, 283, 287, 289, 290, 292, 312, 322, 325, 326, 342, 343, 344, 345, 347, 350, 367, 386, 389, 392, 401, 403, 404, 409, 415, 416, 417, 433, 437, 440, 451, 454, 462, 467, 468, 474, 477, 481, 485, 486, 494, 496, 498, 508, 509, 515, 521, 524, 530, 532, 539, 540, 542, 543, 547, 557, 560, 561, 566, 567, 572, 573, 581, 582, 583, 594, 598, 599, 605, 611, 624, 632, 633, 637, 643, 645, 646, 648, 649, 661, 670, 673, 674, 679, 682, 687, 688, 691, 693, 696, 704, 712, 713, 717, 720, 722, 724, 728, 733, 734, 735, 739, 744, 746, 748, 756, 762, 763, 766, 768, 769, 771, 778, 783, 784, 785, 790, 799, 806, 808, 814, 822, 827, 828, 840, 841, 865, 868, 869, 871, 872, 873, 874, 875, 876, 877, 883, 884, 896, 904, 905, 907, 908, 909, 917, 920, 922, 925, 929, 936, 937, 942, 944, 946, 955, 960, 965, 966, 973, 975, 976, 977, 978, 985, 989, 994, 995, 997, 998, 999, 1007, 1008, 1009, 1010, 1013, 1014, 1015, 1016, 1019, 1022, 1036, 1037, 1038, 1042, 1052, 1061, 1062, 1094, 1101, 1102, 1106, 1109, 1128, 1143, 1155, 1161, 1168, 1171, 1184, 1186, 1189, 1197, 1199, 1200, 1202, 1216, 1218, 1227, 1229, 1249, 1257, 1266, 1267, 1276, 1277, 1278, 1281, 1282, 1283, 1289, 1290, 1292, 1295, 1297, 1298, 1302, 1304, 1305, 1309, 1313, 1317, 1326, 1328, 1329, 1339, 1351, 1353, 1354, 1356, 1359, 1366, 1367, 1380, 1385, 1387, 1390, 1392, 1394, 1399, 1403, 1404, 1408, 1411, 1414, 1415, 1417, 1422, 1423, 1426, 1432, 1436, 1437, 1441, 1442, 1450, 1455, 1458, 1460, 1465, 1466, 1470, 1475, 1488, 1491, 1493, 1497, 1498, 1502, 1504, 1512, 1513, 1523, 1524, 1526, 1528, 1529, 1534, 1545, 1559, 1561, 1572, 1578, 1582, 1583, 1588, 1590, 1592, 1594, 1595, 1599, 1608, 1611, 1616, 1647, 1657, 1658, 1662, 1671, 1672, 1678, 1679, 1680, 1684, 1689, 1694, 1695, 1697, 1700, 1701, 1702, 1704, 1706, 1708, 1710, 1717, 1726, 1727, 1728, 1732, 1733, 1742, 1749, 1750, 1751, 1758, 1760, 1768, 1771, 1780, 1781, 1784, 1785, 1788, 1790, 1791, 1792, 1796, 1800, 1805, 1807, 1812, 1822, 1827, 1828, 1832, 1837, 1844, 1848, 1855, 1858, 1862, 1863, 1870, 1877, 1878, 1880, 1881, 1885, 1886, 1888, 1891, 1894, 1897, 1898, 1899, 1901, 1909, 1918, 1920, 1929, 1930, 1935, 1936, 1944, 1945, 1946, 1947, 1959, 1967, 1970, 1971, 1975, 1979, 1984, 1991, 2000, 2003, 2006, 2009, 2011, 2012, 2016, 2024, 2027, 2028, 2032, 2037, 2040, 2042, 2044, 2048, 2053, 2054, 2057, 2063, 2079, 2083, 2099, 2103, 2105, 2106, 2107, 2108, 2110, 2114, 2119, 2124, 2125, 2126, 2128, 2130, 2132, 2134, 2136, 2140, 2141, 2147, 2154, 2155, 2163, 2165, 2169, 2176, 2177, 2178, 2181, 2191, 2196, 2197, 2200, 2201, 2206, 2208, 2209, 2210, 2211, 2212, 2215, 2216, 2219, 2220, 2221, 2240, 2243, 2244, 2251, 2255, 2257, 2273, 2278, 2279, 2283, 2287, 2293, 2294, 2299, 2300, 2302, 2303, 2304, 2309, 2311, 2315, 2316, 2319, 2322, 2323, 2327, 2331, 2341, 2342, 2347, 2348, 2351, 2357, 2358, 2359, 2360, 2363, 2364, 2366, 2374, 2379, 2383, 2389, 2390, 2391, 2395, 2396, 2399, 2401, 2404, 2405, 2410, 2411, 2412, 2413, 2414, 2415, 2418, 2419, 2429, 2432, 2433, 2434, 2435, 2436, 2437, 2438, 2441, 2442, 2443, 2444, 2446, 2448, 2451, 2452, 2455, 2460, 2465, 2469, 2471, 2475, 2477, 2481, 2482, 2483, 2485, 2490, 2491, 2492, 2500, 2506, 2511, 2512, 2516, 2520, 2525, 2528, 2529, 2530, 2534, 2535, 2536, 2537, 2540, 2541, 2544, 2545, 2546, 2549, 2553, 2554, 2558, 2561, 2562, 2566, 2567, 2570, 2573, 2574, 2575, 2576, 2578, 2579, 2582, 2586, 2587, 2588, 2589, 2591, 2595, 2598, 2600, 2605, 2609, 2610, 2614, 2616, 2639, 2643, 2644, 2652, 2654, 2655, 2656, 2660, 2661, 2664, 2670, 2678, 2680, 2682, 2683, 2696, 2697, 2706, 2707, 2710, 2712, 2716, 2717, 2732, 2733, 2734, 2735, 2739, 2740, 2741, 2742, 2749, 2785, 2787, 2798, 2799, 2800, 2810, 2811, 2812, 2828, 2829, 2839, 2840, 2843, 2845, 2864, 2872, 2873, 2874, 2894, 2898, 2899, 2900, 2901, 2903, 2904, 2906, 2907, 2921, 2929, 2942, 2943, 2946, 2947, 2948, 2950, 2955, 2960, 2966, 2967, 2974, 2975, 2976, 2977, 2979, 2999, 3000, 3001, 3005, 3010, 3013, 3018, 3019, 3020, 3021, 3025, 3027, 3046, 3047, 3066, 3068, 3069, 3070, 3074, 3075, 3085, 3091, 3095, 3097, 3100, 3110, 3111, 3119, 3129, 3130, 3136, 3147, 3169, 3170, 3186, 3187, 3190, 3194, 3195, 3197, 3201, 3202, 3203, 3212, 3216, 3217, 3218, 3219, 3224, 3226, 3227, 3228, 3231, 3234, 3235]\n"
]
}
],
"source": [
"import json\n",
"def load_ids(path, key=\"problem_id\"):\n",
" ids = set()\n",
" with open(path) as f:\n",
" for line in f:\n",
" data = json.loads(line)\n",
" ids.add(data[key])\n",
" return ids\n",
"dataset_ids = load_ids(\"/teamspace/studios/this_studio/dataset/complexity_reasoning_data/dataset.jsonl\")\n",
"starter_ids = load_ids(\"/teamspace/studios/this_studio/dataset/complexity_reasoning_data/starter_codes.jsonl\")\n",
"tests_ids = load_ids(\"/teamspace/studios/this_studio/dataset/complexity_reasoning_data/python_tests.jsonl\")\n",
"missing_starter = dataset_ids - starter_ids\n",
"missing_tests = dataset_ids - tests_ids\n",
"will_convert = dataset_ids & starter_ids & tests_ids\n",
"print(f\"Dataset IDs: {len(dataset_ids)}\")\n",
"print(f\"Starter code IDs: {len(starter_ids)}\")\n",
"print(f\"Python test IDs: {len(tests_ids)}\")\n",
"print(f\"\\nMissing starter code ({len(missing_starter)}): {sorted(missing_starter)}\")\n",
"print(f\"\\nMissing python tests ({len(missing_tests)}): {sorted(missing_tests)}\")\n",
"print(f\"\\nWill be converted ({len(will_convert)}): {sorted(will_convert)}\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Checking 1141 files in rust_solutions...\n",
"\n",
"⚠️ Skipped (no impl Solution): 0146.LRU Cache.rs — found: ['Node', 'LRUCache']\n",
"⚠️ Skipped (no impl Solution): 0155.Min Stack.rs — found: ['MinStack']\n",
"⚠️ Skipped (no impl Solution): 0173.Binary Search Tree Iterator.rs — found: ['TreeNode', 'BSTIterator']\n",
"⚠️ Skipped (no impl Solution): 0208.Implement Trie (Prefix Tree).rs — found: ['TrieNode', 'Trie']\n",
"⚠️ Skipped (no impl Solution): 0225.Implement Stack using Queues.rs — found: ['MyStack']\n",
"⚠️ Skipped (no impl Solution): 0232.Implement Queue using Stacks.rs — found: ['MyQueue']\n",
"⚠️ Skipped (no impl Solution): 0281.Zigzag Iterator.rs — found: ['ZigzagIterator']\n",
"⚠️ Skipped (no impl Solution): 0295.Find Median from Data Stream.rs — found: ['MedianFinder']\n",
"⚠️ Skipped (no impl Solution): 0303.Range Sum Query - Immutable.rs — found: ['NumArray']\n",
"⚠️ Skipped (no impl Solution): 0304.Range Sum Query 2D - Immutable.rs — found: ['NumMatrix']\n",
"⚠️ Skipped (no impl Solution): 0341.Flatten Nested List Iterator.rs — found: ['NestedIterator']\n",
"⚠️ Skipped (no impl Solution): 0362.Design Hit Counter.rs — found: ['HitCounter']\n",
"⚠️ Skipped (no impl Solution): 0380.Insert Delete GetRandom O(1).rs — found: ['RandomizedSet']\n",
"⚠️ Skipped (no impl Solution): 0460.LFU Cache.rs — found: ['Node', 'LinkedList', 'LFUCache']\n",
"⚠️ Skipped (no impl Solution): 0622.Design Circular Queue.rs — found: ['MyCircularQueue']\n",
"⚠️ Skipped (no impl Solution): 0676.Implement Magic Dictionary.rs — found: ['Trie', 'MagicDictionary']\n",
"⚠️ Skipped (no impl Solution): 0677.Map Sum Pairs.rs — found: ['Trie', 'MapSum']\n",
"⚠️ Skipped (no impl Solution): 0707.Design Linked List.rs — found: ['MyLinkedList']\n",
"⚠️ Skipped (no impl Solution): 0729.My Calendar I.rs — found: ['MyCalendar']\n",
"⚠️ Skipped (no impl Solution): 0901.Online Stock Span.rs — found: ['StockSpanner']\n",
"⚠️ Skipped (no impl Solution): 0933.Number of Recent Calls.rs — found: ['RecentCounter']\n",
"⚠️ Skipped (no impl Solution): 1244.Design A Leaderboard.rs — found: ['Leaderboard']\n",
"⚠️ Skipped (no impl Solution): 1570.Dot Product of Two Sparse Vectors.rs — found: ['SparseVector']\n",
"⚠️ Skipped (no impl Solution): 1603.Design Parking System.rs — found: ['ParkingSystem']\n",
"⚠️ Skipped (no impl Solution): 1656.Design an Ordered Stream.rs — found: ['OrderedStream']\n",
"⚠️ Skipped (no impl Solution): 1797.Design Authentication Manager.rs — found: ['AuthenticationManager']\n",
"⚠️ Skipped (no impl Solution): 1865.Finding Pairs With a Certain Sum.rs — found: ['FindSumPairs']\n",
"⚠️ Skipped (no impl Solution): 2043.Simple Bank System.rs — found: ['Bank']\n",
"⚠️ Skipped (no impl Solution): 2080.Range Frequency Queries.rs — found: ['RangeFreqQuery']\n",
"⚠️ Skipped (no impl Solution): 2296.Design a Text Editor.rs — found: ['TextEditor']\n",
"⚠️ Skipped (no impl Solution): 2336.Smallest Number in Infinite Set.rs — found: ['SmallestInfiniteSet']\n",
"⚠️ Skipped (no impl Solution): 2349.Design a Number Container System.rs — found: ['NumberContainers']\n",
"⚠️ Skipped (no impl Solution): 2590.Design a Todo List.rs — found: ['TodoList']\n",
"⚠️ Skipped (no impl Solution): 2671.Frequency Tracker.rs — found: ['FrequencyTracker']\n",
"⚠️ Skipped (no impl Solution): 3484.Design Spreadsheet.rs — found: ['Spreadsheet']\n",
"⚠️ Skipped (no impl Solution): 3508.Implement Router.rs — found: ['Router']\n",
"⚠️ Skipped (no impl Solution): 3822.Design Order Management System.rs — found: ['OrderManagementSystem']\n",
"\n",
"==============================\n",
" FINAL SUMMARY\n",
"==============================\n",
"Total Files Scanned: 1141\n",
"✅ Valid Solutions: 1104\n",
"❌ No 'impl Solution': 37\n",
"⚠️ Pattern Mismatch: 0\n",
"Total Skipped: 37\n",
"==============================\n"
]
}
],
"source": [
"import re\n",
"from pathlib import Path\n",
"\n",
"# Define the path to your folder\n",
"solutions_dir = Path(\"/teamspace/studios/this_studio/dataset/complexity_reasoning_data/rust_solutions\")\n",
"\n",
"# Get all .rs files and sort them\n",
"rs_files = sorted(solutions_dir.glob(\"*.rs\"))\n",
"\n",
"# --- Initialize Counters ---\n",
"total_files = len(rs_files)\n",
"skipped_no_impl = 0\n",
"skipped_pattern_mismatch = 0\n",
"valid_count = 0\n",
"\n",
"print(f\"Checking {total_files} files in {solutions_dir.name}...\\n\")\n",
"\n",
"for rs_file in rs_files:\n",
" content = rs_file.read_text()\n",
" \n",
" if \"impl Solution\" not in content:\n",
" impl_matches = re.findall(r\"impl\\s+(\\w+)\", content)\n",
" print(f\"⚠️ Skipped (no impl Solution): {rs_file.name} — found: {impl_matches}\")\n",
" skipped_no_impl += 1\n",
" \n",
" elif not re.search(r\"impl\\s+Solution\\s*\\{\", content):\n",
" print(f\"❓ Skipped (pattern mismatch): {rs_file.name}\")\n",
" skipped_pattern_mismatch += 1\n",
" \n",
" else:\n",
" valid_count += 1\n",
"\n",
"# --- Final Summary ---\n",
"print(\"\\n\" + \"=\"*30)\n",
"print(\" FINAL SUMMARY\")\n",
"print(\"=\"*30)\n",
"print(f\"Total Files Scanned: {total_files}\")\n",
"print(f\"✅ Valid Solutions: {valid_count}\")\n",
"print(f\"❌ No 'impl Solution': {skipped_no_impl}\")\n",
"print(f\"⚠️ Pattern Mismatch: {skipped_pattern_mismatch}\")\n",
"print(f\"Total Skipped: {skipped_no_impl + skipped_pattern_mismatch}\")\n",
"print(\"=\"*30)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Files with trailing comments after impl Solution: 0\n",
"\n",
"Files with multiple impl blocks: 0\n",
"\n",
"Files with multiple functions in impl Solution: 0\n"
]
}
],
"source": [
"import json\n",
"import re\n",
"from pathlib import Path\n",
"RUST_SOLUTIONS_DIR = Path(\"/media/tm23/NewVolume/rust_dataset/complexity_reasoning_data/rust_solutions/\")\n",
"files_with_trailing_comments = []\n",
"files_with_multiple_impl = []\n",
"files_with_multiple_funcs = []\n",
"for rs_file in sorted(RUST_SOLUTIONS_DIR.glob(\"*.rs\")):\n",
" content = rs_file.read_text()\n",
" if \"impl Solution\" not in content:\n",
" continue\n",
" # Check for multiple impl blocks\n",
" impl_blocks = list(re.finditer(r\"impl\\s+\\w+\\s*\\{\", content))\n",
" if len(impl_blocks) > 1:\n",
" impl_names = [re.search(r\"impl\\s+(\\w+)\", m.group()).group(1) for m in impl_blocks]\n",
" files_with_multiple_impl.append({\n",
" \"file\": rs_file.name,\n",
" \"impls\": impl_names,\n",
" })\n",
" # Check for trailing content after impl Solution block\n",
" impl_match = re.search(r\"impl\\s+Solution\\s*\\{\", content)\n",
" if impl_match:\n",
" # Find matching closing brace\n",
" depth = 0\n",
" i = impl_match.end() - 1\n",
" while i < len(content):\n",
" if content[i] == '{':\n",
" depth += 1\n",
" elif content[i] == '}':\n",
" depth -= 1\n",
" if depth == 0:\n",
" impl_end = i\n",
" break\n",
" i += 1\n",
" else:\n",
" impl_end = len(content)\n",
" trailing = content[impl_end + 1:].strip()\n",
" if trailing:\n",
" # Check if it has actual content (not just whitespace)\n",
" lines = [l for l in trailing.splitlines() if l.strip() and not l.strip().startswith(\"//\")]\n",
" comment_lines = [l for l in trailing.splitlines() if l.strip().startswith(\"//\")]\n",
" if comment_lines or lines:\n",
" files_with_trailing_comments.append({\n",
" \"file\": rs_file.name,\n",
" \"trailing\": trailing[:300],\n",
" \"has_code\": bool(lines),\n",
" \"comment_count\": len(comment_lines),\n",
" })\n",
" # Check for multiple functions in impl Solution\n",
" impl_start = impl_match.start() if impl_match else 0\n",
" impl_block = content[impl_start:impl_end + 1] if impl_match else \"\"\n",
" fn_matches = re.findall(r\"(?:pub\\s+)?fn\\s+(\\w+)\", impl_block)\n",
" if len(fn_matches) > 1:\n",
" files_with_multiple_funcs.append({\n",
" \"file\": rs_file.name,\n",
" \"functions\": fn_matches,\n",
" })\n",
"print(f\"Files with trailing comments after impl Solution: {len(files_with_trailing_comments)}\")\n",
"for item in files_with_trailing_comments[:10]:\n",
" print(f\" {item['file']} — {item['comment_count']} comment lines, has_code={item['has_code']}\")\n",
" print(f\" Trailing: {item['trailing'][:150]}\")\n",
"if len(files_with_trailing_comments) > 10:\n",
" print(f\" ... and {len(files_with_trailing_comments) - 10} more\")\n",
"print(f\"\\nFiles with multiple impl blocks: {len(files_with_multiple_impl)}\")\n",
"for item in files_with_multiple_impl[:10]:\n",
" print(f\" {item['file']} — impls: {item['impls']}\")\n",
"if len(files_with_multiple_impl) > 10:\n",
" print(f\" ... and {len(files_with_multiple_impl) - 10} more\")\n",
"print(f\"\\nFiles with multiple functions in impl Solution: {len(files_with_multiple_funcs)}\")\n",
"for item in files_with_multiple_funcs[:10]:\n",
" print(f\" {item['file']} — functions: {item['functions']}\")\n",
"if len(files_with_multiple_funcs) > 10:\n",
" print(f\" ... and {len(files_with_multiple_funcs) - 10} more\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
|