diff --git a/.travis.yml b/.travis.yml index d2394b409..f794cde82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,9 @@ jobs: - mypy --ignore-missing-imports . || true # https://github.com/python/mypy/issues/7907 - pytest --doctest-modules --ignore=project_euler/ --durations=10 --cov-report=term-missing:skip-covered --cov=. . - name: Project Euler - before_script: pip install pytest-cov + before_script: + - pip install pytest-cov pytest-subtests + - pytest --tb=no --no-summary --capture=no project_euler/validate_solutions.py || true # fail fast on wrong solution script: - pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ after_success: diff --git a/project_euler/project_euler_answers.json b/project_euler/project_euler_answers.json new file mode 100644 index 000000000..3c4cc694e --- /dev/null +++ b/project_euler/project_euler_answers.json @@ -0,0 +1,2902 @@ +[ + [ + 1, + "233168" + ], + [ + 2, + "4613732" + ], + [ + 3, + "6857" + ], + [ + 4, + "906609" + ], + [ + 5, + "232792560" + ], + [ + 6, + "25164150" + ], + [ + 7, + "104743" + ], + [ + 8, + "23514624000" + ], + [ + 9, + "31875000" + ], + [ + 10, + "142913828922" + ], + [ + 11, + "70600674" + ], + [ + 12, + "76576500" + ], + [ + 13, + "5537376230" + ], + [ + 14, + "837799" + ], + [ + 15, + "137846528820" + ], + [ + 16, + "1366" + ], + [ + 17, + "21124" + ], + [ + 18, + "1074" + ], + [ + 19, + "171" + ], + [ + 20, + "648" + ], + [ + 21, + "31626" + ], + [ + 22, + "871198282" + ], + [ + 23, + "4179871" + ], + [ + 24, + "2783915460" + ], + [ + 25, + "4782" + ], + [ + 26, + "983" + ], + [ + 27, + "-59231" + ], + [ + 28, + "669171001" + ], + [ + 29, + "9183" + ], + [ + 30, + "443839" + ], + [ + 31, + "73682" + ], + [ + 32, + "45228" + ], + [ + 33, + "100" + ], + [ + 34, + "40730" + ], + [ + 35, + "55" + ], + [ + 36, + "872187" + ], + [ + 37, + "748317" + ], + [ + 38, + "932718654" + ], + [ + 39, + "840" + ], + [ + 40, + "210" + ], + [ + 41, + "7652413" + ], + [ + 42, + "162" + ], + [ + 43, + "16695334890" + ], + [ + 44, + "5482660" + ], + [ + 45, + "1533776805" + ], + [ + 46, + "5777" + ], + [ + 47, + "134043" + ], + [ + 48, + "9110846700" + ], + [ + 49, + "296962999629" + ], + [ + 50, + "997651" + ], + [ + 51, + "121313" + ], + [ + 52, + "142857" + ], + [ + 53, + "4075" + ], + [ + 54, + "376" + ], + [ + 55, + "249" + ], + [ + 56, + "972" + ], + [ + 57, + "153" + ], + [ + 58, + "26241" + ], + [ + 59, + "129448" + ], + [ + 60, + "26033" + ], + [ + 61, + "28684" + ], + [ + 62, + "127035954683" + ], + [ + 63, + "49" + ], + [ + 64, + "1322" + ], + [ + 65, + "272" + ], + [ + 66, + "661" + ], + [ + 67, + "7273" + ], + [ + 68, + "6531031914842725" + ], + [ + 69, + "510510" + ], + [ + 70, + "8319823" + ], + [ + 71, + "428570" + ], + [ + 72, + "303963552391" + ], + [ + 73, + "7295372" + ], + [ + 74, + "402" + ], + [ + 75, + "161667" + ], + [ + 76, + "190569291" + ], + [ + 77, + "71" + ], + [ + 78, + "55374" + ], + [ + 79, + "73162890" + ], + [ + 80, + "40886" + ], + [ + 81, + "427337" + ], + [ + 82, + "260324" + ], + [ + 83, + "425185" + ], + [ + 84, + "101524" + ], + [ + 85, + "2772" + ], + [ + 86, + "1818" + ], + [ + 87, + "1097343" + ], + [ + 88, + "7587457" + ], + [ + 89, + "743" + ], + [ + 90, + "1217" + ], + [ + 91, + "14234" + ], + [ + 92, + "8581146" + ], + [ + 93, + "1258" + ], + [ + 94, + "518408346" + ], + [ + 95, + "14316" + ], + [ + 96, + "24702" + ], + [ + 97, + "8739992577" + ], + [ + 98, + "18769" + ], + [ + 99, + "709" + ], + [ + 100, + "756872327473" + ], + [ + 101, + "37076114526" + ], + [ + 102, + "228" + ], + [ + 103, + "20313839404245" + ], + [ + 104, + "329468" + ], + [ + 105, + "73702" + ], + [ + 106, + "21384" + ], + [ + 107, + "259679" + ], + [ + 108, + "180180" + ], + [ + 109, + "38182" + ], + [ + 110, + "9350130049860600" + ], + [ + 111, + "612407567715" + ], + [ + 112, + "1587000" + ], + [ + 113, + "51161058134250" + ], + [ + 114, + "16475640049" + ], + [ + 115, + "168" + ], + [ + 116, + "20492570929" + ], + [ + 117, + "100808458960497" + ], + [ + 118, + "44680" + ], + [ + 119, + "248155780267521" + ], + [ + 120, + "333082500" + ], + [ + 121, + "2269" + ], + [ + 122, + "1582" + ], + [ + 123, + "21035" + ], + [ + 124, + "21417" + ], + [ + 125, + "2906969179" + ], + [ + 126, + "18522" + ], + [ + 127, + "18407904" + ], + [ + 128, + "14516824220" + ], + [ + 129, + "1000023" + ], + [ + 130, + "149253" + ], + [ + 131, + "173" + ], + [ + 132, + "843296" + ], + [ + 133, + "453647705" + ], + [ + 134, + "18613426663617118" + ], + [ + 135, + "4989" + ], + [ + 136, + "2544559" + ], + [ + 137, + "1120149658760" + ], + [ + 138, + "1118049290473932" + ], + [ + 139, + "10057761" + ], + [ + 140, + "5673835352990" + ], + [ + 141, + "878454337159" + ], + [ + 142, + "1006193" + ], + [ + 143, + "30758397" + ], + [ + 144, + "354" + ], + [ + 145, + "608720" + ], + [ + 146, + "676333270" + ], + [ + 147, + "846910284" + ], + [ + 148, + "2129970655314432" + ], + [ + 149, + "52852124" + ], + [ + 150, + "-271248680" + ], + [ + 151, + "0.464399" + ], + [ + 152, + "301" + ], + [ + 153, + "17971254122360635" + ], + [ + 154, + "479742450" + ], + [ + 155, + "3857447" + ], + [ + 156, + "21295121502550" + ], + [ + 157, + "53490" + ], + [ + 158, + "409511334375" + ], + [ + 159, + "14489159" + ], + [ + 160, + "16576" + ], + [ + 161, + "20574308184277971" + ], + [ + 162, + "3D58725572C62302" + ], + [ + 163, + "343047" + ], + [ + 164, + "378158756814587" + ], + [ + 165, + "2868868" + ], + [ + 166, + "7130034" + ], + [ + 167, + "3916160068885" + ], + [ + 168, + "59206" + ], + [ + 169, + "178653872807" + ], + [ + 170, + "9857164023" + ], + [ + 171, + "142989277" + ], + [ + 172, + "227485267000992000" + ], + [ + 173, + "1572729" + ], + [ + 174, + "209566" + ], + [ + 175, + "1,13717420,8" + ], + [ + 176, + "96818198400000" + ], + [ + 177, + "129325" + ], + [ + 178, + "126461847755" + ], + [ + 179, + "986262" + ], + [ + 180, + "285196020571078987" + ], + [ + 181, + "83735848679360680" + ], + [ + 182, + "399788195976" + ], + [ + 183, + "48861552" + ], + [ + 184, + "1725323624056" + ], + [ + 185, + "4640261571849533" + ], + [ + 186, + "2325629" + ], + [ + 187, + "17427258" + ], + [ + 188, + "95962097" + ], + [ + 189, + "10834893628237824" + ], + [ + 190, + "371048281" + ], + [ + 191, + "1918080160" + ], + [ + 192, + "57060635927998347" + ], + [ + 193, + "684465067343069" + ], + [ + 194, + "61190912" + ], + [ + 195, + "75085391" + ], + [ + 196, + "322303240771079935" + ], + [ + 197, + "1.710637717" + ], + [ + 198, + "52374425" + ], + [ + 199, + "0.00396087" + ], + [ + 200, + "229161792008" + ], + [ + 201, + "115039000" + ], + [ + 202, + "1209002624" + ], + [ + 203, + "34029210557338" + ], + [ + 204, + "2944730" + ], + [ + 205, + "0.5731441" + ], + [ + 206, + "1389019170" + ], + [ + 207, + "44043947822" + ], + [ + 208, + "331951449665644800" + ], + [ + 209, + "15964587728784" + ], + [ + 210, + "1598174770174689458" + ], + [ + 211, + "1922364685" + ], + [ + 212, + "328968937309" + ], + [ + 213, + "330.721154" + ], + [ + 214, + "1677366278943" + ], + [ + 215, + "806844323190414" + ], + [ + 216, + "5437849" + ], + [ + 217, + "6273134" + ], + [ + 218, + "0" + ], + [ + 219, + "64564225042" + ], + [ + 220, + "139776,963904" + ], + [ + 221, + "1884161251122450" + ], + [ + 222, + "1590933" + ], + [ + 223, + "61614848" + ], + [ + 224, + "4137330" + ], + [ + 225, + "2009" + ], + [ + 226, + "0.11316017" + ], + [ + 227, + "3780.618622" + ], + [ + 228, + "86226" + ], + [ + 229, + "11325263" + ], + [ + 230, + "850481152593119296" + ], + [ + 231, + "7526965179680" + ], + [ + 232, + "0.83648556" + ], + [ + 233, + "271204031455541309" + ], + [ + 234, + "1259187438574927161" + ], + [ + 235, + "1.002322108633" + ], + [ + 236, + "123/59" + ], + [ + 237, + "15836928" + ], + [ + 238, + "9922545104535661" + ], + [ + 239, + "0.001887854841" + ], + [ + 240, + "7448717393364181966" + ], + [ + 241, + "482316491800641154" + ], + [ + 242, + "997104142249036713" + ], + [ + 243, + "892371480" + ], + [ + 244, + "96356848" + ], + [ + 245, + "288084712410001" + ], + [ + 246, + "810834388" + ], + [ + 247, + "782252" + ], + [ + 248, + "23507044290" + ], + [ + 249, + "9275262564250418" + ], + [ + 250, + "1425480602091519" + ], + [ + 251, + "18946051" + ], + [ + 252, + "104924.0" + ], + [ + 253, + "11.492847" + ], + [ + 254, + "8184523820510" + ], + [ + 255, + "4.4474011180" + ], + [ + 256, + "85765680" + ], + [ + 257, + "139012411" + ], + [ + 258, + "12747994" + ], + [ + 259, + "20101196798" + ], + [ + 260, + "167542057" + ], + [ + 261, + "238890850232021" + ], + [ + 262, + "2531.205" + ], + [ + 263, + "2039506520" + ], + [ + 264, + "2816417.1055" + ], + [ + 265, + "209110240768" + ], + [ + 266, + "1096883702440585" + ], + [ + 267, + "0.999992836187" + ], + [ + 268, + "785478606870985" + ], + [ + 269, + "1311109198529286" + ], + [ + 270, + "82282080" + ], + [ + 271, + "4617456485273129588" + ], + [ + 272, + "8495585919506151122" + ], + [ + 273, + "2032447591196869022" + ], + [ + 274, + "1601912348822" + ], + [ + 275, + "15030564" + ], + [ + 276, + "5777137137739632912" + ], + [ + 277, + "1125977393124310" + ], + [ + 278, + "1228215747273908452" + ], + [ + 279, + "416577688" + ], + [ + 280, + "430.088247" + ], + [ + 281, + "1485776387445623" + ], + [ + 282, + "1098988351" + ], + [ + 283, + "28038042525570324" + ], + [ + 284, + "5a411d7b" + ], + [ + 285, + "157055.80999" + ], + [ + 286, + "52.6494571953" + ], + [ + 287, + "313135496" + ], + [ + 288, + "605857431263981935" + ], + [ + 289, + "6567944538" + ], + [ + 290, + "20444710234716473" + ], + [ + 291, + "4037526" + ], + [ + 292, + "3600060866" + ], + [ + 293, + "2209" + ], + [ + 294, + "789184709" + ], + [ + 295, + "4884650818" + ], + [ + 296, + "1137208419" + ], + [ + 297, + "2252639041804718029" + ], + [ + 298, + "1.76882294" + ], + [ + 299, + "549936643" + ], + [ + 300, + "8.0540771484375" + ], + [ + 301, + "2178309" + ], + [ + 302, + "1170060" + ], + [ + 303, + "1111981904675169" + ], + [ + 304, + "283988410192" + ], + [ + 305, + "18174995535140" + ], + [ + 306, + "852938" + ], + [ + 307, + "0.7311720251" + ], + [ + 308, + "1539669807660924" + ], + [ + 309, + "210139" + ], + [ + 310, + "2586528661783" + ], + [ + 311, + "2466018557" + ], + [ + 312, + "324681947" + ], + [ + 313, + "2057774861813004" + ], + [ + 314, + "132.52756426" + ], + [ + 315, + "13625242" + ], + [ + 316, + "542934735751917735" + ], + [ + 317, + "1856532.8455" + ], + [ + 318, + "709313889" + ], + [ + 319, + "268457129" + ], + [ + 320, + "278157919195482643" + ], + [ + 321, + "2470433131948040" + ], + [ + 322, + "999998760323313995" + ], + [ + 323, + "6.3551758451" + ], + [ + 324, + "96972774" + ], + [ + 325, + "54672965" + ], + [ + 326, + "1966666166408794329" + ], + [ + 327, + "34315549139516" + ], + [ + 328, + "260511850222" + ], + [ + 329, + "199740353/29386561536000" + ], + [ + 330, + "15955822" + ], + [ + 331, + "467178235146843549" + ], + [ + 332, + "2717.751525" + ], + [ + 333, + "3053105" + ], + [ + 334, + "150320021261690835" + ], + [ + 335, + "5032316" + ], + [ + 336, + "CAGBIHEFJDK" + ], + [ + 337, + "85068035" + ], + [ + 338, + "15614292" + ], + [ + 339, + "19823.542204" + ], + [ + 340, + "291504964" + ], + [ + 341, + "56098610614277014" + ], + [ + 342, + "5943040885644" + ], + [ + 343, + "269533451410884183" + ], + [ + 344, + "65579304332" + ], + [ + 345, + "13938" + ], + [ + 346, + "336108797689259276" + ], + [ + 347, + "11109800204052" + ], + [ + 348, + "1004195061" + ], + [ + 349, + "115384615384614952" + ], + [ + 350, + "84664213" + ], + [ + 351, + "11762187201804552" + ], + [ + 352, + "378563.260589" + ], + [ + 353, + "1.2759860331" + ], + [ + 354, + "58065134" + ], + [ + 355, + "1726545007" + ], + [ + 356, + "28010159" + ], + [ + 357, + "1739023853137" + ], + [ + 358, + "3284144505" + ], + [ + 359, + "40632119" + ], + [ + 360, + "878825614395267072" + ], + [ + 361, + "178476944" + ], + [ + 362, + "457895958010" + ], + [ + 363, + "0.0000372091" + ], + [ + 364, + "44855254" + ], + [ + 365, + "162619462356610313" + ], + [ + 366, + "88351299" + ], + [ + 367, + "48271207" + ], + [ + 368, + "253.6135092068" + ], + [ + 369, + "862400558448" + ], + [ + 370, + "41791929448408" + ], + [ + 371, + "40.66368097" + ], + [ + 372, + "301450082318807027" + ], + [ + 373, + "727227472448913" + ], + [ + 374, + "334420941" + ], + [ + 375, + "7435327983715286168" + ], + [ + 376, + "973059630185670" + ], + [ + 377, + "732385277" + ], + [ + 378, + "147534623725724718" + ], + [ + 379, + "132314136838185" + ], + [ + 380, + "6.3202e25093" + ], + [ + 381, + "139602943319822" + ], + [ + 382, + "697003956" + ], + [ + 383, + "22173624649806" + ], + [ + 384, + "3354706415856332783" + ], + [ + 385, + "3776957309612153700" + ], + [ + 386, + "528755790" + ], + [ + 387, + "696067597313468" + ], + [ + 388, + "831907372805129931" + ], + [ + 389, + "2406376.3623" + ], + [ + 390, + "2919133642971" + ], + [ + 391, + "61029882288" + ], + [ + 392, + "3.1486734435" + ], + [ + 393, + "112398351350823112" + ], + [ + 394, + "3.2370342194" + ], + [ + 395, + "28.2453753155" + ], + [ + 396, + "173214653" + ], + [ + 397, + "141630459461893728" + ], + [ + 398, + "2010.59096" + ], + [ + 399, + "1508395636674243,6.5e27330467" + ], + [ + 400, + "438505383468410633" + ], + [ + 401, + "281632621" + ], + [ + 402, + "356019862" + ], + [ + 403, + "18224771" + ], + [ + 404, + "1199215615081353" + ], + [ + 405, + "237696125" + ], + [ + 406, + "36813.12757207" + ], + [ + 407, + "39782849136421" + ], + [ + 408, + "299742733" + ], + [ + 409, + "253223948" + ], + [ + 410, + "799999783589946560" + ], + [ + 411, + "9936352" + ], + [ + 412, + "38788800" + ], + [ + 413, + "3079418648040719" + ], + [ + 414, + "552506775824935461" + ], + [ + 415, + "55859742" + ], + [ + 416, + "898082747" + ], + [ + 417, + "446572970925740" + ], + [ + 418, + "1177163565297340320" + ], + [ + 419, + "998567458,1046245404,43363922" + ], + [ + 420, + "145159332" + ], + [ + 421, + "2304215802083466198" + ], + [ + 422, + "92060460" + ], + [ + 423, + "653972374" + ], + [ + 424, + "1059760019628" + ], + [ + 425, + "46479497324" + ], + [ + 426, + "31591886008" + ], + [ + 427, + "97138867" + ], + [ + 428, + "747215561862" + ], + [ + 429, + "98792821" + ], + [ + 430, + "5000624921.38" + ], + [ + 431, + "23.386029052" + ], + [ + 432, + "754862080" + ], + [ + 433, + "326624372659664" + ], + [ + 434, + "863253606" + ], + [ + 435, + "252541322550" + ], + [ + 436, + "0.5276662759" + ], + [ + 437, + "74204709657207" + ], + [ + 438, + "2046409616809" + ], + [ + 439, + "968697378" + ], + [ + 440, + "970746056" + ], + [ + 441, + "5000088.8395" + ], + [ + 442, + "1295552661530920149" + ], + [ + 443, + "2744233049300770" + ], + [ + 444, + "1.200856722e263" + ], + [ + 445, + "659104042" + ], + [ + 446, + "907803852" + ], + [ + 447, + "530553372" + ], + [ + 448, + "106467648" + ], + [ + 449, + "103.37870096" + ], + [ + 450, + "583333163984220940" + ], + [ + 451, + "153651073760956" + ], + [ + 452, + "345558983" + ], + [ + 453, + "104354107" + ], + [ + 454, + "5435004633092" + ], + [ + 455, + "450186511399999" + ], + [ + 456, + "333333208685971546" + ], + [ + 457, + "2647787126797397063" + ], + [ + 458, + "423341841" + ], + [ + 459, + "3996390106631" + ], + [ + 460, + "18.420738199" + ], + [ + 461, + "159820276" + ], + [ + 462, + "5.5350769703e1512" + ], + [ + 463, + "808981553" + ], + [ + 464, + "198775297232878" + ], + [ + 465, + "585965659" + ], + [ + 466, + "258381958195474745" + ], + [ + 467, + "775181359" + ], + [ + 468, + "852950321" + ], + [ + 469, + "0.56766764161831" + ], + [ + 470, + "147668794" + ], + [ + 471, + "1.895093981e31" + ], + [ + 472, + "73811586" + ], + [ + 473, + "35856681704365" + ], + [ + 474, + "9690646731515010" + ], + [ + 475, + "75780067" + ], + [ + 476, + "110242.87794" + ], + [ + 477, + "25044905874565165" + ], + [ + 478, + "59510340" + ], + [ + 479, + "191541795" + ], + [ + 480, + "turnthestarson" + ], + [ + 481, + "729.12106947" + ], + [ + 482, + "1400824879147" + ], + [ + 483, + "4.993401567e22" + ], + [ + 484, + "8907904768686152599" + ], + [ + 485, + "51281274340" + ], + [ + 486, + "11408450515" + ], + [ + 487, + "106650212746" + ], + [ + 488, + "216737278" + ], + [ + 489, + "1791954757162" + ], + [ + 490, + "777577686" + ], + [ + 491, + "194505988824000" + ], + [ + 492, + "242586962923928" + ], + [ + 493, + "6.818741802" + ], + [ + 494, + "2880067194446832666" + ], + [ + 495, + "789107601" + ], + [ + 496, + "2042473533769142717" + ], + [ + 497, + "684901360" + ], + [ + 498, + "472294837" + ], + [ + 499, + "0.8660312" + ], + [ + 500, + "35407281" + ], + [ + 501, + "197912312715" + ], + [ + 502, + "749485217" + ], + [ + 503, + "3.8694550145" + ], + [ + 504, + "694687" + ], + [ + 505, + "714591308667615832" + ], + [ + 506, + "18934502" + ], + [ + 507, + "316558047002627270" + ], + [ + 508, + "891874596" + ], + [ + 509, + "151725678" + ], + [ + 510, + "315306518862563689" + ], + [ + 511, + "935247012" + ], + [ + 512, + "50660591862310323" + ], + [ + 513, + "2925619196" + ], + [ + 514, + "8986.86698" + ], + [ + 515, + "2422639000800" + ], + [ + 516, + "939087315" + ], + [ + 517, + "581468882" + ], + [ + 518, + "100315739184392" + ], + [ + 519, + "804739330" + ], + [ + 520, + "238413705" + ], + [ + 521, + "44389811" + ], + [ + 522, + "96772715" + ], + [ + 523, + "37125450.44" + ], + [ + 524, + "2432925835413407847" + ], + [ + 525, + "44.69921807" + ], + [ + 526, + "49601160286750947" + ], + [ + 527, + "11.92412011" + ], + [ + 528, + "779027989" + ], + [ + 529, + "23624465" + ], + [ + 530, + "207366437157977206" + ], + [ + 531, + "4515432351156203105" + ], + [ + 532, + "827306.56" + ], + [ + 533, + "789453601" + ], + [ + 534, + "11726115562784664" + ], + [ + 535, + "611778217" + ], + [ + 536, + "3557005261906288" + ], + [ + 537, + "779429131" + ], + [ + 538, + "22472871503401097" + ], + [ + 539, + "426334056" + ], + [ + 540, + "500000000002845" + ], + [ + 541, + "4580726482872451" + ], + [ + 542, + "697586734240314852" + ], + [ + 543, + "199007746081234640" + ], + [ + 544, + "640432376" + ], + [ + 545, + "921107572" + ], + [ + 546, + "215656873" + ], + [ + 547, + "11730879.0023" + ], + [ + 548, + "12144044603581281" + ], + [ + 549, + "476001479068717" + ], + [ + 550, + "328104836" + ], + [ + 551, + "73597483551591773" + ], + [ + 552, + "326227335" + ], + [ + 553, + "57717170" + ], + [ + 554, + "89539872" + ], + [ + 555, + "208517717451208352" + ], + [ + 556, + "52126939292957" + ], + [ + 557, + "2699929328" + ], + [ + 558, + "226754889" + ], + [ + 559, + "684724920" + ], + [ + 560, + "994345168" + ], + [ + 561, + "452480999988235494" + ], + [ + 562, + "51208732914368" + ], + [ + 563, + "27186308211734760" + ], + [ + 564, + "12363.698850" + ], + [ + 565, + "2992480851924313898" + ], + [ + 566, + "329569369413585" + ], + [ + 567, + "75.44817535" + ], + [ + 568, + "4228020" + ], + [ + 569, + "21025060" + ], + [ + 570, + "271197444" + ], + [ + 571, + "30510390701978" + ], + [ + 572, + "19737656" + ], + [ + 573, + "1252.9809" + ], + [ + 574, + "5780447552057000454" + ], + [ + 575, + "0.000989640561" + ], + [ + 576, + "344457.5871" + ], + [ + 577, + "265695031399260211" + ], + [ + 578, + "9219696799346" + ], + [ + 579, + "3805524" + ], + [ + 580, + "2327213148095366" + ], + [ + 581, + "2227616372734" + ], + [ + 582, + "19903" + ], + [ + 583, + "1174137929000" + ], + [ + 584, + "32.83822408" + ], + [ + 585, + "17714439395932" + ], + [ + 586, + "82490213" + ], + [ + 587, + "2240" + ], + [ + 588, + "11651930052" + ], + [ + 589, + "131776959.25" + ], + [ + 590, + "834171904" + ], + [ + 591, + "526007984625966" + ], + [ + 592, + "13415DF2BE9C" + ], + [ + 593, + "96632320042.0" + ], + [ + 594, + "47067598" + ], + [ + 595, + "54.17529329" + ], + [ + 596, + "734582049" + ], + [ + 597, + "0.5001817828" + ], + [ + 598, + "543194779059" + ], + [ + 599, + "12395526079546335" + ], + [ + 600, + "2668608479740672" + ], + [ + 601, + "1617243" + ], + [ + 602, + "269496760" + ], + [ + 603, + "879476477" + ], + [ + 604, + "1398582231101" + ], + [ + 605, + "59992576" + ], + [ + 606, + "158452775" + ], + [ + 607, + "13.1265108586" + ], + [ + 608, + "439689828" + ], + [ + 609, + "172023848" + ], + [ + 610, + "319.30207833" + ], + [ + 611, + "49283233900" + ], + [ + 612, + "819963842" + ], + [ + 613, + "0.3916721504" + ], + [ + 614, + "130694090" + ], + [ + 615, + "108424772" + ], + [ + 616, + "310884668312456458" + ], + [ + 617, + "1001133757" + ], + [ + 618, + "634212216" + ], + [ + 619, + "857810883" + ], + [ + 620, + "1470337306" + ], + [ + 621, + "11429712" + ], + [ + 622, + "3010983666182123972" + ], + [ + 623, + "3679796" + ], + [ + 624, + "984524441" + ], + [ + 625, + "551614306" + ], + [ + 626, + "695577663" + ], + [ + 627, + "220196142" + ], + [ + 628, + "210286684" + ], + [ + 629, + "626616617" + ], + [ + 630, + "9669182880384" + ], + [ + 631, + "869588692" + ], + [ + 632, + "728378714" + ], + [ + 633, + "1.0012e-10" + ], + [ + 634, + "4019680944" + ], + [ + 635, + "689294705" + ], + [ + 636, + "888316" + ], + [ + 637, + "49000634845039" + ], + [ + 638, + "18423394" + ], + [ + 639, + "797866893" + ], + [ + 640, + "50.317928" + ], + [ + 641, + "793525366" + ], + [ + 642, + "631499044" + ], + [ + 643, + "968274154" + ], + [ + 644, + "20.11208767" + ], + [ + 645, + "48894.2174" + ], + [ + 646, + "845218467" + ], + [ + 647, + "563132994232918611" + ], + [ + 648, + "301483197" + ], + [ + 649, + "924668016" + ], + [ + 650, + "538319652" + ], + [ + 651, + "448233151" + ], + [ + 652, + "983924497" + ], + [ + 653, + "1130658687" + ], + [ + 654, + "815868280" + ], + [ + 655, + "2000008332" + ], + [ + 656, + "888873503555187" + ], + [ + 657, + "219493139" + ], + [ + 658, + "958280177" + ], + [ + 659, + "238518915714422000" + ], + [ + 660, + "474766783" + ], + [ + 661, + "646231.2177" + ], + [ + 662, + "860873428" + ], + [ + 663, + "1884138010064752" + ], + [ + 664, + "35295862" + ], + [ + 665, + "11541685709674" + ], + [ + 666, + "0.48023168" + ], + [ + 667, + "1.5276527928" + ], + [ + 668, + "2811077773" + ], + [ + 669, + "56342087360542122" + ], + [ + 670, + "551055065" + ], + [ + 671, + "946106780" + ], + [ + 672, + "91627537" + ], + [ + 673, + "700325380" + ], + [ + 674, + "416678753" + ], + [ + 675, + "416146418" + ], + [ + 676, + "3562668074339584" + ], + [ + 677, + "984183023" + ], + [ + 678, + "1986065" + ], + [ + 679, + "644997092988678" + ], + [ + 680, + "563917241" + ], + [ + 681, + "2611227421428" + ], + [ + 682, + "290872710" + ], + [ + 683, + "2.38955315e11" + ], + [ + 684, + "922058210" + ], + [ + 685, + "662878999" + ], + [ + 686, + "193060223" + ], + [ + 687, + "0.3285320869" + ], + [ + 688, + "110941813" + ], + [ + 689, + "0.56565454" + ], + [ + 690, + "415157690" + ], + [ + 691, + "11570761" + ], + [ + 692, + "842043391019219959" + ], + [ + 693, + "699161" + ], + [ + 694, + "1339784153569958487" + ], + [ + 695, + "0.1017786859" + ], + [ + 696, + "436944244" + ], + [ + 697, + "4343871.06" + ], + [ + 698, + "57808202" + ], + [ + 699, + "37010438774467572" + ], + [ + 700, + "1517926517777556" + ], + [ + 701, + "13.51099836" + ], + [ + 702, + "622305608172525546" + ], + [ + 703, + "843437991" + ], + [ + 704, + "501985601490518144" + ], + [ + 705, + "480440153" + ], + [ + 706, + "884837055" + ], + [ + 707, + "652907799" + ], + [ + 708, + "28874142998632109" + ], + [ + 709, + "773479144" + ], + [ + 710, + "1275000" + ], + [ + 711, + "541510990" + ], + [ + 712, + "413876461" + ], + [ + 713, + "788626351539895" + ], + [ + 714, + "2.452767775565e20" + ], + [ + 715, + "883188017" + ], + [ + 716, + "238948623" + ], + [ + 717, + "1603036763131" + ], + [ + 718, + "228579116" + ], + [ + 719, + "128088830547982" + ], + [ + 720, + "688081048" + ], + [ + 721, + "700792959" + ], + [ + 722, + "3.376792776502e132" + ], + [ + 723, + "1395793419248" + ], + [ + 724, + "18128250110" + ], + [ + 725, + "4598797036650685" + ] +] \ No newline at end of file diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py new file mode 100755 index 000000000..01d70721e --- /dev/null +++ b/project_euler/validate_solutions.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +import importlib.util +import json +import pathlib +from types import ModuleType +from typing import Generator + +import pytest + +PROJECT_EULER_DIR_PATH = pathlib.Path.cwd().joinpath("project_euler") +PROJECT_EULER_ANSWERS_PATH = PROJECT_EULER_DIR_PATH.joinpath( + "project_euler_answers.json" +) + +with open(PROJECT_EULER_ANSWERS_PATH) as file_handle: + PROBLEM_ANSWERS = json.load(file_handle) + +error_msgs = [] + + +def generate_solution_modules( + dir_path: pathlib.Path, +) -> Generator[ModuleType, None, None]: + # Iterating over every file or directory + for file_path in dir_path.iterdir(): + if file_path.suffix != ".py" or file_path.name.startswith(("_", "test")): + continue + # Importing the source file through the given path + # https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly + spec = importlib.util.spec_from_file_location(file_path.name, str(file_path)) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + yield module + + +@pytest.mark.parametrize("problem_number, expected", PROBLEM_ANSWERS) +def test_project_euler(subtests, problem_number: int, expected: str): + problem_dir = PROJECT_EULER_DIR_PATH.joinpath(f"problem_{problem_number:02}") + # Check if the problem directory exist. If not, then skip. + if problem_dir.is_dir(): + for solution_module in generate_solution_modules(problem_dir): + # All the tests in a loop is considered as one test by pytest so, use + # subtests to make sure all the subtests are considered as different. + with subtests.test( + msg=f"Problem {problem_number} tests", solution_module=solution_module + ): + try: + answer = str(solution_module.solution()) + assert answer == expected, f"Expected {expected} but got {answer}" + except (AssertionError, AttributeError, TypeError) as err: + error_msgs.append( + f"problem_{problem_number}/{solution_module.__name__}: {err}" + ) + raise # We still want pytest to know that this test failed + else: + pytest.skip(f"Solution {problem_number} does not exist yet.") + + +# Run this function at the end of all the tests +# https://stackoverflow.com/a/52873379 +@pytest.fixture(scope="session", autouse=True) +def custom_print_message(request): + def print_error_messages(): + if error_msgs: + print("\n" + "\n".join(error_msgs)) + + request.addfinalizer(print_error_messages)