problem set generator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

question parsing and number generation, newline problem

+400 -14
+290 -1
Cargo.lock
··· 18 18 ] 19 19 20 20 [[package]] 21 + name = "anyhow" 22 + version = "1.0.102" 23 + source = "registry+https://github.com/rust-lang/crates.io-index" 24 + checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" 25 + 26 + [[package]] 21 27 name = "approx" 22 28 version = "0.3.2" 23 29 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 106 112 ] 107 113 108 114 [[package]] 115 + name = "bitflags" 116 + version = "2.11.1" 117 + source = "registry+https://github.com/rust-lang/crates.io-index" 118 + checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" 119 + 120 + [[package]] 109 121 name = "bstr" 110 122 version = "1.12.1" 111 123 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 151 163 checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 152 164 153 165 [[package]] 166 + name = "chacha20" 167 + version = "0.10.0" 168 + source = "registry+https://github.com/rust-lang/crates.io-index" 169 + checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" 170 + dependencies = [ 171 + "cfg-if", 172 + "cpufeatures", 173 + "rand_core", 174 + ] 175 + 176 + [[package]] 154 177 name = "chrono" 155 178 version = "0.4.44" 156 179 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 174 197 version = "0.8.7" 175 198 source = "registry+https://github.com/rust-lang/crates.io-index" 176 199 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 200 + 201 + [[package]] 202 + name = "cpufeatures" 203 + version = "0.3.0" 204 + source = "registry+https://github.com/rust-lang/crates.io-index" 205 + checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" 206 + dependencies = [ 207 + "libc", 208 + ] 177 209 178 210 [[package]] 179 211 name = "crc32fast" ··· 272 304 checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" 273 305 274 306 [[package]] 307 + name = "equivalent" 308 + version = "1.0.2" 309 + source = "registry+https://github.com/rust-lang/crates.io-index" 310 + checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 311 + 312 + [[package]] 275 313 name = "find-msvc-tools" 276 314 version = "0.1.9" 277 315 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 286 324 "crc32fast", 287 325 "miniz_oxide", 288 326 ] 327 + 328 + [[package]] 329 + name = "foldhash" 330 + version = "0.1.5" 331 + source = "registry+https://github.com/rust-lang/crates.io-index" 332 + checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" 289 333 290 334 [[package]] 291 335 name = "form_urlencoded" ··· 347 391 "printpdf", 348 392 "rusttype", 349 393 ] 394 + 395 + [[package]] 396 + name = "getrandom" 397 + version = "0.4.2" 398 + source = "registry+https://github.com/rust-lang/crates.io-index" 399 + checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" 400 + dependencies = [ 401 + "cfg-if", 402 + "libc", 403 + "r-efi", 404 + "rand_core", 405 + "wasip2", 406 + "wasip3", 407 + ] 408 + 409 + [[package]] 410 + name = "hashbrown" 411 + version = "0.15.5" 412 + source = "registry+https://github.com/rust-lang/crates.io-index" 413 + checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" 414 + dependencies = [ 415 + "foldhash", 416 + ] 417 + 418 + [[package]] 419 + name = "hashbrown" 420 + version = "0.17.0" 421 + source = "registry+https://github.com/rust-lang/crates.io-index" 422 + checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" 350 423 351 424 [[package]] 352 425 name = "heck" ··· 482 555 ] 483 556 484 557 [[package]] 558 + name = "id-arena" 559 + version = "2.3.0" 560 + source = "registry+https://github.com/rust-lang/crates.io-index" 561 + checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" 562 + 563 + [[package]] 564 + name = "indexmap" 565 + version = "2.14.0" 566 + source = "registry+https://github.com/rust-lang/crates.io-index" 567 + checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" 568 + dependencies = [ 569 + "equivalent", 570 + "hashbrown 0.17.0", 571 + "serde", 572 + "serde_core", 573 + ] 574 + 575 + [[package]] 485 576 name = "itoa" 486 577 version = "0.4.8" 487 578 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 502 593 "once_cell", 503 594 "wasm-bindgen", 504 595 ] 596 + 597 + [[package]] 598 + name = "leb128fmt" 599 + version = "0.1.0" 600 + source = "registry+https://github.com/rust-lang/crates.io-index" 601 + checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" 505 602 506 603 [[package]] 507 604 name = "libc" ··· 636 733 ] 637 734 638 735 [[package]] 736 + name = "prettyplease" 737 + version = "0.2.37" 738 + source = "registry+https://github.com/rust-lang/crates.io-index" 739 + checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" 740 + dependencies = [ 741 + "proc-macro2", 742 + "syn 2.0.117", 743 + ] 744 + 745 + [[package]] 639 746 name = "printpdf" 640 747 version = "0.3.4" 641 748 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 654 761 "axum", 655 762 "genpdf", 656 763 "hyphenation", 764 + "rand", 657 765 "strum", 658 766 "strum_macros", 659 767 "tokio", ··· 684 792 ] 685 793 686 794 [[package]] 795 + name = "r-efi" 796 + version = "6.0.0" 797 + source = "registry+https://github.com/rust-lang/crates.io-index" 798 + checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" 799 + 800 + [[package]] 801 + name = "rand" 802 + version = "0.10.1" 803 + source = "registry+https://github.com/rust-lang/crates.io-index" 804 + checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" 805 + dependencies = [ 806 + "chacha20", 807 + "getrandom", 808 + "rand_core", 809 + ] 810 + 811 + [[package]] 812 + name = "rand_core" 813 + version = "0.10.1" 814 + source = "registry+https://github.com/rust-lang/crates.io-index" 815 + checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" 816 + 817 + [[package]] 687 818 name = "regex-automata" 688 819 version = "0.4.14" 689 820 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 695 826 source = "registry+https://github.com/rust-lang/crates.io-index" 696 827 checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 697 828 dependencies = [ 698 - "semver", 829 + "semver 0.9.0", 699 830 ] 700 831 701 832 [[package]] ··· 729 860 dependencies = [ 730 861 "semver-parser", 731 862 ] 863 + 864 + [[package]] 865 + name = "semver" 866 + version = "1.0.28" 867 + source = "registry+https://github.com/rust-lang/crates.io-index" 868 + checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" 732 869 733 870 [[package]] 734 871 name = "semver-parser" ··· 1082 1219 checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" 1083 1220 1084 1221 [[package]] 1222 + name = "unicode-xid" 1223 + version = "0.2.6" 1224 + source = "registry+https://github.com/rust-lang/crates.io-index" 1225 + checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" 1226 + 1227 + [[package]] 1085 1228 name = "version_check" 1086 1229 version = "0.9.5" 1087 1230 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1094 1237 checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" 1095 1238 1096 1239 [[package]] 1240 + name = "wasip2" 1241 + version = "1.0.3+wasi-0.2.9" 1242 + source = "registry+https://github.com/rust-lang/crates.io-index" 1243 + checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" 1244 + dependencies = [ 1245 + "wit-bindgen 0.57.1", 1246 + ] 1247 + 1248 + [[package]] 1249 + name = "wasip3" 1250 + version = "0.4.0+wasi-0.3.0-rc-2026-01-06" 1251 + source = "registry+https://github.com/rust-lang/crates.io-index" 1252 + checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" 1253 + dependencies = [ 1254 + "wit-bindgen 0.51.0", 1255 + ] 1256 + 1257 + [[package]] 1097 1258 name = "wasm-bindgen" 1098 1259 version = "0.2.118" 1099 1260 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1139 1300 ] 1140 1301 1141 1302 [[package]] 1303 + name = "wasm-encoder" 1304 + version = "0.244.0" 1305 + source = "registry+https://github.com/rust-lang/crates.io-index" 1306 + checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" 1307 + dependencies = [ 1308 + "leb128fmt", 1309 + "wasmparser", 1310 + ] 1311 + 1312 + [[package]] 1313 + name = "wasm-metadata" 1314 + version = "0.244.0" 1315 + source = "registry+https://github.com/rust-lang/crates.io-index" 1316 + checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" 1317 + dependencies = [ 1318 + "anyhow", 1319 + "indexmap", 1320 + "wasm-encoder", 1321 + "wasmparser", 1322 + ] 1323 + 1324 + [[package]] 1325 + name = "wasmparser" 1326 + version = "0.244.0" 1327 + source = "registry+https://github.com/rust-lang/crates.io-index" 1328 + checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" 1329 + dependencies = [ 1330 + "bitflags", 1331 + "hashbrown 0.15.5", 1332 + "indexmap", 1333 + "semver 1.0.28", 1334 + ] 1335 + 1336 + [[package]] 1142 1337 name = "winapi" 1143 1338 version = "0.3.9" 1144 1339 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1226 1421 checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 1227 1422 dependencies = [ 1228 1423 "windows-link", 1424 + ] 1425 + 1426 + [[package]] 1427 + name = "wit-bindgen" 1428 + version = "0.51.0" 1429 + source = "registry+https://github.com/rust-lang/crates.io-index" 1430 + checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" 1431 + dependencies = [ 1432 + "wit-bindgen-rust-macro", 1433 + ] 1434 + 1435 + [[package]] 1436 + name = "wit-bindgen" 1437 + version = "0.57.1" 1438 + source = "registry+https://github.com/rust-lang/crates.io-index" 1439 + checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" 1440 + 1441 + [[package]] 1442 + name = "wit-bindgen-core" 1443 + version = "0.51.0" 1444 + source = "registry+https://github.com/rust-lang/crates.io-index" 1445 + checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" 1446 + dependencies = [ 1447 + "anyhow", 1448 + "heck", 1449 + "wit-parser", 1450 + ] 1451 + 1452 + [[package]] 1453 + name = "wit-bindgen-rust" 1454 + version = "0.51.0" 1455 + source = "registry+https://github.com/rust-lang/crates.io-index" 1456 + checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" 1457 + dependencies = [ 1458 + "anyhow", 1459 + "heck", 1460 + "indexmap", 1461 + "prettyplease", 1462 + "syn 2.0.117", 1463 + "wasm-metadata", 1464 + "wit-bindgen-core", 1465 + "wit-component", 1466 + ] 1467 + 1468 + [[package]] 1469 + name = "wit-bindgen-rust-macro" 1470 + version = "0.51.0" 1471 + source = "registry+https://github.com/rust-lang/crates.io-index" 1472 + checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" 1473 + dependencies = [ 1474 + "anyhow", 1475 + "prettyplease", 1476 + "proc-macro2", 1477 + "quote", 1478 + "syn 2.0.117", 1479 + "wit-bindgen-core", 1480 + "wit-bindgen-rust", 1481 + ] 1482 + 1483 + [[package]] 1484 + name = "wit-component" 1485 + version = "0.244.0" 1486 + source = "registry+https://github.com/rust-lang/crates.io-index" 1487 + checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" 1488 + dependencies = [ 1489 + "anyhow", 1490 + "bitflags", 1491 + "indexmap", 1492 + "log", 1493 + "serde", 1494 + "serde_derive", 1495 + "serde_json", 1496 + "wasm-encoder", 1497 + "wasm-metadata", 1498 + "wasmparser", 1499 + "wit-parser", 1500 + ] 1501 + 1502 + [[package]] 1503 + name = "wit-parser" 1504 + version = "0.244.0" 1505 + source = "registry+https://github.com/rust-lang/crates.io-index" 1506 + checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" 1507 + dependencies = [ 1508 + "anyhow", 1509 + "id-arena", 1510 + "indexmap", 1511 + "log", 1512 + "semver 1.0.28", 1513 + "serde", 1514 + "serde_derive", 1515 + "serde_json", 1516 + "unicode-xid", 1517 + "wasmparser", 1229 1518 ] 1230 1519 1231 1520 [[package]]
+1
Cargo.toml
··· 7 7 axum = "0.8.9" 8 8 genpdf = { version = "0.2.0", features = ["hyphenation"] } 9 9 hyphenation = { version = "0.8.4", features = ["embed_en-us"] } 10 + rand = "0.10.1" 10 11 strum = "0.28.0" 11 12 strum_macros = "0.28.0" 12 13 tokio = { version = "1.52.1", features = ["rt-multi-thread"] }
+6
README.md
··· 24 24 - [ ] Port axum to run on [shuttle.dev](https://www.shuttle.dev/) 25 25 - [ ] Write a front-end page with a basic form that would open a new tab with the pdf requested on [my website](https://tangled.org/sevenpigeons.ca/sevenpigeons.ca) 26 26 27 + ## Questions 28 + 29 + Questions are represented by a `struct` with it's subject, theme, and the text of the question. 30 + 31 + To parse from string (and text file), first line is the Subject, second Theme, and everything afterwards the text of the question. 32 + 27 33 ## Fonts 28 34 29 35 ~I am not sure about distributing Roboto font for now, please add~
+18
problems/Math/PartialDerivatives/3elem.txt
··· 1 + Math; 2 + PartialDerivatives; 3 + 4 + f(x,y) = x^ {{0}} + x^ {{1}} *y^ {{2}} - {{3}} *y^ {{4}} 5 + 6 + f_x( {{5}} , {{6}} ) = ? 7 + f_y( {{7}} , {{8}} ) = ?; 8 + 1,5 9 + 2,5 10 + 2,5 11 + 1,5 12 + 1,5 13 + 1,33 14 + 2,44 15 + 1,33 16 + 2,44; 17 + {{1}} 18 +
+34 -5
src/main.rs
··· 29 29 30 30 let mut doc = build_document_base(state); 31 31 32 + let test_string: &str = "Math; 33 + PartialDerivatives; 34 + 35 + f(x,y) = x^ {{0}} + x^ {{1}} *y^ {{2}} - {{3}} *y^ {{4}} 36 + 37 + f_x( {{5}} , {{6}} ) = ? 38 + 39 + f_y( {{7}} , {{8}} ) = ?; 40 + 1,5 41 + 2,5 42 + 2,5 43 + 1,5 44 + 1,5 45 + 1,33 46 + 2,44 47 + 1,33 48 + 2,44"; 49 + 50 + let q = Question::from_str(test_string).unwrap(); 51 + 32 52 for i in 0..len { 33 53 doc.push( 34 54 genpdf::elements::Paragraph::new( 35 - format!("this is line {}", i) 55 + // format!("this is line {}", i) 56 + q.generate_question() 36 57 )); 37 58 } 38 59 ··· 73 94 74 95 #[test] 75 96 fn test_string_to_question_parse() { 76 - let test_question = Question {subject:util::Subject::Math,theme:util::Theme::Math(util::MathTheme::ParametricEquations),text: "\n\n{{}} + y = 12".to_string()}; 77 - let test_string: &str = "Math 78 - ParametricEquations 97 + let test_question = Question { 98 + subject:util::Subject::Math, 99 + theme:util::Theme::Math(util::MathTheme::ParametricEquations), 100 + text: "\n\n{{0}} + y = 12".to_string(), 101 + var_conditions:vec![(1,4)], 102 + ans_expression: None}; 103 + let test_string: &str = "Math; 104 + ParametricEquations; 79 105 80 106 81 - {{}} + y = 12"; 107 + {{0}} + y = 12; 108 + 1,4"; 82 109 110 + let text = Question::from_str(test_string).unwrap().generate_question(); 111 + println!("{}\n",text); 83 112 assert_eq!(Question::from_str(test_string).unwrap(),test_question); 84 113 85 114 }
+51 -8
src/util.rs
··· 3 3 4 4 use axum::{http::{HeaderMap, header}, response::IntoResponse}; 5 5 use genpdf::{Document, elements::{self, Paragraph}, style}; 6 + use rand::random_range; 6 7 use crate::GenpdfState; 7 8 use strum_macros::{Display, EnumString}; 8 9 ··· 32 33 ParametricEquations, 33 34 InfiniteSequenceSeries, 34 35 PartialDerivatives, 35 - 36 + 36 37 } 37 38 38 39 #[derive(Debug,PartialEq)] 39 40 pub struct Question { 40 41 pub subject: Subject, 41 42 pub theme: Theme, 42 - pub text: String 43 + pub text: String, 44 + pub var_conditions: Vec<(i32,i32)>, 45 + pub ans_expression: Option<String> 43 46 } 44 47 45 48 #[derive(Debug,Display)] ··· 51 54 impl FromStr for Question { 52 55 type Err = QuestionParseError; 53 56 fn from_str(s: &str) -> Result<Self, Self::Err> { 54 - let l : Vec<&str> = s.splitn(3, '\n').collect(); 57 + let l : Vec<&str> = s.splitn(5, ";\n").collect(); 55 58 let subj: Subject = Subject::from_str(l[0]).unwrap(); 56 59 let theme: Theme = match subj { 57 - Subject::Math => Theme::Math(MathTheme::from_str(l[1]).unwrap()), 60 + Subject::Math => Theme::Math( match MathTheme::from_str(l[1]) { 61 + Ok(t) => t, 62 + Err(err) => panic!("{err}: string {0}",l[1]) 63 + }), 58 64 Subject::Physics => Theme::Physics(PhysTheme::from_str(l[1]).unwrap()), 59 65 }; 60 - if !l[2].is_empty() { 61 - Ok(Question { subject: subj, theme: theme, text: l[2].to_string() }) 66 + if l[2].is_empty() { 67 + return Err(QuestionParseError::QuestionFileParseError); 68 + } 69 + let var_amount = l[2].to_string().matches("{{").collect::<Vec<_>>().len(); 70 + if l[3].is_empty() { 71 + return Err(QuestionParseError::QuestionFileParseError); 72 + } 73 + let lines = l[3].lines().collect::<Vec<_>>(); 74 + if !(lines.len() == var_amount) { 75 + return Err(QuestionParseError::QuestionFileParseError); 76 + } 77 + 78 + let var_conf:Vec<(i32,i32)> = lines.iter().map(|x| { 79 + let elements:Vec<_> = x.split(",").collect(); 80 + (elements[0].parse().unwrap(),elements[1].parse().unwrap()) 81 + } 82 + ).collect(); 83 + 84 + if l.len() < 4 { 85 + Ok(Question { subject: subj, theme: theme, text: l[2].to_string(),var_conditions:var_conf ,ans_expression: Some(l[4].to_string()) }) 62 86 } else { 63 - Err(QuestionParseError::QuestionFileParseError) 87 + Ok(Question { subject: subj, theme: theme, text: l[2].to_string(),var_conditions:var_conf ,ans_expression: None }) 64 88 } 65 89 } 66 - 90 + 91 + } 92 + 93 + 94 + impl Question { 95 + pub fn generate_question(&self) -> String { 96 + let text = self.text.split_whitespace().map(|x| { 97 + if x.contains("{{") { 98 + if x[0..2] == *"{{" && x[3..5] == *"}}" { 99 + let var_num:usize = x.chars().nth(2).unwrap().to_string().parse().unwrap(); 100 + return format!("{}",random_range(self.var_conditions[var_num].0..self.var_conditions[var_num].1)).to_string(); 101 + } 102 + } 103 + x.to_string() 104 + }).collect(); 105 + 106 + text 107 + } 108 + 67 109 } 110 + 68 111 69 112 70 113 pub fn build_document_base(state:GenpdfState) -> Document {