From cc3442fefa26307d332db09d5435994e4f77c11d Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Fri, 30 Jun 2023 21:59:11 -0400 Subject: [PATCH] Update test coverage --- files/Problem11Grid.txt | 20 ++ files/Problem13Numbers.txt | 100 +++++++ files/Problem18Pyramid.txt | 15 ++ files/Problem67Pyramid.txt | 100 +++++++ files/Problem8Number.txt | 1 + .../project_euler/problems/Problem1.java | 6 +- .../project_euler/problems/Problem10.java | 6 +- .../project_euler/problems/Problem11.java | 121 ++++----- .../project_euler/problems/Problem12.java | 10 +- .../project_euler/problems/Problem13.java | 253 +++--------------- .../project_euler/problems/Problem14.java | 8 +- .../project_euler/problems/Problem15.java | 6 +- .../project_euler/problems/Problem16.java | 8 +- .../project_euler/problems/Problem17.java | 23 +- .../project_euler/problems/Problem18.java | 81 +++--- .../project_euler/problems/Problem19.java | 8 +- .../project_euler/problems/Problem2.java | 6 +- .../project_euler/problems/Problem20.java | 8 +- .../project_euler/problems/Problem21.java | 8 +- .../project_euler/problems/Problem22.java | 16 +- .../project_euler/problems/Problem23.java | 9 +- .../project_euler/problems/Problem24.java | 6 +- .../project_euler/problems/Problem25.java | 8 +- .../project_euler/problems/Problem26.java | 9 +- .../project_euler/problems/Problem27.java | 10 +- .../project_euler/problems/Problem28.java | 8 +- .../project_euler/problems/Problem29.java | 6 +- .../project_euler/problems/Problem3.java | 6 +- .../project_euler/problems/Problem30.java | 8 +- .../project_euler/problems/Problem31.java | 6 +- .../project_euler/problems/Problem32.java | 12 +- .../project_euler/problems/Problem33.java | 11 +- .../project_euler/problems/Problem34.java | 10 +- .../project_euler/problems/Problem35.java | 8 +- .../project_euler/problems/Problem36.java | 8 +- .../project_euler/problems/Problem37.java | 8 +- .../project_euler/problems/Problem38.java | 8 +- .../project_euler/problems/Problem39.java | 6 +- .../project_euler/problems/Problem4.java | 6 +- .../project_euler/problems/Problem40.java | 8 +- .../project_euler/problems/Problem41.java | 6 +- .../project_euler/problems/Problem42.java | 12 +- .../project_euler/problems/Problem43.java | 6 +- .../project_euler/problems/Problem44.java | 12 +- .../project_euler/problems/Problem45.java | 12 +- .../project_euler/problems/Problem46.java | 6 +- .../project_euler/problems/Problem47.java | 29 +- .../project_euler/problems/Problem48.java | 6 +- .../project_euler/problems/Problem49.java | 6 +- .../project_euler/problems/Problem5.java | 6 +- .../project_euler/problems/Problem50.java | 6 +- .../project_euler/problems/Problem6.java | 8 +- .../project_euler/problems/Problem67.java | 217 +-------------- .../project_euler/problems/Problem7.java | 6 +- .../project_euler/problems/Problem8.java | 66 ++--- .../project_euler/problems/Problem9.java | 16 +- .../project_euler/TestProblemSelection.java | 2 + .../project_euler/problems/TestProblem.java | 89 ++++++ .../project_euler/problems/TestProblem1.java | 18 +- .../project_euler/problems/TestProblem10.java | 18 +- .../project_euler/problems/TestProblem11.java | 52 +++- .../project_euler/problems/TestProblem12.java | 34 ++- .../project_euler/problems/TestProblem13.java | 48 +++- .../project_euler/problems/TestProblem14.java | 23 +- .../project_euler/problems/TestProblem15.java | 18 +- .../project_euler/problems/TestProblem16.java | 25 +- .../project_euler/problems/TestProblem17.java | 32 ++- .../project_euler/problems/TestProblem18.java | 88 +++++- .../project_euler/problems/TestProblem19.java | 18 +- .../project_euler/problems/TestProblem2.java | 18 +- .../project_euler/problems/TestProblem20.java | 26 +- .../project_euler/problems/TestProblem21.java | 27 +- .../project_euler/problems/TestProblem22.java | 56 +++- .../project_euler/problems/TestProblem23.java | 35 ++- .../project_euler/problems/TestProblem24.java | 18 +- .../project_euler/problems/TestProblem25.java | 32 ++- .../project_euler/problems/TestProblem26.java | 23 +- .../project_euler/problems/TestProblem27.java | 30 ++- .../project_euler/problems/TestProblem28.java | 27 +- .../project_euler/problems/TestProblem29.java | 24 +- .../project_euler/problems/TestProblem3.java | 26 +- .../project_euler/problems/TestProblem30.java | 24 +- .../project_euler/problems/TestProblem31.java | 18 +- .../project_euler/problems/TestProblem32.java | 41 ++- .../project_euler/problems/TestProblem33.java | 29 +- .../project_euler/problems/TestProblem34.java | 24 +- .../project_euler/problems/TestProblem35.java | 21 +- .../project_euler/problems/TestProblem36.java | 25 +- .../project_euler/problems/TestProblem37.java | 25 +- .../project_euler/problems/TestProblem38.java | 22 +- .../project_euler/problems/TestProblem39.java | 32 ++- .../project_euler/problems/TestProblem4.java | 21 +- .../project_euler/problems/TestProblem40.java | 19 +- .../project_euler/problems/TestProblem41.java | 17 +- .../project_euler/problems/TestProblem42.java | 47 +++- .../project_euler/problems/TestProblem43.java | 33 ++- .../project_euler/problems/TestProblem44.java | 30 ++- .../project_euler/problems/TestProblem45.java | 26 +- .../project_euler/problems/TestProblem46.java | 17 +- .../project_euler/problems/TestProblem47.java | 17 +- .../project_euler/problems/TestProblem48.java | 21 +- .../project_euler/problems/TestProblem49.java | 17 +- .../project_euler/problems/TestProblem5.java | 18 +- .../project_euler/problems/TestProblem50.java | 20 +- .../project_euler/problems/TestProblem6.java | 30 ++- .../project_euler/problems/TestProblem67.java | 59 +++- .../project_euler/problems/TestProblem7.java | 20 +- .../project_euler/problems/TestProblem8.java | 54 +++- .../project_euler/problems/TestProblem9.java | 41 ++- ...blemBaseTest.java => TestProblemBase.java} | 26 +- 110 files changed, 1828 insertions(+), 1158 deletions(-) create mode 100644 files/Problem11Grid.txt create mode 100644 files/Problem13Numbers.txt create mode 100644 files/Problem18Pyramid.txt create mode 100644 files/Problem67Pyramid.txt create mode 100644 files/Problem8Number.txt create mode 100644 src/test/java/com/mattrixwv/project_euler/problems/TestProblem.java rename src/test/java/com/mattrixwv/project_euler/problems/{ProblemBaseTest.java => TestProblemBase.java} (74%) diff --git a/files/Problem11Grid.txt b/files/Problem11Grid.txt new file mode 100644 index 0000000..1fc75c6 --- /dev/null +++ b/files/Problem11Grid.txt @@ -0,0 +1,20 @@ +08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 +49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 +81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 +52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 +22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 +24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 +32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 +67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21 +24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72 +21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95 +78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92 +16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57 +86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58 +19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40 +04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66 +88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69 +04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36 +20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16 +20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54 +01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48 \ No newline at end of file diff --git a/files/Problem13Numbers.txt b/files/Problem13Numbers.txt new file mode 100644 index 0000000..e3b3e9f --- /dev/null +++ b/files/Problem13Numbers.txt @@ -0,0 +1,100 @@ +37107287533902102798797998220837590246510135740250 +46376937677490009712648124896970078050417018260538 +74324986199524741059474233309513058123726617309629 +91942213363574161572522430563301811072406154908250 +23067588207539346171171980310421047513778063246676 +89261670696623633820136378418383684178734361726757 +28112879812849979408065481931592621691275889832738 +44274228917432520321923589422876796487670272189318 +47451445736001306439091167216856844588711603153276 +70386486105843025439939619828917593665686757934951 +62176457141856560629502157223196586755079324193331 +64906352462741904929101432445813822663347944758178 +92575867718337217661963751590579239728245598838407 +58203565325359399008402633568948830189458628227828 +80181199384826282014278194139940567587151170094390 +35398664372827112653829987240784473053190104293586 +86515506006295864861532075273371959191420517255829 +71693888707715466499115593487603532921714970056938 +54370070576826684624621495650076471787294438377604 +53282654108756828443191190634694037855217779295145 +36123272525000296071075082563815656710885258350721 +45876576172410976447339110607218265236877223636045 +17423706905851860660448207621209813287860733969412 +81142660418086830619328460811191061556940512689692 +51934325451728388641918047049293215058642563049483 +62467221648435076201727918039944693004732956340691 +15732444386908125794514089057706229429197107928209 +55037687525678773091862540744969844508330393682126 +18336384825330154686196124348767681297534375946515 +80386287592878490201521685554828717201219257766954 +78182833757993103614740356856449095527097864797581 +16726320100436897842553539920931837441497806860984 +48403098129077791799088218795327364475675590848030 +87086987551392711854517078544161852424320693150332 +59959406895756536782107074926966537676326235447210 +69793950679652694742597709739166693763042633987085 +41052684708299085211399427365734116182760315001271 +65378607361501080857009149939512557028198746004375 +35829035317434717326932123578154982629742552737307 +94953759765105305946966067683156574377167401875275 +88902802571733229619176668713819931811048770190271 +25267680276078003013678680992525463401061632866526 +36270218540497705585629946580636237993140746255962 +24074486908231174977792365466257246923322810917141 +91430288197103288597806669760892938638285025333403 +34413065578016127815921815005561868836468420090470 +23053081172816430487623791969842487255036638784583 +11487696932154902810424020138335124462181441773470 +63783299490636259666498587618221225225512486764533 +67720186971698544312419572409913959008952310058822 +95548255300263520781532296796249481641953868218774 +76085327132285723110424803456124867697064507995236 +37774242535411291684276865538926205024910326572967 +23701913275725675285653248258265463092207058596522 +29798860272258331913126375147341994889534765745501 +18495701454879288984856827726077713721403798879715 +38298203783031473527721580348144513491373226651381 +34829543829199918180278916522431027392251122869539 +40957953066405232632538044100059654939159879593635 +29746152185502371307642255121183693803580388584903 +41698116222072977186158236678424689157993532961922 +62467957194401269043877107275048102390895523597457 +23189706772547915061505504953922979530901129967519 +86188088225875314529584099251203829009407770775672 +11306739708304724483816533873502340845647058077308 +82959174767140363198008187129011875491310547126581 +97623331044818386269515456334926366572897563400500 +42846280183517070527831839425882145521227251250327 +55121603546981200581762165212827652751691296897789 +32238195734329339946437501907836945765883352399886 +75506164965184775180738168837861091527357929701337 +62177842752192623401942399639168044983993173312731 +32924185707147349566916674687634660915035914677504 +99518671430235219628894890102423325116913619626622 +73267460800591547471830798392868535206946944540724 +76841822524674417161514036427982273348055556214818 +97142617910342598647204516893989422179826088076852 +87783646182799346313767754307809363333018982642090 +10848802521674670883215120185883543223812876952786 +71329612474782464538636993009049310363619763878039 +62184073572399794223406235393808339651327408011116 +66627891981488087797941876876144230030984490851411 +60661826293682836764744779239180335110989069790714 +85786944089552990653640447425576083659976645795096 +66024396409905389607120198219976047599490197230297 +64913982680032973156037120041377903785566085089252 +16730939319872750275468906903707539413042652315011 +94809377245048795150954100921645863754710598436791 +78639167021187492431995700641917969777599028300699 +15368713711936614952811305876380278410754449733078 +40789923115535562561142322423255033685442488917353 +44889911501440648020369068063960672322193204149535 +41503128880339536053299340368006977710650566631954 +81234880673210146739058568557934581403627822703280 +82616570773948327592232845941706525094512325230608 +22918802058777319719839450180888072429661980811197 +77158542502016545090413245809786882778948721859617 +72107838435069186155435662884062257473692284509516 +20849603980134001723930671666823555245252804609722 +53503534226472524250874054075591789781264330331690 \ No newline at end of file diff --git a/files/Problem18Pyramid.txt b/files/Problem18Pyramid.txt new file mode 100644 index 0000000..bc0ed83 --- /dev/null +++ b/files/Problem18Pyramid.txt @@ -0,0 +1,15 @@ +75 +95 64 +17 47 82 +18 35 87 10 +20 04 82 47 65 +19 01 23 75 03 34 +88 02 77 73 07 63 67 +99 65 04 28 06 16 70 92 +41 41 26 56 83 40 80 70 33 +41 48 72 33 47 32 37 16 94 29 +53 71 44 65 25 43 91 52 97 51 14 +70 11 33 28 77 73 17 78 39 68 17 57 +91 71 52 38 17 14 91 43 58 50 27 29 48 +63 66 04 68 89 53 67 30 73 16 69 87 40 31 +04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 \ No newline at end of file diff --git a/files/Problem67Pyramid.txt b/files/Problem67Pyramid.txt new file mode 100644 index 0000000..e849e93 --- /dev/null +++ b/files/Problem67Pyramid.txt @@ -0,0 +1,100 @@ +59 +73 41 +52 40 09 +26 53 06 34 +10 51 87 86 81 +61 95 66 57 25 68 +90 81 80 38 92 67 73 +30 28 51 76 81 18 75 44 +84 14 95 87 62 81 17 78 58 +21 46 71 58 02 79 62 39 31 09 +56 34 35 53 78 31 81 18 90 93 15 +78 53 04 21 84 93 32 13 97 11 37 51 +45 03 81 79 05 18 78 86 13 30 63 99 95 +39 87 96 28 03 38 42 17 82 87 58 07 22 57 +06 17 51 17 07 93 09 07 75 97 95 78 87 08 53 +67 66 59 60 88 99 94 65 55 77 55 34 27 53 78 28 +76 40 41 04 87 16 09 42 75 69 23 97 30 60 10 79 87 +12 10 44 26 21 36 32 84 98 60 13 12 36 16 63 31 91 35 +70 39 06 05 55 27 38 48 28 22 34 35 62 62 15 14 94 89 86 +66 56 68 84 96 21 34 34 34 81 62 40 65 54 62 05 98 03 02 60 +38 89 46 37 99 54 34 53 36 14 70 26 02 90 45 13 31 61 83 73 47 +36 10 63 96 60 49 41 05 37 42 14 58 84 93 96 17 09 43 05 43 06 59 +66 57 87 57 61 28 37 51 84 73 79 15 39 95 88 87 43 39 11 86 77 74 18 +54 42 05 79 30 49 99 73 46 37 50 02 45 09 54 52 27 95 27 65 19 45 26 45 +71 39 17 78 76 29 52 90 18 99 78 19 35 62 71 19 23 65 93 85 49 33 75 09 02 +33 24 47 61 60 55 32 88 57 55 91 54 46 57 07 77 98 52 80 99 24 25 46 78 79 05 +92 09 13 55 10 67 26 78 76 82 63 49 51 31 24 68 05 57 07 54 69 21 67 43 17 63 12 +24 59 06 08 98 74 66 26 61 60 13 03 09 09 24 30 71 08 88 70 72 70 29 90 11 82 41 34 +66 82 67 04 36 60 92 77 91 85 62 49 59 61 30 90 29 94 26 41 89 04 53 22 83 41 09 74 90 +48 28 26 37 28 52 77 26 51 32 18 98 79 36 62 13 17 08 19 54 89 29 73 68 42 14 08 16 70 37 +37 60 69 70 72 71 09 59 13 60 38 13 57 36 09 30 43 89 30 39 15 02 44 73 05 73 26 63 56 86 12 +55 55 85 50 62 99 84 77 28 85 03 21 27 22 19 26 82 69 54 04 13 07 85 14 01 15 70 59 89 95 10 19 +04 09 31 92 91 38 92 86 98 75 21 05 64 42 62 84 36 20 73 42 21 23 22 51 51 79 25 45 85 53 03 43 22 +75 63 02 49 14 12 89 14 60 78 92 16 44 82 38 30 72 11 46 52 90 27 08 65 78 03 85 41 57 79 39 52 33 48 +78 27 56 56 39 13 19 43 86 72 58 95 39 07 04 34 21 98 39 15 39 84 89 69 84 46 37 57 59 35 59 50 26 15 93 +42 89 36 27 78 91 24 11 17 41 05 94 07 69 51 96 03 96 47 90 90 45 91 20 50 56 10 32 36 49 04 53 85 92 25 65 +52 09 61 30 61 97 66 21 96 92 98 90 06 34 96 60 32 69 68 33 75 84 18 31 71 50 84 63 03 03 19 11 28 42 75 45 45 +61 31 61 68 96 34 49 39 05 71 76 59 62 67 06 47 96 99 34 21 32 47 52 07 71 60 42 72 94 56 82 83 84 40 94 87 82 46 +01 20 60 14 17 38 26 78 66 81 45 95 18 51 98 81 48 16 53 88 37 52 69 95 72 93 22 34 98 20 54 27 73 61 56 63 60 34 63 +93 42 94 83 47 61 27 51 79 79 45 01 44 73 31 70 83 42 88 25 53 51 30 15 65 94 80 44 61 84 12 77 02 62 02 65 94 42 14 94 +32 73 09 67 68 29 74 98 10 19 85 48 38 31 85 67 53 93 93 77 47 67 39 72 94 53 18 43 77 40 78 32 29 59 24 06 02 83 50 60 66 +32 01 44 30 16 51 15 81 98 15 10 62 86 79 50 62 45 60 70 38 31 85 65 61 64 06 69 84 14 22 56 43 09 48 66 69 83 91 60 40 36 61 +92 48 22 99 15 95 64 43 01 16 94 02 99 19 17 69 11 58 97 56 89 31 77 45 67 96 12 73 08 20 36 47 81 44 50 64 68 85 40 81 85 52 09 +91 35 92 45 32 84 62 15 19 64 21 66 06 01 52 80 62 59 12 25 88 28 91 50 40 16 22 99 92 79 87 51 21 77 74 77 07 42 38 42 74 83 02 05 +46 19 77 66 24 18 05 32 02 84 31 99 92 58 96 72 91 36 62 99 55 29 53 42 12 37 26 58 89 50 66 19 82 75 12 48 24 87 91 85 02 07 03 76 86 +99 98 84 93 07 17 33 61 92 20 66 60 24 66 40 30 67 05 37 29 24 96 03 27 70 62 13 04 45 47 59 88 43 20 66 15 46 92 30 04 71 66 78 70 53 99 +67 60 38 06 88 04 17 72 10 99 71 07 42 25 54 05 26 64 91 50 45 71 06 30 67 48 69 82 08 56 80 67 18 46 66 63 01 20 08 80 47 07 91 16 03 79 87 +18 54 78 49 80 48 77 40 68 23 60 88 58 80 33 57 11 69 55 53 64 02 94 49 60 92 16 35 81 21 82 96 25 24 96 18 02 05 49 03 50 77 06 32 84 27 18 38 +68 01 50 04 03 21 42 94 53 24 89 05 92 26 52 36 68 11 85 01 04 42 02 45 15 06 50 04 53 73 25 74 81 88 98 21 67 84 79 97 99 20 95 04 40 46 02 58 87 +94 10 02 78 88 52 21 03 88 60 06 53 49 71 20 91 12 65 07 49 21 22 11 41 58 99 36 16 09 48 17 24 52 36 23 15 72 16 84 56 02 99 43 76 81 71 29 39 49 17 +64 39 59 84 86 16 17 66 03 09 43 06 64 18 63 29 68 06 23 07 87 14 26 35 17 12 98 41 53 64 78 18 98 27 28 84 80 67 75 62 10 11 76 90 54 10 05 54 41 39 66 +43 83 18 37 32 31 52 29 95 47 08 76 35 11 04 53 35 43 34 10 52 57 12 36 20 39 40 55 78 44 07 31 38 26 08 15 56 88 86 01 52 62 10 24 32 05 60 65 53 28 57 99 +03 50 03 52 07 73 49 92 66 80 01 46 08 67 25 36 73 93 07 42 25 53 13 96 76 83 87 90 54 89 78 22 78 91 73 51 69 09 79 94 83 53 09 40 69 62 10 79 49 47 03 81 30 +71 54 73 33 51 76 59 54 79 37 56 45 84 17 62 21 98 69 41 95 65 24 39 37 62 03 24 48 54 64 46 82 71 78 33 67 09 16 96 68 52 74 79 68 32 21 13 78 96 60 09 69 20 36 +73 26 21 44 46 38 17 83 65 98 07 23 52 46 61 97 33 13 60 31 70 15 36 77 31 58 56 93 75 68 21 36 69 53 90 75 25 82 39 50 65 94 29 30 11 33 11 13 96 02 56 47 07 49 02 +76 46 73 30 10 20 60 70 14 56 34 26 37 39 48 24 55 76 84 91 39 86 95 61 50 14 53 93 64 67 37 31 10 84 42 70 48 20 10 72 60 61 84 79 69 65 99 73 89 25 85 48 92 56 97 16 +03 14 80 27 22 30 44 27 67 75 79 32 51 54 81 29 65 14 19 04 13 82 04 91 43 40 12 52 29 99 07 76 60 25 01 07 61 71 37 92 40 47 99 66 57 01 43 44 22 40 53 53 09 69 26 81 07 +49 80 56 90 93 87 47 13 75 28 87 23 72 79 32 18 27 20 28 10 37 59 21 18 70 04 79 96 03 31 45 71 81 06 14 18 17 05 31 50 92 79 23 47 09 39 47 91 43 54 69 47 42 95 62 46 32 85 +37 18 62 85 87 28 64 05 77 51 47 26 30 65 05 70 65 75 59 80 42 52 25 20 44 10 92 17 71 95 52 14 77 13 24 55 11 65 26 91 01 30 63 15 49 48 41 17 67 47 03 68 20 90 98 32 04 40 68 +90 51 58 60 06 55 23 68 05 19 76 94 82 36 96 43 38 90 87 28 33 83 05 17 70 83 96 93 06 04 78 47 80 06 23 84 75 23 87 72 99 14 50 98 92 38 90 64 61 58 76 94 36 66 87 80 51 35 61 38 +57 95 64 06 53 36 82 51 40 33 47 14 07 98 78 65 39 58 53 06 50 53 04 69 40 68 36 69 75 78 75 60 03 32 39 24 74 47 26 90 13 40 44 71 90 76 51 24 36 50 25 45 70 80 61 80 61 43 90 64 11 +18 29 86 56 68 42 79 10 42 44 30 12 96 18 23 18 52 59 02 99 67 46 60 86 43 38 55 17 44 93 42 21 55 14 47 34 55 16 49 24 23 29 96 51 55 10 46 53 27 92 27 46 63 57 30 65 43 27 21 20 24 83 +81 72 93 19 69 52 48 01 13 83 92 69 20 48 69 59 20 62 05 42 28 89 90 99 32 72 84 17 08 87 36 03 60 31 36 36 81 26 97 36 48 54 56 56 27 16 91 08 23 11 87 99 33 47 02 14 44 73 70 99 43 35 33 +90 56 61 86 56 12 70 59 63 32 01 15 81 47 71 76 95 32 65 80 54 70 34 51 40 45 33 04 64 55 78 68 88 47 31 47 68 87 03 84 23 44 89 72 35 08 31 76 63 26 90 85 96 67 65 91 19 14 17 86 04 71 32 95 +37 13 04 22 64 37 37 28 56 62 86 33 07 37 10 44 52 82 52 06 19 52 57 75 90 26 91 24 06 21 14 67 76 30 46 14 35 89 89 41 03 64 56 97 87 63 22 34 03 79 17 45 11 53 25 56 96 61 23 18 63 31 37 37 47 +77 23 26 70 72 76 77 04 28 64 71 69 14 85 96 54 95 48 06 62 99 83 86 77 97 75 71 66 30 19 57 90 33 01 60 61 14 12 90 99 32 77 56 41 18 14 87 49 10 14 90 64 18 50 21 74 14 16 88 05 45 73 82 47 74 44 +22 97 41 13 34 31 54 61 56 94 03 24 59 27 98 77 04 09 37 40 12 26 87 09 71 70 07 18 64 57 80 21 12 71 83 94 60 39 73 79 73 19 97 32 64 29 41 07 48 84 85 67 12 74 95 20 24 52 41 67 56 61 29 93 35 72 69 +72 23 63 66 01 11 07 30 52 56 95 16 65 26 83 90 50 74 60 18 16 48 43 77 37 11 99 98 30 94 91 26 62 73 45 12 87 73 47 27 01 88 66 99 21 41 95 80 02 53 23 32 61 48 32 43 43 83 14 66 95 91 19 81 80 67 25 88 +08 62 32 18 92 14 83 71 37 96 11 83 39 99 05 16 23 27 10 67 02 25 44 11 55 31 46 64 41 56 44 74 26 81 51 31 45 85 87 09 81 95 22 28 76 69 46 48 64 87 67 76 27 89 31 11 74 16 62 03 60 94 42 47 09 34 94 93 72 +56 18 90 18 42 17 42 32 14 86 06 53 33 95 99 35 29 15 44 20 49 59 25 54 34 59 84 21 23 54 35 90 78 16 93 13 37 88 54 19 86 67 68 55 66 84 65 42 98 37 87 56 33 28 58 38 28 38 66 27 52 21 81 15 08 22 97 32 85 27 +91 53 40 28 13 34 91 25 01 63 50 37 22 49 71 58 32 28 30 18 68 94 23 83 63 62 94 76 80 41 90 22 82 52 29 12 18 56 10 08 35 14 37 57 23 65 67 40 72 39 93 39 70 89 40 34 07 46 94 22 20 05 53 64 56 30 05 56 61 88 27 +23 95 11 12 37 69 68 24 66 10 87 70 43 50 75 07 62 41 83 58 95 93 89 79 45 39 02 22 05 22 95 43 62 11 68 29 17 40 26 44 25 71 87 16 70 85 19 25 59 94 90 41 41 80 61 70 55 60 84 33 95 76 42 63 15 09 03 40 38 12 03 32 +09 84 56 80 61 55 85 97 16 94 82 94 98 57 84 30 84 48 93 90 71 05 95 90 73 17 30 98 40 64 65 89 07 79 09 19 56 36 42 30 23 69 73 72 07 05 27 61 24 31 43 48 71 84 21 28 26 65 65 59 65 74 77 20 10 81 61 84 95 08 52 23 70 +47 81 28 09 98 51 67 64 35 51 59 36 92 82 77 65 80 24 72 53 22 07 27 10 21 28 30 22 48 82 80 48 56 20 14 43 18 25 50 95 90 31 77 08 09 48 44 80 90 22 93 45 82 17 13 96 25 26 08 73 34 99 06 49 24 06 83 51 40 14 15 10 25 01 +54 25 10 81 30 64 24 74 75 80 36 75 82 60 22 69 72 91 45 67 03 62 79 54 89 74 44 83 64 96 66 73 44 30 74 50 37 05 09 97 70 01 60 46 37 91 39 75 75 18 58 52 72 78 51 81 86 52 08 97 01 46 43 66 98 62 81 18 70 93 73 08 32 46 34 +96 80 82 07 59 71 92 53 19 20 88 66 03 26 26 10 24 27 50 82 94 73 63 08 51 33 22 45 19 13 58 33 90 15 22 50 36 13 55 06 35 47 82 52 33 61 36 27 28 46 98 14 73 20 73 32 16 26 80 53 47 66 76 38 94 45 02 01 22 52 47 96 64 58 52 39 +88 46 23 39 74 63 81 64 20 90 33 33 76 55 58 26 10 46 42 26 74 74 12 83 32 43 09 02 73 55 86 54 85 34 28 23 29 79 91 62 47 41 82 87 99 22 48 90 20 05 96 75 95 04 43 28 81 39 81 01 28 42 78 25 39 77 90 57 58 98 17 36 73 22 63 74 51 +29 39 74 94 95 78 64 24 38 86 63 87 93 06 70 92 22 16 80 64 29 52 20 27 23 50 14 13 87 15 72 96 81 22 08 49 72 30 70 24 79 31 16 64 59 21 89 34 96 91 48 76 43 53 88 01 57 80 23 81 90 79 58 01 80 87 17 99 86 90 72 63 32 69 14 28 88 69 +37 17 71 95 56 93 71 35 43 45 04 98 92 94 84 96 11 30 31 27 31 60 92 03 48 05 98 91 86 94 35 90 90 08 48 19 33 28 68 37 59 26 65 96 50 68 22 07 09 49 34 31 77 49 43 06 75 17 81 87 61 79 52 26 27 72 29 50 07 98 86 01 17 10 46 64 24 18 56 +51 30 25 94 88 85 79 91 40 33 63 84 49 67 98 92 15 26 75 19 82 05 18 78 65 93 61 48 91 43 59 41 70 51 22 15 92 81 67 91 46 98 11 11 65 31 66 10 98 65 83 21 05 56 05 98 73 67 46 74 69 34 08 30 05 52 07 98 32 95 30 94 65 50 24 63 28 81 99 57 +19 23 61 36 09 89 71 98 65 17 30 29 89 26 79 74 94 11 44 48 97 54 81 55 39 66 69 45 28 47 13 86 15 76 74 70 84 32 36 33 79 20 78 14 41 47 89 28 81 05 99 66 81 86 38 26 06 25 13 60 54 55 23 53 27 05 89 25 23 11 13 54 59 54 56 34 16 24 53 44 06 +13 40 57 72 21 15 60 08 04 19 11 98 34 45 09 97 86 71 03 15 56 19 15 44 97 31 90 04 87 87 76 08 12 30 24 62 84 28 12 85 82 53 99 52 13 94 06 65 97 86 09 50 94 68 69 74 30 67 87 94 63 07 78 27 80 36 69 41 06 92 32 78 37 82 30 05 18 87 99 72 19 99 +44 20 55 77 69 91 27 31 28 81 80 27 02 07 97 23 95 98 12 25 75 29 47 71 07 47 78 39 41 59 27 76 13 15 66 61 68 35 69 86 16 53 67 63 99 85 41 56 08 28 33 40 94 76 90 85 31 70 24 65 84 65 99 82 19 25 54 37 21 46 33 02 52 99 51 33 26 04 87 02 08 18 96 +54 42 61 45 91 06 64 79 80 82 32 16 83 63 42 49 19 78 65 97 40 42 14 61 49 34 04 18 25 98 59 30 82 72 26 88 54 36 21 75 03 88 99 53 46 51 55 78 22 94 34 40 68 87 84 25 30 76 25 08 92 84 42 61 40 38 09 99 40 23 29 39 46 55 10 90 35 84 56 70 63 23 91 39 +52 92 03 71 89 07 09 37 68 66 58 20 44 92 51 56 13 71 79 99 26 37 02 06 16 67 36 52 58 16 79 73 56 60 59 27 44 77 94 82 20 50 98 33 09 87 94 37 40 83 64 83 58 85 17 76 53 02 83 52 22 27 39 20 48 92 45 21 09 42 24 23 12 37 52 28 50 78 79 20 86 62 73 20 59 +54 96 80 15 91 90 99 70 10 09 58 90 93 50 81 99 54 38 36 10 30 11 35 84 16 45 82 18 11 97 36 43 96 79 97 65 40 48 23 19 17 31 64 52 65 65 37 32 65 76 99 79 34 65 79 27 55 33 03 01 33 27 61 28 66 08 04 70 49 46 48 83 01 45 19 96 13 81 14 21 31 79 93 85 50 05 +92 92 48 84 59 98 31 53 23 27 15 22 79 95 24 76 05 79 16 93 97 89 38 89 42 83 02 88 94 95 82 21 01 97 48 39 31 78 09 65 50 56 97 61 01 07 65 27 21 23 14 15 80 97 44 78 49 35 33 45 81 74 34 05 31 57 09 38 94 07 69 54 69 32 65 68 46 68 78 90 24 28 49 51 45 86 35 +41 63 89 76 87 31 86 09 46 14 87 82 22 29 47 16 13 10 70 72 82 95 48 64 58 43 13 75 42 69 21 12 67 13 64 85 58 23 98 09 37 76 05 22 31 12 66 50 29 99 86 72 45 25 10 28 19 06 90 43 29 31 67 79 46 25 74 14 97 35 76 37 65 46 23 82 06 22 30 76 93 66 94 17 96 13 20 72 +63 40 78 08 52 09 90 41 70 28 36 14 46 44 85 96 24 52 58 15 87 37 05 98 99 39 13 61 76 38 44 99 83 74 90 22 53 80 56 98 30 51 63 39 44 30 91 91 04 22 27 73 17 35 53 18 35 45 54 56 27 78 48 13 69 36 44 38 71 25 30 56 15 22 73 43 32 69 59 25 93 83 45 11 34 94 44 39 92 +12 36 56 88 13 96 16 12 55 54 11 47 19 78 17 17 68 81 77 51 42 55 99 85 66 27 81 79 93 42 65 61 69 74 14 01 18 56 12 01 58 37 91 22 42 66 83 25 19 04 96 41 25 45 18 69 96 88 36 93 10 12 98 32 44 83 83 04 72 91 04 27 73 07 34 37 71 60 59 31 01 54 54 44 96 93 83 36 04 45 +30 18 22 20 42 96 65 79 17 41 55 69 94 81 29 80 91 31 85 25 47 26 43 49 02 99 34 67 99 76 16 14 15 93 08 32 99 44 61 77 67 50 43 55 87 55 53 72 17 46 62 25 50 99 73 05 93 48 17 31 70 80 59 09 44 59 45 13 74 66 58 94 87 73 16 14 85 38 74 99 64 23 79 28 71 42 20 37 82 31 23 +51 96 39 65 46 71 56 13 29 68 53 86 45 33 51 49 12 91 21 21 76 85 02 17 98 15 46 12 60 21 88 30 92 83 44 59 42 50 27 88 46 86 94 73 45 54 23 24 14 10 94 21 20 34 23 51 04 83 99 75 90 63 60 16 22 33 83 70 11 32 10 50 29 30 83 46 11 05 31 17 86 42 49 01 44 63 28 60 07 78 95 40 +44 61 89 59 04 49 51 27 69 71 46 76 44 04 09 34 56 39 15 06 94 91 75 90 65 27 56 23 74 06 23 33 36 69 14 39 05 34 35 57 33 22 76 46 56 10 61 65 98 09 16 69 04 62 65 18 99 76 49 18 72 66 73 83 82 40 76 31 89 91 27 88 17 35 41 35 32 51 32 67 52 68 74 85 80 57 07 11 62 66 47 22 67 +65 37 19 97 26 17 16 24 24 17 50 37 64 82 24 36 32 11 68 34 69 31 32 89 79 93 96 68 49 90 14 23 04 04 67 99 81 74 70 74 36 96 68 09 64 39 88 35 54 89 96 58 66 27 88 97 32 14 06 35 78 20 71 06 85 66 57 02 58 91 72 05 29 56 73 48 86 52 09 93 22 57 79 42 12 01 31 68 17 59 63 76 07 77 +73 81 14 13 17 20 11 09 01 83 08 85 91 70 84 63 62 77 37 07 47 01 59 95 39 69 39 21 99 09 87 02 97 16 92 36 74 71 90 66 33 73 73 75 52 91 11 12 26 53 05 26 26 48 61 50 90 65 01 87 42 47 74 35 22 73 24 26 56 70 52 05 48 41 31 18 83 27 21 39 80 85 26 08 44 02 71 07 63 22 05 52 19 08 20 +17 25 21 11 72 93 33 49 64 23 53 82 03 13 91 65 85 02 40 05 42 31 77 42 05 36 06 54 04 58 07 76 87 83 25 57 66 12 74 33 85 37 74 32 20 69 03 97 91 68 82 44 19 14 89 28 85 85 80 53 34 87 58 98 88 78 48 65 98 40 11 57 10 67 70 81 60 79 74 72 97 59 79 47 30 20 54 80 89 91 14 05 33 36 79 39 +60 85 59 39 60 07 57 76 77 92 06 35 15 72 23 41 45 52 95 18 64 79 86 53 56 31 69 11 91 31 84 50 44 82 22 81 41 40 30 42 30 91 48 94 74 76 64 58 74 25 96 57 14 19 03 99 28 83 15 75 99 01 89 85 79 50 03 95 32 67 44 08 07 41 62 64 29 20 14 76 26 55 48 71 69 66 19 72 44 25 14 01 48 74 12 98 07 +64 66 84 24 18 16 27 48 20 14 47 69 30 86 48 40 23 16 61 21 51 50 26 47 35 33 91 28 78 64 43 68 04 79 51 08 19 60 52 95 06 68 46 86 35 97 27 58 04 65 30 58 99 12 12 75 91 39 50 31 42 64 70 04 46 07 98 73 98 93 37 89 77 91 64 71 64 65 66 21 78 62 81 74 42 20 83 70 73 95 78 45 92 27 34 53 71 15 +30 11 85 31 34 71 13 48 05 14 44 03 19 67 23 73 19 57 06 90 94 72 57 69 81 62 59 68 88 57 55 69 49 13 07 87 97 80 89 05 71 05 05 26 38 40 16 62 45 99 18 38 98 24 21 26 62 74 69 04 85 57 77 35 58 67 91 79 79 57 86 28 66 34 72 51 76 78 36 95 63 90 08 78 47 63 45 31 22 70 52 48 79 94 15 77 61 67 68 +23 33 44 81 80 92 93 75 94 88 23 61 39 76 22 03 28 94 32 06 49 65 41 34 18 23 08 47 62 60 03 63 33 13 80 52 31 54 73 43 70 26 16 69 57 87 83 31 03 93 70 81 47 95 77 44 29 68 39 51 56 59 63 07 25 70 07 77 43 53 64 03 94 42 95 39 18 01 66 21 16 97 20 50 90 16 70 10 95 69 29 06 25 61 41 26 15 59 63 35 \ No newline at end of file diff --git a/files/Problem8Number.txt b/files/Problem8Number.txt new file mode 100644 index 0000000..c129f96 --- /dev/null +++ b/files/Problem8Number.txt @@ -0,0 +1 @@ +7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 \ No newline at end of file diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem1.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem1.java index aeb6ca6..ef7a08d 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem1.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem1.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem1.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the sum of all the multiples of 3 or 5 that are less than 1000 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2021 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -28,7 +28,7 @@ public class Problem1 extends Problem{ //Static variables private static final int TOP_NUM = 999; //The largest number to be checked //Instance variables - private int fullSum; //The sum of all the numbers + protected int fullSum; //The sum of all the numbers //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem10.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem10.java index cfff504..6511f1b 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem10.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem10.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem10.java //Matthew Ellison // Created: 03-03-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the sum of all the primes below two million //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2021 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,7 +32,7 @@ public class Problem10 extends Problem{ //Static variables private static final long GOAL_NUMBER = 2000000L - 1L; //The largest number to check for primes //Instance variables - private long sum; //The sum of all of the prime numbers + protected long sum; //The sum of all of the prime numbers //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem11.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem11.java index dd5118e..26b443d 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem11.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem11.java @@ -1,33 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem11.java //Matthew Ellison // Created: 03-03-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid? -/* -08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 -49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 -81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 -52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 -22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 -24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 -32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 -67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21 -24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72 -21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95 -78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92 -16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57 -86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58 -19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40 -04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66 -88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69 -04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36 -20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16 -20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54 -01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48 -*/ //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -45,6 +23,10 @@ package com.mattrixwv.project_euler.problems; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.List; @@ -55,28 +37,10 @@ public class Problem11 extends Problem{ //Variables //Static variables //This is the grid of numbers that we will be working with - private static final Integer[][] grid = {{ 8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8}, - {49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0}, - {81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65}, - {52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91}, - {22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80}, - {24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50}, - {32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70}, - {67, 26, 20, 68, 2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21}, - {24, 55, 58, 5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72}, - {21, 36, 23, 9, 75, 0, 76, 44, 20, 45, 35, 14, 0, 61, 33, 97, 34, 31, 33, 95}, - {78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 3, 80, 4, 62, 16, 14, 9, 53, 56, 92}, - {16, 39, 5, 42, 96, 35, 31, 47, 55, 58, 88, 24, 0, 17, 54, 24, 36, 29, 85, 57}, - {86, 56, 0, 48, 35, 71, 89, 7, 5, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58}, - {19, 80, 81, 68, 5, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 4, 89, 55, 40}, - { 4, 52, 8, 83, 97, 35, 99, 16, 7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66}, - {88, 36, 68, 87, 57, 62, 20, 72, 3, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69}, - { 4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36}, - {20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16}, - {20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54}, - { 1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48}}; + protected static String FILE_NAME = "files/Problem11Grid.txt"; + protected static ArrayList> grid; //Instance variables - private ArrayList greatestProduct; //Holds the largest product we have found so far + protected List greatestProduct; //Holds the largest product we have found so far //Functions //Constructor @@ -85,6 +49,32 @@ public class Problem11 extends Problem{ greatestProduct = new ArrayList<>(); } //Operational functions + //Read numbers from file into grid + private void readFile(){ + if(grid != null){ + return; + } + File file = new File(FILE_NAME); + if(file.exists()){ + try{ + List lines = Files.readAllLines(file.toPath()); + grid = new ArrayList<>(); + for(String line : lines){ + ArrayList row = new ArrayList<>(); + for(String num : line.split(" ")){ + row.add(Integer.parseInt(num)); + } + grid.add(row); + } + } + catch(IOException error){ + throw new InvalidParameterException("Error reading file", error); + } + } + else{ + throw new InvalidParameterException("Error opening file"); + } + } //Solve the problem @Override public void solve(){ @@ -102,13 +92,16 @@ public class Problem11 extends Problem{ currentProduct.add(0); } + //Read the file into the number + readFile(); + //Start the timer timer.start(); //Loop through every row and column - for(int row = 0;row < grid.length;++row){ - for(int col = 0;col < grid[row].length;++col){ + for(int row = 0;row < grid.size();++row){ + for(int col = 0;col < grid.get(row).size();++col){ //Directional booleans to show whether you can move a certain direction boolean left = false; boolean right = false; @@ -118,7 +111,7 @@ public class Problem11 extends Problem{ if((col - 3) >= 1){ left = true; } - if((col + 3) < grid[row].length){ + if((col + 3) < grid.get(row).size()){ right = true; } if((row + 3) < 20){ @@ -155,10 +148,10 @@ public class Problem11 extends Problem{ //Check to the right of the current location private void checkRight(ArrayList currentProduct, int row, int col){ //Fill the product - currentProduct.set(0, grid[row][col]); - currentProduct.set(1, grid[row][col + 1]); - currentProduct.set(2, grid[row][col + 2]); - currentProduct.set(3, grid[row][col + 3]); + currentProduct.set(0, grid.get(row).get(col)); + currentProduct.set(1, grid.get(row).get(col + 1)); + currentProduct.set(2, grid.get(row).get(col + 2)); + currentProduct.set(3, grid.get(row).get(col + 3)); //If the current number's product is greater than the greatest product replace it if(ArrayAlgorithms.getProd(currentProduct) > ArrayAlgorithms.getProd(greatestProduct)){ @@ -171,10 +164,10 @@ public class Problem11 extends Problem{ //Check below the current location private void checkDown(ArrayList currentProduct, int row, int col){ //Fill the product - currentProduct.set(0, grid[row][col]); - currentProduct.set(1, grid[row + 1][col]); - currentProduct.set(2, grid[row + 2][col]); - currentProduct.set(3, grid[row + 3][col]); + currentProduct.set(0, grid.get(row).get(col)); + currentProduct.set(1, grid.get(row + 1).get(col)); + currentProduct.set(2, grid.get(row + 2).get(col)); + currentProduct.set(3, grid.get(row + 3).get(col)); //If the current number's product is greater than the greatest product replace it if(ArrayAlgorithms.getProd(currentProduct) > ArrayAlgorithms.getProd(greatestProduct)){ @@ -187,10 +180,10 @@ public class Problem11 extends Problem{ //Check the left-down diagonal from the current location private void checkLeftDown(ArrayList currentProduct, int row, int col){ //Fill the product - currentProduct.set(0, grid[row][col]); - currentProduct.set(1, grid[row + 1][col - 1]); - currentProduct.set(2, grid[row + 2][col - 2]); - currentProduct.set(3, grid[row + 3][col - 3]); + currentProduct.set(0, grid.get(row).get(col)); + currentProduct.set(1, grid.get(row + 1).get(col - 1)); + currentProduct.set(2, grid.get(row + 2).get(col - 2)); + currentProduct.set(3, grid.get(row + 3).get(col - 3)); //If the current number's product is greater than the greatest product replace it if(ArrayAlgorithms.getProd(currentProduct) > ArrayAlgorithms.getProd(greatestProduct)){ @@ -203,10 +196,10 @@ public class Problem11 extends Problem{ //Check the right-down diagonal from the current location private void checkRightDown(ArrayList currentProduct, int row, int col){ //Fill the product - currentProduct.set(0, grid[row][col]); - currentProduct.set(1, grid[row + 1][col + 1]); - currentProduct.set(2, grid[row + 2][col + 2]); - currentProduct.set(3, grid[row + 3][col + 3]); + currentProduct.set(0, grid.get(row).get(col)); + currentProduct.set(1, grid.get(row + 1).get(col + 1)); + currentProduct.set(1, grid.get(row + 2).get(col + 2)); + currentProduct.set(1, grid.get(row + 3).get(col + 3)); //If the current number's product is greater than the greatest product replace it if(ArrayAlgorithms.getProd(currentProduct) > ArrayAlgorithms.getProd(greatestProduct)){ diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem12.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem12.java index 42d2420..b936c5f 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem12.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem12.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem12.java //Matthew Ellison // Created: 03-04-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the value of the first triangle number to have over five hundred divisors? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,9 +34,9 @@ public class Problem12 extends Problem{ //Static variables private static final Long GOAL_DIVISORS = 500L; //The minimum number of divisors that you want //Instance variables - private long sum; //The sum of the numbers up to counter - private long counter; //The next number to be added to sum - private List divisors; //Holds the divisors of the triangular number sum + protected long sum; //The sum of the numbers up to counter + protected long counter; //The next number to be added to sum + protected List divisors; //Holds the divisors of the triangular number sum //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem13.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem13.java index e21954b..723b436 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem13.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem13.java @@ -1,113 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem13.java //Matthew Ellison // Created: 03-04-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Work out the first ten digits of the sum of the following one-hundred 50-digit numbers -/* -37107287533902102798797998220837590246510135740250 -46376937677490009712648124896970078050417018260538 -74324986199524741059474233309513058123726617309629 -91942213363574161572522430563301811072406154908250 -23067588207539346171171980310421047513778063246676 -89261670696623633820136378418383684178734361726757 -28112879812849979408065481931592621691275889832738 -44274228917432520321923589422876796487670272189318 -47451445736001306439091167216856844588711603153276 -70386486105843025439939619828917593665686757934951 -62176457141856560629502157223196586755079324193331 -64906352462741904929101432445813822663347944758178 -92575867718337217661963751590579239728245598838407 -58203565325359399008402633568948830189458628227828 -80181199384826282014278194139940567587151170094390 -35398664372827112653829987240784473053190104293586 -86515506006295864861532075273371959191420517255829 -71693888707715466499115593487603532921714970056938 -54370070576826684624621495650076471787294438377604 -53282654108756828443191190634694037855217779295145 -36123272525000296071075082563815656710885258350721 -45876576172410976447339110607218265236877223636045 -17423706905851860660448207621209813287860733969412 -81142660418086830619328460811191061556940512689692 -51934325451728388641918047049293215058642563049483 -62467221648435076201727918039944693004732956340691 -15732444386908125794514089057706229429197107928209 -55037687525678773091862540744969844508330393682126 -18336384825330154686196124348767681297534375946515 -80386287592878490201521685554828717201219257766954 -78182833757993103614740356856449095527097864797581 -16726320100436897842553539920931837441497806860984 -48403098129077791799088218795327364475675590848030 -87086987551392711854517078544161852424320693150332 -59959406895756536782107074926966537676326235447210 -69793950679652694742597709739166693763042633987085 -41052684708299085211399427365734116182760315001271 -65378607361501080857009149939512557028198746004375 -35829035317434717326932123578154982629742552737307 -94953759765105305946966067683156574377167401875275 -88902802571733229619176668713819931811048770190271 -25267680276078003013678680992525463401061632866526 -36270218540497705585629946580636237993140746255962 -24074486908231174977792365466257246923322810917141 -91430288197103288597806669760892938638285025333403 -34413065578016127815921815005561868836468420090470 -23053081172816430487623791969842487255036638784583 -11487696932154902810424020138335124462181441773470 -63783299490636259666498587618221225225512486764533 -67720186971698544312419572409913959008952310058822 -95548255300263520781532296796249481641953868218774 -76085327132285723110424803456124867697064507995236 -37774242535411291684276865538926205024910326572967 -23701913275725675285653248258265463092207058596522 -29798860272258331913126375147341994889534765745501 -18495701454879288984856827726077713721403798879715 -38298203783031473527721580348144513491373226651381 -34829543829199918180278916522431027392251122869539 -40957953066405232632538044100059654939159879593635 -29746152185502371307642255121183693803580388584903 -41698116222072977186158236678424689157993532961922 -62467957194401269043877107275048102390895523597457 -23189706772547915061505504953922979530901129967519 -86188088225875314529584099251203829009407770775672 -11306739708304724483816533873502340845647058077308 -82959174767140363198008187129011875491310547126581 -97623331044818386269515456334926366572897563400500 -42846280183517070527831839425882145521227251250327 -55121603546981200581762165212827652751691296897789 -32238195734329339946437501907836945765883352399886 -75506164965184775180738168837861091527357929701337 -62177842752192623401942399639168044983993173312731 -32924185707147349566916674687634660915035914677504 -99518671430235219628894890102423325116913619626622 -73267460800591547471830798392868535206946944540724 -76841822524674417161514036427982273348055556214818 -97142617910342598647204516893989422179826088076852 -87783646182799346313767754307809363333018982642090 -10848802521674670883215120185883543223812876952786 -71329612474782464538636993009049310363619763878039 -62184073572399794223406235393808339651327408011116 -66627891981488087797941876876144230030984490851411 -60661826293682836764744779239180335110989069790714 -85786944089552990653640447425576083659976645795096 -66024396409905389607120198219976047599490197230297 -64913982680032973156037120041377903785566085089252 -16730939319872750275468906903707539413042652315011 -94809377245048795150954100921645863754710598436791 -78639167021187492431995700641917969777599028300699 -15368713711936614952811305876380278410754449733078 -40789923115535562561142322423255033685442488917353 -44889911501440648020369068063960672322193204149535 -41503128880339536053299340368006977710650566631954 -81234880673210146739058568557934581403627822703280 -82616570773948327592232845941706525094512325230608 -22918802058777319719839450180888072429661980811197 -77158542502016545090413245809786882778948721859617 -72107838435069186155435662884062257473692284509516 -20849603980134001723930671666823555245252804609722 -53503534226472524250874054075591789781264330331690 -*/ //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -125,7 +23,11 @@ package com.mattrixwv.project_euler.problems; +import java.io.File; +import java.io.IOException; import java.math.BigInteger; +import java.nio.file.Files; +import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.List; @@ -134,127 +36,40 @@ import com.mattrixwv.ArrayAlgorithms; public class Problem13 extends Problem{ //Variables + //Static variables + protected static String FILE_NAME = "files/Problem13Numbers.txt"; + protected static ArrayList nums; //Holds the numbers that are being summed //Instance variables - private ArrayList nums; //Holds the numbers that are being summed - private BigInteger sum; //The sum of all the numbers + protected BigInteger sum; //The sum of all the numbers //Functions //Constructor public Problem13(){ super("Work out the first ten digits of the sum of the one-hundred 50-digit numbers"); - nums = new ArrayList<>(); - reserveVectors(); - setNums(); sum = BigInteger.ZERO; } //Operational functions - //A function to set the nums vector - private void reserveVectors(){ - nums.ensureCapacity(100); - } - //Reserve the size of the vector to speed up insertion - private void setNums(){ - //Setup the array - nums.add(new BigInteger("37107287533902102798797998220837590246510135740250")); - nums.add(new BigInteger("46376937677490009712648124896970078050417018260538")); - nums.add(new BigInteger("74324986199524741059474233309513058123726617309629")); - nums.add(new BigInteger("91942213363574161572522430563301811072406154908250")); - nums.add(new BigInteger("23067588207539346171171980310421047513778063246676")); - nums.add(new BigInteger("89261670696623633820136378418383684178734361726757")); - nums.add(new BigInteger("28112879812849979408065481931592621691275889832738")); - nums.add(new BigInteger("44274228917432520321923589422876796487670272189318")); - nums.add(new BigInteger("47451445736001306439091167216856844588711603153276")); - nums.add(new BigInteger("70386486105843025439939619828917593665686757934951")); - nums.add(new BigInteger("62176457141856560629502157223196586755079324193331")); - nums.add(new BigInteger("64906352462741904929101432445813822663347944758178")); - nums.add(new BigInteger("92575867718337217661963751590579239728245598838407")); - nums.add(new BigInteger("58203565325359399008402633568948830189458628227828")); - nums.add(new BigInteger("80181199384826282014278194139940567587151170094390")); - nums.add(new BigInteger("35398664372827112653829987240784473053190104293586")); - nums.add(new BigInteger("86515506006295864861532075273371959191420517255829")); - nums.add(new BigInteger("71693888707715466499115593487603532921714970056938")); - nums.add(new BigInteger("54370070576826684624621495650076471787294438377604")); - nums.add(new BigInteger("53282654108756828443191190634694037855217779295145")); - nums.add(new BigInteger("36123272525000296071075082563815656710885258350721")); - nums.add(new BigInteger("45876576172410976447339110607218265236877223636045")); - nums.add(new BigInteger("17423706905851860660448207621209813287860733969412")); - nums.add(new BigInteger("81142660418086830619328460811191061556940512689692")); - nums.add(new BigInteger("51934325451728388641918047049293215058642563049483")); - nums.add(new BigInteger("62467221648435076201727918039944693004732956340691")); - nums.add(new BigInteger("15732444386908125794514089057706229429197107928209")); - nums.add(new BigInteger("55037687525678773091862540744969844508330393682126")); - nums.add(new BigInteger("18336384825330154686196124348767681297534375946515")); - nums.add(new BigInteger("80386287592878490201521685554828717201219257766954")); - nums.add(new BigInteger("78182833757993103614740356856449095527097864797581")); - nums.add(new BigInteger("16726320100436897842553539920931837441497806860984")); - nums.add(new BigInteger("48403098129077791799088218795327364475675590848030")); - nums.add(new BigInteger("87086987551392711854517078544161852424320693150332")); - nums.add(new BigInteger("59959406895756536782107074926966537676326235447210")); - nums.add(new BigInteger("69793950679652694742597709739166693763042633987085")); - nums.add(new BigInteger("41052684708299085211399427365734116182760315001271")); - nums.add(new BigInteger("65378607361501080857009149939512557028198746004375")); - nums.add(new BigInteger("35829035317434717326932123578154982629742552737307")); - nums.add(new BigInteger("94953759765105305946966067683156574377167401875275")); - nums.add(new BigInteger("88902802571733229619176668713819931811048770190271")); - nums.add(new BigInteger("25267680276078003013678680992525463401061632866526")); - nums.add(new BigInteger("36270218540497705585629946580636237993140746255962")); - nums.add(new BigInteger("24074486908231174977792365466257246923322810917141")); - nums.add(new BigInteger("91430288197103288597806669760892938638285025333403")); - nums.add(new BigInteger("34413065578016127815921815005561868836468420090470")); - nums.add(new BigInteger("23053081172816430487623791969842487255036638784583")); - nums.add(new BigInteger("11487696932154902810424020138335124462181441773470")); - nums.add(new BigInteger("63783299490636259666498587618221225225512486764533")); - nums.add(new BigInteger("67720186971698544312419572409913959008952310058822")); - nums.add(new BigInteger("95548255300263520781532296796249481641953868218774")); - nums.add(new BigInteger("76085327132285723110424803456124867697064507995236")); - nums.add(new BigInteger("37774242535411291684276865538926205024910326572967")); - nums.add(new BigInteger("23701913275725675285653248258265463092207058596522")); - nums.add(new BigInteger("29798860272258331913126375147341994889534765745501")); - nums.add(new BigInteger("18495701454879288984856827726077713721403798879715")); - nums.add(new BigInteger("38298203783031473527721580348144513491373226651381")); - nums.add(new BigInteger("34829543829199918180278916522431027392251122869539")); - nums.add(new BigInteger("40957953066405232632538044100059654939159879593635")); - nums.add(new BigInteger("29746152185502371307642255121183693803580388584903")); - nums.add(new BigInteger("41698116222072977186158236678424689157993532961922")); - nums.add(new BigInteger("62467957194401269043877107275048102390895523597457")); - nums.add(new BigInteger("23189706772547915061505504953922979530901129967519")); - nums.add(new BigInteger("86188088225875314529584099251203829009407770775672")); - nums.add(new BigInteger("11306739708304724483816533873502340845647058077308")); - nums.add(new BigInteger("82959174767140363198008187129011875491310547126581")); - nums.add(new BigInteger("97623331044818386269515456334926366572897563400500")); - nums.add(new BigInteger("42846280183517070527831839425882145521227251250327")); - nums.add(new BigInteger("55121603546981200581762165212827652751691296897789")); - nums.add(new BigInteger("32238195734329339946437501907836945765883352399886")); - nums.add(new BigInteger("75506164965184775180738168837861091527357929701337")); - nums.add(new BigInteger("62177842752192623401942399639168044983993173312731")); - nums.add(new BigInteger("32924185707147349566916674687634660915035914677504")); - nums.add(new BigInteger("99518671430235219628894890102423325116913619626622")); - nums.add(new BigInteger("73267460800591547471830798392868535206946944540724")); - nums.add(new BigInteger("76841822524674417161514036427982273348055556214818")); - nums.add(new BigInteger("97142617910342598647204516893989422179826088076852")); - nums.add(new BigInteger("87783646182799346313767754307809363333018982642090")); - nums.add(new BigInteger("10848802521674670883215120185883543223812876952786")); - nums.add(new BigInteger("71329612474782464538636993009049310363619763878039")); - nums.add(new BigInteger("62184073572399794223406235393808339651327408011116")); - nums.add(new BigInteger("66627891981488087797941876876144230030984490851411")); - nums.add(new BigInteger("60661826293682836764744779239180335110989069790714")); - nums.add(new BigInteger("85786944089552990653640447425576083659976645795096")); - nums.add(new BigInteger("66024396409905389607120198219976047599490197230297")); - nums.add(new BigInteger("64913982680032973156037120041377903785566085089252")); - nums.add(new BigInteger("16730939319872750275468906903707539413042652315011")); - nums.add(new BigInteger("94809377245048795150954100921645863754710598436791")); - nums.add(new BigInteger("78639167021187492431995700641917969777599028300699")); - nums.add(new BigInteger("15368713711936614952811305876380278410754449733078")); - nums.add(new BigInteger("40789923115535562561142322423255033685442488917353")); - nums.add(new BigInteger("44889911501440648020369068063960672322193204149535")); - nums.add(new BigInteger("41503128880339536053299340368006977710650566631954")); - nums.add(new BigInteger("81234880673210146739058568557934581403627822703280")); - nums.add(new BigInteger("82616570773948327592232845941706525094512325230608")); - nums.add(new BigInteger("22918802058777319719839450180888072429661980811197")); - nums.add(new BigInteger("77158542502016545090413245809786882778948721859617")); - nums.add(new BigInteger("72107838435069186155435662884062257473692284509516")); - nums.add(new BigInteger("20849603980134001723930671666823555245252804609722")); - nums.add(new BigInteger("53503534226472524250874054075591789781264330331690")); + //Read number from file into nums + private void readFile(){ + if(nums != null){ + return; + } + File file = new File(FILE_NAME); + if(file.exists()){ + try{ + List lines = Files.readAllLines(file.toPath()); + nums = new ArrayList<>(); + for(String line : lines){ + nums.add(new BigInteger(line)); + } + } + catch(IOException error){ + throw new InvalidParameterException("Error reading file", error); + } + } + else{ + throw new InvalidParameterException("Error opening file"); + } } //Solve the problem @Override @@ -264,6 +79,9 @@ public class Problem13 extends Problem{ return; } + //Read the file into the number + readFile(); + //Start the timer timer.start(); @@ -283,9 +101,6 @@ public class Problem13 extends Problem{ public void reset(){ super.reset(); sum = BigInteger.ZERO; - nums.clear(); - reserveVectors(); - setNums(); } //Gets //Returns the result of solving the problem diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem14.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem14.java index ba531df..7aadfa2 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem14.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem14.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem14.java //Matthew Ellison // Created: 03-04-19 -//Modified: 08-20-22 +//Modified: 06-27-23 /* The following iterative sequence is defined for the set of positive integers: n → n/2 (n is even) @@ -10,7 +10,7 @@ Which starting number, under one million, produces the longest chain? */ //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -33,8 +33,8 @@ public class Problem14 extends Problem{ //Static variables private static final long MAX_NUM = 1000000L - 1L; //This is the top number that you will be checking against the series //Instance variables - private long maxLength; //This is the length of the longest chain - private long maxNum; //This is the starting number of the longest chain + protected long maxLength; //This is the length of the longest chain + protected long maxNum; //This is the starting number of the longest chain //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem15.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem15.java index 3e920bc..8ec6d9e 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem15.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem15.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem15.java //Matthew Ellison // Created: 03-04-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -29,7 +29,7 @@ public class Problem15 extends Problem{ protected static int gridWidth = 20; //The width of the box to traverse protected static int gridLength = 20; //The height of the box to traverse //Instance variables - private long numOfRoutes; //The number of routes from 0, 0 to 20, 20 + protected long numOfRoutes; //The number of routes from 0, 0 to 20, 20 //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem16.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem16.java index 671dcc5..3efffef 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem16.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem16.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java //Matthew Ellison // Created: 03-04-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the sum of the digits of the number 2^1000? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,8 +32,8 @@ public class Problem16 extends Problem{ private static final int NUM_TO_POWER = 2; //The number that is going to be raised to a power private static final int POWER = 1000; //The power that the number is going to be raised to //Instance variables - private BigInteger num; //The number to be calculated - private int sumOfElements; //The sum of all digits in the number + protected BigInteger num; //The number to be calculated + protected int sumOfElements; //The sum of all digits in the number //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem17.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem17.java index 675c857..2faddfb 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem17.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem17.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem17.java //Matthew Ellison // Created: 03-04-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -23,17 +23,13 @@ package com.mattrixwv.project_euler.problems; -import com.mattrixwv.exceptions.InvalidResult; -import com.mattrixwv.project_euler.exceptions.Unsolved; - - public class Problem17 extends Problem{ //Variables //Static variables private static final int START_NUM = 1; //This is the smallest number to get the words of private static final int STOP_NUM = 1000; //This is the largest number to get the words of //Instance variables - private long letterCount; //This is the cumulative number of letters in the words of the numbers + protected long letterCount; //This is the cumulative number of letters in the words of the numbers //Functions //Constructor @@ -76,13 +72,14 @@ public class Problem17 extends Problem{ letterCount = 0; } //This function makes a word out of the number passed into it - private String makeWordFromNum(int number){ + protected String makeWordFromNum(int number){ int num = number; StringBuilder numberString = new StringBuilder(); //Starting with the largest digit create a string based on the number passed in //Check for negative if(num < 0){ numberString.append("negative "); + num = -num; } //Check if the number is zero @@ -105,7 +102,7 @@ public class Problem17 extends Problem{ } //Insert an and if there is need - if(!numberString.toString().isBlank() && (num > 0)){ + if(!numberString.toString().isBlank() && (numberString.indexOf("negative") != 0) && (num > 0)){ numberString.append(" and "); } @@ -122,7 +119,6 @@ public class Problem17 extends Problem{ case 4: numberString.append("forty"); break; case 3: numberString.append("thirty"); break; case 2: numberString.append("twenty"); break; - default: throw new InvalidResult("tensPlace < 2"); } num -= (tensPlace * 10); //If there is something left in the number you will need a dash to separate the tens and ones place @@ -144,7 +140,6 @@ public class Problem17 extends Problem{ case 2: numberString.append("twelve"); break; case 1: numberString.append("eleven"); break; case 0: numberString.append("ten"); break; - default: throw new InvalidResult("onesPlace > 9"); } //If this was hit the number was completed num = 0; @@ -162,17 +157,11 @@ public class Problem17 extends Problem{ case 3: numberString.append("three"); break; case 2: numberString.append("two"); break; case 1: numberString.append("one"); break; - default: throw new InvalidResult("onesPlace > 9"); } //If this was hit the number was completed num = 0; } - //If the number is not 0 there was a problem - if(num != 0){ - throw new Unsolved("The number " + number + " was not completely reduced!\nRemainder is " + num); - } - //Return the string return numberString.toString(); } diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem18.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem18.java index b5a90f0..e740735 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem18.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem18.java @@ -1,29 +1,12 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem18.java //Matthew Ellison // Created: 03-11-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the maximum total from top to bottom -/* -75 -95 64 -17 47 82 -18 35 87 10 -20 04 82 47 65 -19 01 23 75 03 34 -88 02 77 73 07 63 67 -99 65 04 28 06 16 70 92 -41 41 26 56 83 40 80 70 33 -41 48 72 33 47 32 37 16 94 29 -53 71 44 65 25 43 91 52 97 51 14 -70 11 33 28 77 73 17 78 39 68 17 57 -91 71 52 38 17 14 91 43 58 50 27 29 48 -63 66 04 68 89 53 67 30 73 16 69 87 40 31 -04 62 98 27 23 09 70 98 73 93 38 53 60 04 23 -*/ //This is done using a breadth first search //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -41,9 +24,13 @@ package com.mattrixwv.project_euler.problems; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.security.InvalidParameterException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.StringJoiner; @@ -75,27 +62,8 @@ public class Problem18 extends Problem{ //Variables //Static variables + protected String FILE_NAME = "files/Problem18Pyramid.txt"; protected static ArrayList> list; //The list to hold the numbers in - static{ - list = new ArrayList<>( - Arrays.asList( - new ArrayList(Arrays.asList(75)), - new ArrayList(Arrays.asList(95, 64)), - new ArrayList(Arrays.asList(17, 47, 82)), - new ArrayList(Arrays.asList(18, 35, 87, 10)), - new ArrayList(Arrays.asList(20, 04, 82, 47, 65)), - new ArrayList(Arrays.asList(19, 01, 23, 75, 03, 34)), - new ArrayList(Arrays.asList(88, 02, 77, 73, 07, 63, 67)), - new ArrayList(Arrays.asList(99, 65, 04, 28, 06, 16, 70, 92)), - new ArrayList(Arrays.asList(41, 41, 26, 56, 83, 40, 80, 70, 33)), - new ArrayList(Arrays.asList(41, 48, 72, 33, 47, 32, 37, 16, 94, 29)), - new ArrayList(Arrays.asList(53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14)), - new ArrayList(Arrays.asList(70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57)), - new ArrayList(Arrays.asList(91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48)), - new ArrayList(Arrays.asList(63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31)), - new ArrayList(Arrays.asList(04, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 04, 23)) - )); - } //Instance variables protected ArrayList foundPoints; //For the points that you have already found the shortest distance to protected ArrayList possiblePoints; //For the locations you are checking this round @@ -110,6 +78,32 @@ public class Problem18 extends Problem{ actualTotal = 0; } //Operational functions + //Read number from file into number + private void readFile(){ + if(list != null){ + return; + } + File file = new File(FILE_NAME); + if(file.exists()){ + try{ + List lines = Files.readAllLines(file.toPath()); + list = new ArrayList<>(); + for(String line : lines){ + ArrayList working = new ArrayList<>(); + for(String num : line.split(" ")){ + working.add(Integer.parseInt(num)); + } + list.add(working); + } + } + catch(IOException error){ + throw new InvalidParameterException("Error reading file", error); + } + } + else{ + throw new InvalidParameterException("Error opening file"); + } + } //This function turns every number in the array into (100 - num) to allow you to find the largest numbers rather than the smallest protected void invert(ArrayList> list){ //Loop through every row in the list @@ -132,6 +126,9 @@ public class Problem18 extends Problem{ return; } + //Read the file into the list + readFile(); + //Start the timer timer.start(); @@ -237,10 +234,6 @@ public class Problem18 extends Problem{ int loc = foundPoints.size() - 1; Location toAdd = null; while(!found){ - if(loc < 0){ - results.add("Error: Location < 0\n"); - System.exit(1); - } Iterator it = foundPoints.iterator(); Location tempLoc = new Location(0, 0, 0, false); for(int cnt = 0;cnt < loc;++cnt){ diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem19.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem19.java index 944c983..50b7622 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem19.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem19.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem19.java //Matthew Ellison // Created: 03-13-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)? /* You are given the following information, but you may prefer to do some research for yourself. @@ -16,7 +16,7 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles */ //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -33,8 +33,10 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles */ package com.mattrixwv.project_euler.problems; + import com.mattrixwv.exceptions.InvalidResult; + public class Problem19 extends Problem{ //Variables //Static variables @@ -43,7 +45,7 @@ public class Problem19 extends Problem{ private static final int START_YEAR = 1901; //The first year we are going to test private static final int END_YEAR = 2000; //The last year we are going to test //Instance variables - private long totalSundays; //Keep track of the number of sundays + protected long totalSundays; //Keep track of the number of sundays //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem2.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem2.java index d9a0431..517f0db 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem2.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem2.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem2.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //The sum of the even Fibonacci numbers less than 4,000,000 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -33,7 +33,7 @@ public class Problem2 extends Problem{ //Static variables private static final int TOP_NUM = 4000000 - 1; //The largest number that will be checked as a fibonacci number //Instance variables - private int fullSum; //Holds the sum of all the numbers + protected int fullSum; //Holds the sum of all the numbers //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem20.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem20.java index 8e9a163..e3ddbf2 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem20.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem20.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem20.java //Matthew Ellison // Created: 03-14-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the sum of the digits of 100!? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,8 +31,8 @@ public class Problem20 extends Problem{ //Static variables private static final int TOP_NUM = 100; //The largest number that will be multiplied //Instance variables - private BigInteger num; //Holds the number 100! - private long sum; //The sum of the digits of num + protected BigInteger num; //Holds the number 100! + protected long sum; //The sum of the digits of num //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem21.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem21.java index aed8661..e463d33 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem21.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem21.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java //Matthew Ellison // Created: 03-18-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Evaluate the sum of all the amicable numbers under 10000 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,8 +36,8 @@ public class Problem21 extends Problem{ //Static variables private static final int LIMIT = 10000; //The number that is > the largest number to be checked //Instance variables - private ArrayList divisorSum; //Holds the sum of the divisors of the subscript number - private ArrayList amicable; //Holds all amicable numbers + protected ArrayList divisorSum; //Holds the sum of the divisors of the subscript number + protected ArrayList amicable; //Holds all amicable numbers //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem22.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem22.java index f308f1d..7a721b2 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem22.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem22.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem22.java //Matthew Ellison // Created: 03-20-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the total of all the name scores in this file? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -37,13 +37,13 @@ import java.util.List; public class Problem22 extends Problem{ //Variables //Static variables - private static final String FILE_NAME = "files/Problem22Names.txt"; + protected static String FILE_NAME = "files/Problem22Names.txt"; //Holds the names that will be scored - private static final ArrayList names = new ArrayList<>(); + protected static ArrayList names = new ArrayList<>(); //Instance variables - private ArrayList sums; //Holds the score based on the sum of the characters in the name - private ArrayList prod; //Holds the score based on the sum of the characters and the location in alphabetical order - private long sum; //Holds the sum of the scores + protected ArrayList sums; //Holds the score based on the sum of the characters in the name + protected ArrayList prod; //Holds the score based on the sum of the characters and the location in alphabetical order + protected long sum; //Holds the sum of the scores //Functions //Constructor @@ -71,7 +71,7 @@ public class Problem22 extends Problem{ } } catch(IOException error){ - throw new InvalidParameterException(error.getMessage()); + throw new InvalidParameterException("Error reading file", error); } } else{ diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem23.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem23.java index 3b02159..ad17ba7 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem23.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem23.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem23.java //Matthew Ellison // Created: 03-22-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -35,8 +35,9 @@ public class Problem23 extends Problem{ //Static variables protected static int maxNum = 28123; //The largest number to be checked //Instance variables - private ArrayList divisorSums; //This gives the sum of the divisors at subscripts - private long sum; //The sum of all the numbers we are looking for + protected ArrayList divisorSums; //This gives the sum of the divisors at subscripts + protected long sum; //The sum of all the numbers we are looking for + //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem24.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem24.java index f213b9f..2e72603 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem24.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem24.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem24.java //Matthew Ellison // Created: 03-24-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -35,7 +35,7 @@ public class Problem24 extends Problem{ protected static int neededPerm = 1000000; //The number of the permutation that you need protected static String nums = "0123456789"; //All of the characters that we need to get the permutations of //Instance variables - private List permutations; //Holds all of the permutations of the string nums + protected List permutations; //Holds all of the permutations of the string nums //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem25.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem25.java index 069e7dd..76a5d0b 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem25.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem25.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem25.java //Matthew Ellison // Created: 03-25-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the index of the first term in the Fibonacci sequence to contain 1000 digits? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -33,8 +33,8 @@ public class Problem25 extends Problem{ //Static variables private static final int NUM_DIGITS = 1000; //The number of digits to calculate up to //Instance variables - private BigInteger number; //The current Fibonacci number - private BigInteger index; //The index of the current Fibonacci number just calculated + protected BigInteger number; //The current Fibonacci number + protected BigInteger index; //The index of the current Fibonacci number just calculated //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem26.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem26.java index c8ad8e6..8c075ed 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem26.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem26.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem26.java //Matthew Ellison // Created: 07-28-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,8 +31,9 @@ public class Problem26 extends Problem{ //Static variables private static final int TOP_NUM = 999; //The largest denominator to test //Instance variables - private int longestCycle; //The length of the longest cycle - private int longestNumber; //The starting denominator of the longest cycle + protected int longestCycle; //The length of the longest cycle + protected int longestNumber; //The starting denominator of the longest cycle + //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem27.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem27.java index 373b13b..395b179 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem27.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem27.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem27.java //Matthew Ellison // Created: 09-15-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,9 +32,9 @@ public class Problem27 extends Problem{ private static final int LARGEST_POSSIBLE_A = 999; private static final int LARGEST_POSSIBLE_B = 1000; //Instance variables - private int topA; //The A for the most n's generated - private int topB; //The B for the most n's generated - private int topN; //The most n's generated + protected int topA; //The A for the most n's generated + protected int topB; //The B for the most n's generated + protected int topN; //The most n's generated //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem28.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem28.java index 1329bfa..36777bd 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem28.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem28.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem28.java //Matthew Ellison // Created: 09-22-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -30,8 +30,8 @@ import java.util.List; public class Problem28 extends Problem{ //Variables //Instance variables - private ArrayList> grid; //Holds the grid that we will be filling and searching - private int sumOfDiagonals; //Holds the sum of the diagonals of the grid + protected ArrayList> grid; //Holds the grid that we will be filling and searching + protected int sumOfDiagonals; //Holds the sum of the diagonals of the grid //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem29.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem29.java index ff622bd..cda9eda 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem29.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem29.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem29.java //Matthew Ellison // Created: 10-09-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,7 +36,7 @@ public class Problem29 extends Problem{ private static final int BOTTOM_B = 2; //The lowest possible value for b private static final int TOP_B = 100; //The highest possible value for b //Instance variables - private ArrayList unique; //Holds all unique values generated + protected List unique; //Holds all unique values generated //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem3.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem3.java index 63e60ea..43e28c8 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem3.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem3.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem3.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //The largest prime factor of 600851475143 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -35,7 +35,7 @@ public class Problem3 extends Problem{ //Static variables private static final long GOAL_NUMBER = 600851475143L; //The number that needs factored //Instance variables - private List factors; //Holds the factors of goalNumber + protected List factors; //Holds the factors of goalNumber //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem30.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem30.java index 691659c..31b2668 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem30.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem30.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem30.java //Matthew Ellison // Created: 10-27-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,8 +36,8 @@ public class Problem30 extends Problem{ private static final long BOTTOM_NUM = 2; //Starts with 2 because 0 and 1 don't count private static final long POWER_RAISED = 5; //This is the power that the digits are raised to //Instance variables - private ArrayList sumOfFifthNumbers; //This is an ArrayList of the numbers that are the sum of the fifth power of their digits - private long sum; //This is the sum of the sumOfFifthNumbers array + protected List sumOfFifthNumbers; //This is an ArrayList of the numbers that are the sum of the fifth power of their digits + protected long sum; //This is the sum of the sumOfFifthNumbers array //Functions //Operational functions diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem31.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem31.java index 18fa9d0..30fd672 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem31.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem31.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem31.java //Matthew Ellison // Created: 06-19-20 -//Modified: 08-20-22 +//Modified: 06-27-23 //How many different ways can £2 be made using any number of coins? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -28,7 +28,7 @@ public class Problem31 extends Problem{ //Static variables private static final int DESIRED_VALUE = 200; //The value of coins we want //Instance variables - private int permutations; //The number of permutations that are found + protected int permutations; //The number of permutations that are found //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem32.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem32.java index c86e655..0842e69 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem32.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem32.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem32.java //Matthew Ellison // Created: 07-27-20 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,18 +31,16 @@ import com.mattrixwv.StringAlgorithms; public class Problem32 extends Problem{ //Structures //Holds the set of numbers that make a product - private class ProductSet{ + protected class ProductSet{ private int multiplicand; private int multiplier; public ProductSet(int multiplicand, int multiplier){ this.multiplicand = multiplicand; this.multiplier = multiplier; } - @SuppressWarnings("unused") public int getMultiplicand(){ return multiplicand; } - @SuppressWarnings("unused") public int getMultiplier(){ return multiplier; } @@ -78,8 +76,8 @@ public class Problem32 extends Problem{ private static final int TOP_MULTIPLICAND = 99; //The largest multiplicand to check private static final int TOP_MULTIPLIER = 4999; //The largest multiplier to check //Instance variables - ArrayList listOfProducts; //The list of unique products that are 1-9 pandigital - long sumOfPandigitals; //The sum of the products of the pandigital numbers + protected ArrayList listOfProducts; //The list of unique products that are 1-9 pandigital + protected long sumOfPandigitals; //The sum of the products of the pandigital numbers //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem33.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem33.java index 07089e6..bb17f78 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem33.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem33.java @@ -1,7 +1,7 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem33.java //Matthew Ellison // Created: 02-05-21 -//Modified: 08-20-22 +//Modified: 06-27-23 /* The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s We shall consider fractions like, 30/50 = 3/5, to be trivial examples @@ -10,7 +10,7 @@ If the product of these four fractions is given in its lowest common terms, find */ //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -43,9 +43,9 @@ public class Problem33 extends Problem{ private static final int MIN_DENOMINATOR = 11; //The lowest the denominator can be private static final int MAX_DENOMINATOR = 99; //The highest the denominator can be //Instance variables - private ArrayList numerators; //Holds the numerators that were found - private ArrayList denominators; //Holds the denominators that were found - private int prodDenominator; //Holds the answer to the question + protected ArrayList numerators; //Holds the numerators that were found + protected ArrayList denominators; //Holds the denominators that were found + protected int prodDenominator; //Holds the answer to the question //Functions //Constructor @@ -127,6 +127,7 @@ public class Problem33 extends Problem{ super.reset(); numerators.clear(); denominators.clear(); + prodDenominator = 1; } //Gets //Returns the result of solving the problem diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem34.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem34.java index a11f6f0..4c0769e 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem34.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem34.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem34.java //Matthew Ellison // Created: 02-05-21 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the sum of all numbers which are equal to the sum of the factorial of their digits //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,8 +34,8 @@ public class Problem34 extends Problem{ //Static variables private static final int MAX_NUM = 1499999; //The largest num that can be the sum of its own digits //Instance variables - private ArrayList factorials; //Holds the pre-computed factorials of the numbers 0-9 - private int sum; //Holds the sum of all numbers equal to the sum of their digit's factorials + protected List factorials; //Holds the pre-computed factorials of the numbers 0-9 + protected int sum; //Holds the sum of all numbers equal to the sum of their digit's factorials //Functions //Constructor @@ -91,7 +91,7 @@ public class Problem34 extends Problem{ public void reset(){ super.reset(); sum = 0; - factorials = new ArrayList<>(); + factorials.clear(); for(int cnt = 0;cnt <= 9;++cnt){ factorials.add(0); } diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem35.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem35.java index caad57e..bb93784 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem35.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem35.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem35.java //Matthew Ellison // Created: 06-05-21 -//Modified: 08-20-22 +//Modified: 06-27-23 //How many circular primes are there below one million? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,8 +34,8 @@ public class Problem35 extends Problem{ //Static variables protected static int maxNum = 999999; //The largest number that we are checking for primes //Instance variables - private List primes; //The primes below MAX_NUM - private ArrayList circularPrimes; //The circular primes below MAX_NUM + protected List primes; //The primes below MAX_NUM + protected List circularPrimes; //The circular primes below MAX_NUM //Functions //Returns a list of all rotations of a string passed to it private ArrayList getRotations(String str){ diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem36.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem36.java index 78343c2..318aab6 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem36.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem36.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem36.java //Matthew Ellison // Created: 06-29-21 -//Modified: 08-20-22 +//Modified: 06-30-23 //Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,8 +36,8 @@ public class Problem36 extends Problem{ //Static variables private static final int MAX_NUM = 999999; //The largest number that will be checked //Instance variables - private ArrayList palindromes; //All numbers that are palindromes in base 10 and 2 - private int sum; //The sum of all elements in the list of palindromes + protected ArrayList palindromes; //All numbers that are palindromes in base 10 and 2 + protected int sum; //The sum of all elements in the list of palindromes //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem37.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem37.java index 30ec30d..9204026 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem37.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem37.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem37.java //Matthew Ellison // Created: 07-01-21 -//Modified: 08-20-22 +//Modified: 06-30-23 //Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted). //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,8 +36,8 @@ public class Problem37 extends Problem{ //Static variables private static final long LAST_PRIME_BEFORE_CHECK = 7; //The last prime before 11 since single digit primes aren't checked //Instance variables - private ArrayList truncPrimes; //All numbers that are truncatable primes - private long sum; //The sum of all elements in truncPrimes + protected List truncPrimes; //All numbers that are truncatable primes + protected long sum; //The sum of all elements in truncPrimes //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem38.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem38.java index 3c3cb46..68e88ce 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem38.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem38.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem37.java //Matthew Ellison // Created: 10-11-21 -//Modified: 08-20-22 +//Modified: 06-30-23 //What is the largest 1-9 pandigital number that can be formed as the concatenated product of an integer with 1, 2, ... n where n > 1 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,8 +31,8 @@ public class Problem38 extends Problem{ //Static variables private static final long HIGHEST_POSSIBLE_NUM = 9999; //The highest number that needs to be checked for a 1-9 pandigital //Instance variables - private long largestNum; //The number passed to the executeFormula function that returns the largest pandigital - private long pandigital; //The largest pandigital number found + protected long largestNum; //The number passed to the executeFormula function that returns the largest pandigital + protected long pandigital; //The largest pandigital number found //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem39.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem39.java index 6226448..29aa02a 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem39.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem39.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem39.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //If p is the perimeter of a right triangle for which value of p <= 1000 is the number of solutions for the sides {a, b, c} maximized //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,7 +34,7 @@ public class Problem39 extends Problem{ //Static variables protected static long maxPerimeter = 1000; //Instace variables - private ArrayList> longestSolutions; + protected List> longestSolutions; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem4.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem4.java index fb3bfcd..80535db 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem4.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem4.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem4.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the largest palindrome made from the product of two 3-digit numbers //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,7 +34,7 @@ public class Problem4 extends Problem{ private static final int START_NUM = 100; //The first number to be multiplied private static final int END_NUM = 999; //The last number to be multiplied //Instance variables - private ArrayList palindromes; //Holds all numbers that turn out to be palindromes + protected List palindromes; //Holds all numbers that turn out to be palindromes //Constructor public Problem4(){ diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem40.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem40.java index 1ee41c3..ffd20d5 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem40.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem40.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem40.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //An irrational decimal fraction is created by concatenating the positive integers. Find the value of the following expression: d1 * d10 * d100 * d1000 * d10000 * d100000 * d1000000 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -33,8 +33,8 @@ public class Problem40 extends Problem{ //Static variables private static final long LARGEST_SUBSCRIPT = 1000000; //Instance variables - private StringBuilder irrationalDecimal; - private long product; + protected StringBuilder irrationalDecimal; + protected long product; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem41.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem41.java index fbe9cea..7b6d7f8 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem41.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem41.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem41.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //What is the largest n-digit pandigital prime? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,7 +32,7 @@ import com.mattrixwv.StringAlgorithms; public class Problem41 extends Problem{ //Variables //Instance variables - private long largestPrimePandigital; + protected long largestPrimePandigital; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem42.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem42.java index 8a296b9..fbffcc0 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem42.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem42.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem42.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //Triangular number t(n) = (n * (n + 1)) / 2. For A = 1, B = 2, ... find the number of triangular words in the file //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,10 +34,10 @@ import java.util.List; public class Problem42 extends Problem{ //Variables //Static variables - private static final String FILE_NAME = "files/Problem42Words.txt"; - private static final ArrayList fileWords = new ArrayList<>(); + protected static String FILE_NAME = "files/Problem42Words.txt"; + protected static ArrayList fileWords = new ArrayList<>(); //Instance variables - private ArrayList triangleWords; + protected ArrayList triangleWords; //Functions //Constructor @@ -63,7 +63,7 @@ public class Problem42 extends Problem{ } } catch(IOException error){ - throw new InvalidParameterException(error.getMessage()); + throw new InvalidParameterException("Error reading file", error); } } else{ diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem43.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem43.java index 346482f..dd5f889 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem43.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem43.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem43.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //Find the sum of all 0-9 pandigital numbers with this property //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,7 +36,7 @@ public class Problem43 extends Problem{ //Static variables protected static String nums = "0123456789"; //Instance variables - private ArrayList subPrimePandigitals; + protected ArrayList subPrimePandigitals; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem44.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem44.java index 0f8cc70..c231890 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem44.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem44.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem44.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //Pentagonal number P = ((n * (3 * n - 1)) / 2). Find 2 pentagonal numbers whos sum and difference are also pentagonal numbers //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,10 +32,10 @@ import com.mattrixwv.generators.PentagonalNumberGenerator; public class Problem44 extends Problem{ //Variables //Instance variables - private PentagonalNumberGenerator generator; - private List pentagonalList; - private long pentagonalNumber1; - private long pentagonalNumber2; + protected PentagonalNumberGenerator generator; + protected List pentagonalList; + protected long pentagonalNumber1; + protected long pentagonalNumber2; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem45.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem45.java index 107bbec..d7bdeb9 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem45.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem45.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem45.java //Mattrixwv // Created: 08-20-22 -//Modified: 08-20-22 +//Modified: 06-30-23 //If p is the perimeter of a right triangle for which value of p <= 1000 is the number of solutions for the sides {a, b, c} maximized //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,10 +31,10 @@ public class Problem45 extends Problem{ //Static variables private static final long MIN_NUMBER = 40756; //Instance variables - private long num; - private TriangularNumberGenerator triGen; - private PentagonalNumberGenerator penGen; - private HexagonalNumberGenerator hexGen; + protected long num; + protected TriangularNumberGenerator triGen; + protected PentagonalNumberGenerator penGen; + protected HexagonalNumberGenerator hexGen; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem46.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem46.java index 5670a79..10a2f6b 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem46.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem46.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/project_euler/Problems/Problem46.java //Mattrixwv // Created: 08-22-22 -//Modified: 08-22-22 +//Modified: 06-30-23 //What is the smallest odd coposite number that cannot be written as the sum of a prime and twice a square? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,7 +31,7 @@ import com.mattrixwv.generators.SieveOfEratosthenes; public class Problem46 extends Problem{ //Variables //Instance variables - private long num; + protected long num; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem47.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem47.java index 5eda2ee..1aef79b 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem47.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem47.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem47.java //Mattrixwv // Created: 08-22-22 -//Modified: 08-22-22 +//Modified: 06-30-23 //What is the first of four consecutive integers to have four distinct prime factors each? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -25,7 +25,6 @@ package com.mattrixwv.project_euler.problems; import java.util.HashMap; import java.util.List; -import java.util.Map.Entry; import com.mattrixwv.NumberAlgorithms; @@ -33,7 +32,7 @@ import com.mattrixwv.NumberAlgorithms; public class Problem47 extends Problem{ //Variables //Instance variables - private long num; //The first of the consecutive numbers + protected long num; //The first of the consecutive numbers //Function //Constructor @@ -59,7 +58,6 @@ public class Problem47 extends Problem{ factors.put(2L, NumberAlgorithms.getFactors(2L)); factors.put(3L, NumberAlgorithms.getFactors(3L)); for(long cnt = 1;num == 0;++cnt){ - boolean found = false; //Get the next set of factors factors.put(cnt + 3, NumberAlgorithms.getFactors(cnt + 3)); @@ -86,26 +84,7 @@ public class Problem47 extends Problem{ continue; } - //Make sure none of the elements match - for(Entry entry : factors0.entrySet()){ - if(entry.getValue().equals(factors1.get(entry.getKey())) || entry.getValue().equals(factors2.get(entry.getKey())) || entry.getValue().equals(factors3.get(entry.getKey()))){ - found = true; - } - } - for(Entry entry : factors1.entrySet()){ - if(entry.getValue().equals(factors2.get(entry.getKey())) || entry.getValue().equals(factors3.get(entry.getKey()))){ - found = true; - } - } - for(Entry entry : factors2.entrySet()){ - if(entry.getValue().equals(factors3.get(entry.getKey()))){ - found = true; - } - } - - if(!found){ - num = cnt; - } + num = cnt; } diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem48.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem48.java index cda45f7..6d51214 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem48.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem48.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem48.java //Mattrixwv // Created: 08-23-22 -//Modified: 08-23-22 +//Modified: 06-30-23 //Find the last ten digits of the series 1^1 + 2^2 + 3^3 + ... + 1000^1000 //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,7 +31,7 @@ public class Problem48 extends Problem{ //Static variables private static final BigInteger TOP_NUM = BigInteger.valueOf(1000); //Instance variables - private BigInteger sum; + protected BigInteger sum; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem49.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem49.java index 6c9c6ba..f1dea06 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem49.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem49.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem49.java //Mattrixwv // Created: 08-23-22 -//Modified: 08-23-22 +//Modified: 06-30-23 //What is the 12-digit number formed by concatenating the three terms in the sequence? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -39,7 +39,7 @@ public class Problem49 extends Problem{ private static final int MIN_NUMBER = 1000; private static final int MAX_NUMBER = 9999; //Instance variables - private String concatenationOfNumbers; + protected String concatenationOfNumbers; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem5.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem5.java index 900cc8f..5d4d8ab 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem5.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem5.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem5.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -26,7 +26,7 @@ package com.mattrixwv.project_euler.problems; public class Problem5 extends Problem{ //Variables //Instance variables - private int smallestNum; //The smallest number that is found + protected int smallestNum; //The smallest number that is found //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem50.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem50.java index ada16c7..ed8de88 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem50.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem50.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/com/mattrixwv/project_euler/problems/Problem50.java //Mattrixwv // Created: 08-23-22 -//Modified: 08-23-22 +//Modified: 06-30-23 //Which prime, below one-million, can be written as the sum of the most consecutive primes? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -35,7 +35,7 @@ public class Problem50 extends Problem{ //Static variables private static final long MAX = 999999; //Instance variables - private ArrayList consecutivePrimes; + protected ArrayList consecutivePrimes; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem6.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem6.java index 94be541..6fa423e 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem6.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem6.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem6.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -29,8 +29,8 @@ public class Problem6 extends Problem{ private static final int START_NUM = 1; //The first number that needs to be counted private static final int END_NUM = 100; //The last number that needs to be counted //Instance variables - private long sumOfSquares; //Holds the sum of the squares of all the numbers - private long squareOfSum; //Holds the square of the sum of all the numbers + protected long sumOfSquares; //Holds the sum of the squares of all the numbers + protected long squareOfSum; //Holds the square of the sum of all the numbers //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem67.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem67.java index cdd9268..ba9d07b 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem67.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem67.java @@ -1,114 +1,12 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem67.java //Matthew Ellison // Created: 03-26-19 -//Modified: 07-03-21 +//Modified: 06-30-23 //Find the maximum total from top to bottom -/* -59 -73 41 -52 40 09 -26 53 06 34 -10 51 87 86 81 -61 95 66 57 25 68 -90 81 80 38 92 67 73 -30 28 51 76 81 18 75 44 -84 14 95 87 62 81 17 78 58 -21 46 71 58 02 79 62 39 31 09 -56 34 35 53 78 31 81 18 90 93 15 -78 53 04 21 84 93 32 13 97 11 37 51 -45 03 81 79 05 18 78 86 13 30 63 99 95 -39 87 96 28 03 38 42 17 82 87 58 07 22 57 -06 17 51 17 07 93 09 07 75 97 95 78 87 08 53 -67 66 59 60 88 99 94 65 55 77 55 34 27 53 78 28 -76 40 41 04 87 16 09 42 75 69 23 97 30 60 10 79 87 -12 10 44 26 21 36 32 84 98 60 13 12 36 16 63 31 91 35 -70 39 06 05 55 27 38 48 28 22 34 35 62 62 15 14 94 89 86 -66 56 68 84 96 21 34 34 34 81 62 40 65 54 62 05 98 03 02 60 -38 89 46 37 99 54 34 53 36 14 70 26 02 90 45 13 31 61 83 73 47 -36 10 63 96 60 49 41 05 37 42 14 58 84 93 96 17 09 43 05 43 06 59 -66 57 87 57 61 28 37 51 84 73 79 15 39 95 88 87 43 39 11 86 77 74 18 -54 42 05 79 30 49 99 73 46 37 50 02 45 09 54 52 27 95 27 65 19 45 26 45 -71 39 17 78 76 29 52 90 18 99 78 19 35 62 71 19 23 65 93 85 49 33 75 09 02 -33 24 47 61 60 55 32 88 57 55 91 54 46 57 07 77 98 52 80 99 24 25 46 78 79 05 -92 09 13 55 10 67 26 78 76 82 63 49 51 31 24 68 05 57 07 54 69 21 67 43 17 63 12 -24 59 06 08 98 74 66 26 61 60 13 03 09 09 24 30 71 08 88 70 72 70 29 90 11 82 41 34 -66 82 67 04 36 60 92 77 91 85 62 49 59 61 30 90 29 94 26 41 89 04 53 22 83 41 09 74 90 -48 28 26 37 28 52 77 26 51 32 18 98 79 36 62 13 17 08 19 54 89 29 73 68 42 14 08 16 70 37 -37 60 69 70 72 71 09 59 13 60 38 13 57 36 09 30 43 89 30 39 15 02 44 73 05 73 26 63 56 86 12 -55 55 85 50 62 99 84 77 28 85 03 21 27 22 19 26 82 69 54 04 13 07 85 14 01 15 70 59 89 95 10 19 -04 09 31 92 91 38 92 86 98 75 21 05 64 42 62 84 36 20 73 42 21 23 22 51 51 79 25 45 85 53 03 43 22 -75 63 02 49 14 12 89 14 60 78 92 16 44 82 38 30 72 11 46 52 90 27 08 65 78 03 85 41 57 79 39 52 33 48 -78 27 56 56 39 13 19 43 86 72 58 95 39 07 04 34 21 98 39 15 39 84 89 69 84 46 37 57 59 35 59 50 26 15 93 -42 89 36 27 78 91 24 11 17 41 05 94 07 69 51 96 03 96 47 90 90 45 91 20 50 56 10 32 36 49 04 53 85 92 25 65 -52 09 61 30 61 97 66 21 96 92 98 90 06 34 96 60 32 69 68 33 75 84 18 31 71 50 84 63 03 03 19 11 28 42 75 45 45 -61 31 61 68 96 34 49 39 05 71 76 59 62 67 06 47 96 99 34 21 32 47 52 07 71 60 42 72 94 56 82 83 84 40 94 87 82 46 -01 20 60 14 17 38 26 78 66 81 45 95 18 51 98 81 48 16 53 88 37 52 69 95 72 93 22 34 98 20 54 27 73 61 56 63 60 34 63 -93 42 94 83 47 61 27 51 79 79 45 01 44 73 31 70 83 42 88 25 53 51 30 15 65 94 80 44 61 84 12 77 02 62 02 65 94 42 14 94 -32 73 09 67 68 29 74 98 10 19 85 48 38 31 85 67 53 93 93 77 47 67 39 72 94 53 18 43 77 40 78 32 29 59 24 06 02 83 50 60 66 -32 01 44 30 16 51 15 81 98 15 10 62 86 79 50 62 45 60 70 38 31 85 65 61 64 06 69 84 14 22 56 43 09 48 66 69 83 91 60 40 36 61 -92 48 22 99 15 95 64 43 01 16 94 02 99 19 17 69 11 58 97 56 89 31 77 45 67 96 12 73 08 20 36 47 81 44 50 64 68 85 40 81 85 52 09 -91 35 92 45 32 84 62 15 19 64 21 66 06 01 52 80 62 59 12 25 88 28 91 50 40 16 22 99 92 79 87 51 21 77 74 77 07 42 38 42 74 83 02 05 -46 19 77 66 24 18 05 32 02 84 31 99 92 58 96 72 91 36 62 99 55 29 53 42 12 37 26 58 89 50 66 19 82 75 12 48 24 87 91 85 02 07 03 76 86 -99 98 84 93 07 17 33 61 92 20 66 60 24 66 40 30 67 05 37 29 24 96 03 27 70 62 13 04 45 47 59 88 43 20 66 15 46 92 30 04 71 66 78 70 53 99 -67 60 38 06 88 04 17 72 10 99 71 07 42 25 54 05 26 64 91 50 45 71 06 30 67 48 69 82 08 56 80 67 18 46 66 63 01 20 08 80 47 07 91 16 03 79 87 -18 54 78 49 80 48 77 40 68 23 60 88 58 80 33 57 11 69 55 53 64 02 94 49 60 92 16 35 81 21 82 96 25 24 96 18 02 05 49 03 50 77 06 32 84 27 18 38 -68 01 50 04 03 21 42 94 53 24 89 05 92 26 52 36 68 11 85 01 04 42 02 45 15 06 50 04 53 73 25 74 81 88 98 21 67 84 79 97 99 20 95 04 40 46 02 58 87 -94 10 02 78 88 52 21 03 88 60 06 53 49 71 20 91 12 65 07 49 21 22 11 41 58 99 36 16 09 48 17 24 52 36 23 15 72 16 84 56 02 99 43 76 81 71 29 39 49 17 -64 39 59 84 86 16 17 66 03 09 43 06 64 18 63 29 68 06 23 07 87 14 26 35 17 12 98 41 53 64 78 18 98 27 28 84 80 67 75 62 10 11 76 90 54 10 05 54 41 39 66 -43 83 18 37 32 31 52 29 95 47 08 76 35 11 04 53 35 43 34 10 52 57 12 36 20 39 40 55 78 44 07 31 38 26 08 15 56 88 86 01 52 62 10 24 32 05 60 65 53 28 57 99 -03 50 03 52 07 73 49 92 66 80 01 46 08 67 25 36 73 93 07 42 25 53 13 96 76 83 87 90 54 89 78 22 78 91 73 51 69 09 79 94 83 53 09 40 69 62 10 79 49 47 03 81 30 -71 54 73 33 51 76 59 54 79 37 56 45 84 17 62 21 98 69 41 95 65 24 39 37 62 03 24 48 54 64 46 82 71 78 33 67 09 16 96 68 52 74 79 68 32 21 13 78 96 60 09 69 20 36 -73 26 21 44 46 38 17 83 65 98 07 23 52 46 61 97 33 13 60 31 70 15 36 77 31 58 56 93 75 68 21 36 69 53 90 75 25 82 39 50 65 94 29 30 11 33 11 13 96 02 56 47 07 49 02 -76 46 73 30 10 20 60 70 14 56 34 26 37 39 48 24 55 76 84 91 39 86 95 61 50 14 53 93 64 67 37 31 10 84 42 70 48 20 10 72 60 61 84 79 69 65 99 73 89 25 85 48 92 56 97 16 -03 14 80 27 22 30 44 27 67 75 79 32 51 54 81 29 65 14 19 04 13 82 04 91 43 40 12 52 29 99 07 76 60 25 01 07 61 71 37 92 40 47 99 66 57 01 43 44 22 40 53 53 09 69 26 81 07 -49 80 56 90 93 87 47 13 75 28 87 23 72 79 32 18 27 20 28 10 37 59 21 18 70 04 79 96 03 31 45 71 81 06 14 18 17 05 31 50 92 79 23 47 09 39 47 91 43 54 69 47 42 95 62 46 32 85 -37 18 62 85 87 28 64 05 77 51 47 26 30 65 05 70 65 75 59 80 42 52 25 20 44 10 92 17 71 95 52 14 77 13 24 55 11 65 26 91 01 30 63 15 49 48 41 17 67 47 03 68 20 90 98 32 04 40 68 -90 51 58 60 06 55 23 68 05 19 76 94 82 36 96 43 38 90 87 28 33 83 05 17 70 83 96 93 06 04 78 47 80 06 23 84 75 23 87 72 99 14 50 98 92 38 90 64 61 58 76 94 36 66 87 80 51 35 61 38 -57 95 64 06 53 36 82 51 40 33 47 14 07 98 78 65 39 58 53 06 50 53 04 69 40 68 36 69 75 78 75 60 03 32 39 24 74 47 26 90 13 40 44 71 90 76 51 24 36 50 25 45 70 80 61 80 61 43 90 64 11 -18 29 86 56 68 42 79 10 42 44 30 12 96 18 23 18 52 59 02 99 67 46 60 86 43 38 55 17 44 93 42 21 55 14 47 34 55 16 49 24 23 29 96 51 55 10 46 53 27 92 27 46 63 57 30 65 43 27 21 20 24 83 -81 72 93 19 69 52 48 01 13 83 92 69 20 48 69 59 20 62 05 42 28 89 90 99 32 72 84 17 08 87 36 03 60 31 36 36 81 26 97 36 48 54 56 56 27 16 91 08 23 11 87 99 33 47 02 14 44 73 70 99 43 35 33 -90 56 61 86 56 12 70 59 63 32 01 15 81 47 71 76 95 32 65 80 54 70 34 51 40 45 33 04 64 55 78 68 88 47 31 47 68 87 03 84 23 44 89 72 35 08 31 76 63 26 90 85 96 67 65 91 19 14 17 86 04 71 32 95 -37 13 04 22 64 37 37 28 56 62 86 33 07 37 10 44 52 82 52 06 19 52 57 75 90 26 91 24 06 21 14 67 76 30 46 14 35 89 89 41 03 64 56 97 87 63 22 34 03 79 17 45 11 53 25 56 96 61 23 18 63 31 37 37 47 -77 23 26 70 72 76 77 04 28 64 71 69 14 85 96 54 95 48 06 62 99 83 86 77 97 75 71 66 30 19 57 90 33 01 60 61 14 12 90 99 32 77 56 41 18 14 87 49 10 14 90 64 18 50 21 74 14 16 88 05 45 73 82 47 74 44 -22 97 41 13 34 31 54 61 56 94 03 24 59 27 98 77 04 09 37 40 12 26 87 09 71 70 07 18 64 57 80 21 12 71 83 94 60 39 73 79 73 19 97 32 64 29 41 07 48 84 85 67 12 74 95 20 24 52 41 67 56 61 29 93 35 72 69 -72 23 63 66 01 11 07 30 52 56 95 16 65 26 83 90 50 74 60 18 16 48 43 77 37 11 99 98 30 94 91 26 62 73 45 12 87 73 47 27 01 88 66 99 21 41 95 80 02 53 23 32 61 48 32 43 43 83 14 66 95 91 19 81 80 67 25 88 -08 62 32 18 92 14 83 71 37 96 11 83 39 99 05 16 23 27 10 67 02 25 44 11 55 31 46 64 41 56 44 74 26 81 51 31 45 85 87 09 81 95 22 28 76 69 46 48 64 87 67 76 27 89 31 11 74 16 62 03 60 94 42 47 09 34 94 93 72 -56 18 90 18 42 17 42 32 14 86 06 53 33 95 99 35 29 15 44 20 49 59 25 54 34 59 84 21 23 54 35 90 78 16 93 13 37 88 54 19 86 67 68 55 66 84 65 42 98 37 87 56 33 28 58 38 28 38 66 27 52 21 81 15 08 22 97 32 85 27 -91 53 40 28 13 34 91 25 01 63 50 37 22 49 71 58 32 28 30 18 68 94 23 83 63 62 94 76 80 41 90 22 82 52 29 12 18 56 10 08 35 14 37 57 23 65 67 40 72 39 93 39 70 89 40 34 07 46 94 22 20 05 53 64 56 30 05 56 61 88 27 -23 95 11 12 37 69 68 24 66 10 87 70 43 50 75 07 62 41 83 58 95 93 89 79 45 39 02 22 05 22 95 43 62 11 68 29 17 40 26 44 25 71 87 16 70 85 19 25 59 94 90 41 41 80 61 70 55 60 84 33 95 76 42 63 15 09 03 40 38 12 03 32 -09 84 56 80 61 55 85 97 16 94 82 94 98 57 84 30 84 48 93 90 71 05 95 90 73 17 30 98 40 64 65 89 07 79 09 19 56 36 42 30 23 69 73 72 07 05 27 61 24 31 43 48 71 84 21 28 26 65 65 59 65 74 77 20 10 81 61 84 95 08 52 23 70 -47 81 28 09 98 51 67 64 35 51 59 36 92 82 77 65 80 24 72 53 22 07 27 10 21 28 30 22 48 82 80 48 56 20 14 43 18 25 50 95 90 31 77 08 09 48 44 80 90 22 93 45 82 17 13 96 25 26 08 73 34 99 06 49 24 06 83 51 40 14 15 10 25 01 -54 25 10 81 30 64 24 74 75 80 36 75 82 60 22 69 72 91 45 67 03 62 79 54 89 74 44 83 64 96 66 73 44 30 74 50 37 05 09 97 70 01 60 46 37 91 39 75 75 18 58 52 72 78 51 81 86 52 08 97 01 46 43 66 98 62 81 18 70 93 73 08 32 46 34 -96 80 82 07 59 71 92 53 19 20 88 66 03 26 26 10 24 27 50 82 94 73 63 08 51 33 22 45 19 13 58 33 90 15 22 50 36 13 55 06 35 47 82 52 33 61 36 27 28 46 98 14 73 20 73 32 16 26 80 53 47 66 76 38 94 45 02 01 22 52 47 96 64 58 52 39 -88 46 23 39 74 63 81 64 20 90 33 33 76 55 58 26 10 46 42 26 74 74 12 83 32 43 09 02 73 55 86 54 85 34 28 23 29 79 91 62 47 41 82 87 99 22 48 90 20 05 96 75 95 04 43 28 81 39 81 01 28 42 78 25 39 77 90 57 58 98 17 36 73 22 63 74 51 -29 39 74 94 95 78 64 24 38 86 63 87 93 06 70 92 22 16 80 64 29 52 20 27 23 50 14 13 87 15 72 96 81 22 08 49 72 30 70 24 79 31 16 64 59 21 89 34 96 91 48 76 43 53 88 01 57 80 23 81 90 79 58 01 80 87 17 99 86 90 72 63 32 69 14 28 88 69 -37 17 71 95 56 93 71 35 43 45 04 98 92 94 84 96 11 30 31 27 31 60 92 03 48 05 98 91 86 94 35 90 90 08 48 19 33 28 68 37 59 26 65 96 50 68 22 07 09 49 34 31 77 49 43 06 75 17 81 87 61 79 52 26 27 72 29 50 07 98 86 01 17 10 46 64 24 18 56 -51 30 25 94 88 85 79 91 40 33 63 84 49 67 98 92 15 26 75 19 82 05 18 78 65 93 61 48 91 43 59 41 70 51 22 15 92 81 67 91 46 98 11 11 65 31 66 10 98 65 83 21 05 56 05 98 73 67 46 74 69 34 08 30 05 52 07 98 32 95 30 94 65 50 24 63 28 81 99 57 -19 23 61 36 09 89 71 98 65 17 30 29 89 26 79 74 94 11 44 48 97 54 81 55 39 66 69 45 28 47 13 86 15 76 74 70 84 32 36 33 79 20 78 14 41 47 89 28 81 05 99 66 81 86 38 26 06 25 13 60 54 55 23 53 27 05 89 25 23 11 13 54 59 54 56 34 16 24 53 44 06 -13 40 57 72 21 15 60 08 04 19 11 98 34 45 09 97 86 71 03 15 56 19 15 44 97 31 90 04 87 87 76 08 12 30 24 62 84 28 12 85 82 53 99 52 13 94 06 65 97 86 09 50 94 68 69 74 30 67 87 94 63 07 78 27 80 36 69 41 06 92 32 78 37 82 30 05 18 87 99 72 19 99 -44 20 55 77 69 91 27 31 28 81 80 27 02 07 97 23 95 98 12 25 75 29 47 71 07 47 78 39 41 59 27 76 13 15 66 61 68 35 69 86 16 53 67 63 99 85 41 56 08 28 33 40 94 76 90 85 31 70 24 65 84 65 99 82 19 25 54 37 21 46 33 02 52 99 51 33 26 04 87 02 08 18 96 -54 42 61 45 91 06 64 79 80 82 32 16 83 63 42 49 19 78 65 97 40 42 14 61 49 34 04 18 25 98 59 30 82 72 26 88 54 36 21 75 03 88 99 53 46 51 55 78 22 94 34 40 68 87 84 25 30 76 25 08 92 84 42 61 40 38 09 99 40 23 29 39 46 55 10 90 35 84 56 70 63 23 91 39 -52 92 03 71 89 07 09 37 68 66 58 20 44 92 51 56 13 71 79 99 26 37 02 06 16 67 36 52 58 16 79 73 56 60 59 27 44 77 94 82 20 50 98 33 09 87 94 37 40 83 64 83 58 85 17 76 53 02 83 52 22 27 39 20 48 92 45 21 09 42 24 23 12 37 52 28 50 78 79 20 86 62 73 20 59 -54 96 80 15 91 90 99 70 10 09 58 90 93 50 81 99 54 38 36 10 30 11 35 84 16 45 82 18 11 97 36 43 96 79 97 65 40 48 23 19 17 31 64 52 65 65 37 32 65 76 99 79 34 65 79 27 55 33 03 01 33 27 61 28 66 08 04 70 49 46 48 83 01 45 19 96 13 81 14 21 31 79 93 85 50 05 -92 92 48 84 59 98 31 53 23 27 15 22 79 95 24 76 05 79 16 93 97 89 38 89 42 83 02 88 94 95 82 21 01 97 48 39 31 78 09 65 50 56 97 61 01 07 65 27 21 23 14 15 80 97 44 78 49 35 33 45 81 74 34 05 31 57 09 38 94 07 69 54 69 32 65 68 46 68 78 90 24 28 49 51 45 86 35 -41 63 89 76 87 31 86 09 46 14 87 82 22 29 47 16 13 10 70 72 82 95 48 64 58 43 13 75 42 69 21 12 67 13 64 85 58 23 98 09 37 76 05 22 31 12 66 50 29 99 86 72 45 25 10 28 19 06 90 43 29 31 67 79 46 25 74 14 97 35 76 37 65 46 23 82 06 22 30 76 93 66 94 17 96 13 20 72 -63 40 78 08 52 09 90 41 70 28 36 14 46 44 85 96 24 52 58 15 87 37 05 98 99 39 13 61 76 38 44 99 83 74 90 22 53 80 56 98 30 51 63 39 44 30 91 91 04 22 27 73 17 35 53 18 35 45 54 56 27 78 48 13 69 36 44 38 71 25 30 56 15 22 73 43 32 69 59 25 93 83 45 11 34 94 44 39 92 -12 36 56 88 13 96 16 12 55 54 11 47 19 78 17 17 68 81 77 51 42 55 99 85 66 27 81 79 93 42 65 61 69 74 14 01 18 56 12 01 58 37 91 22 42 66 83 25 19 04 96 41 25 45 18 69 96 88 36 93 10 12 98 32 44 83 83 04 72 91 04 27 73 07 34 37 71 60 59 31 01 54 54 44 96 93 83 36 04 45 -30 18 22 20 42 96 65 79 17 41 55 69 94 81 29 80 91 31 85 25 47 26 43 49 02 99 34 67 99 76 16 14 15 93 08 32 99 44 61 77 67 50 43 55 87 55 53 72 17 46 62 25 50 99 73 05 93 48 17 31 70 80 59 09 44 59 45 13 74 66 58 94 87 73 16 14 85 38 74 99 64 23 79 28 71 42 20 37 82 31 23 -51 96 39 65 46 71 56 13 29 68 53 86 45 33 51 49 12 91 21 21 76 85 02 17 98 15 46 12 60 21 88 30 92 83 44 59 42 50 27 88 46 86 94 73 45 54 23 24 14 10 94 21 20 34 23 51 04 83 99 75 90 63 60 16 22 33 83 70 11 32 10 50 29 30 83 46 11 05 31 17 86 42 49 01 44 63 28 60 07 78 95 40 -44 61 89 59 04 49 51 27 69 71 46 76 44 04 09 34 56 39 15 06 94 91 75 90 65 27 56 23 74 06 23 33 36 69 14 39 05 34 35 57 33 22 76 46 56 10 61 65 98 09 16 69 04 62 65 18 99 76 49 18 72 66 73 83 82 40 76 31 89 91 27 88 17 35 41 35 32 51 32 67 52 68 74 85 80 57 07 11 62 66 47 22 67 -65 37 19 97 26 17 16 24 24 17 50 37 64 82 24 36 32 11 68 34 69 31 32 89 79 93 96 68 49 90 14 23 04 04 67 99 81 74 70 74 36 96 68 09 64 39 88 35 54 89 96 58 66 27 88 97 32 14 06 35 78 20 71 06 85 66 57 02 58 91 72 05 29 56 73 48 86 52 09 93 22 57 79 42 12 01 31 68 17 59 63 76 07 77 -73 81 14 13 17 20 11 09 01 83 08 85 91 70 84 63 62 77 37 07 47 01 59 95 39 69 39 21 99 09 87 02 97 16 92 36 74 71 90 66 33 73 73 75 52 91 11 12 26 53 05 26 26 48 61 50 90 65 01 87 42 47 74 35 22 73 24 26 56 70 52 05 48 41 31 18 83 27 21 39 80 85 26 08 44 02 71 07 63 22 05 52 19 08 20 -17 25 21 11 72 93 33 49 64 23 53 82 03 13 91 65 85 02 40 05 42 31 77 42 05 36 06 54 04 58 07 76 87 83 25 57 66 12 74 33 85 37 74 32 20 69 03 97 91 68 82 44 19 14 89 28 85 85 80 53 34 87 58 98 88 78 48 65 98 40 11 57 10 67 70 81 60 79 74 72 97 59 79 47 30 20 54 80 89 91 14 05 33 36 79 39 -60 85 59 39 60 07 57 76 77 92 06 35 15 72 23 41 45 52 95 18 64 79 86 53 56 31 69 11 91 31 84 50 44 82 22 81 41 40 30 42 30 91 48 94 74 76 64 58 74 25 96 57 14 19 03 99 28 83 15 75 99 01 89 85 79 50 03 95 32 67 44 08 07 41 62 64 29 20 14 76 26 55 48 71 69 66 19 72 44 25 14 01 48 74 12 98 07 -64 66 84 24 18 16 27 48 20 14 47 69 30 86 48 40 23 16 61 21 51 50 26 47 35 33 91 28 78 64 43 68 04 79 51 08 19 60 52 95 06 68 46 86 35 97 27 58 04 65 30 58 99 12 12 75 91 39 50 31 42 64 70 04 46 07 98 73 98 93 37 89 77 91 64 71 64 65 66 21 78 62 81 74 42 20 83 70 73 95 78 45 92 27 34 53 71 15 -30 11 85 31 34 71 13 48 05 14 44 03 19 67 23 73 19 57 06 90 94 72 57 69 81 62 59 68 88 57 55 69 49 13 07 87 97 80 89 05 71 05 05 26 38 40 16 62 45 99 18 38 98 24 21 26 62 74 69 04 85 57 77 35 58 67 91 79 79 57 86 28 66 34 72 51 76 78 36 95 63 90 08 78 47 63 45 31 22 70 52 48 79 94 15 77 61 67 68 -23 33 44 81 80 92 93 75 94 88 23 61 39 76 22 03 28 94 32 06 49 65 41 34 18 23 08 47 62 60 03 63 33 13 80 52 31 54 73 43 70 26 16 69 57 87 83 31 03 93 70 81 47 95 77 44 29 68 39 51 56 59 63 07 25 70 07 77 43 53 64 03 94 42 95 39 18 01 66 21 16 97 20 50 90 16 70 10 95 69 29 06 25 61 41 26 15 59 63 35 -*/ //This is done using a breadth first search //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2021 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -126,116 +24,11 @@ package com.mattrixwv.project_euler.problems; -import java.util.ArrayList; -import java.util.Arrays; - - public class Problem67 extends Problem18{ //Setup the list of numbers to check - static{ - list = new ArrayList>( - Arrays.asList( - new ArrayList(Arrays.asList(59)), - new ArrayList(Arrays.asList(73, 41)), - new ArrayList(Arrays.asList(52, 40, 9)), - new ArrayList(Arrays.asList(26, 53, 06, 34)), - new ArrayList(Arrays.asList(10, 51, 87, 86, 81)), - new ArrayList(Arrays.asList(61, 95, 66, 57, 25, 68)), - new ArrayList(Arrays.asList(90, 81, 80, 38, 92, 67, 73)), - new ArrayList(Arrays.asList(30, 28, 51, 76, 81, 18, 75, 44)), - new ArrayList(Arrays.asList(84, 14, 95, 87, 62, 81, 17, 78, 58)), - new ArrayList(Arrays.asList(21, 46, 71, 58, 02, 79, 62, 39, 31, 9)), - new ArrayList(Arrays.asList(56, 34, 35, 53, 78, 31, 81, 18, 90, 93, 15)), - new ArrayList(Arrays.asList(78, 53, 04, 21, 84, 93, 32, 13, 97, 11, 37, 51)), - new ArrayList(Arrays.asList(45, 03, 81, 79, 05, 18, 78, 86, 13, 30, 63, 99, 95)), - new ArrayList(Arrays.asList(39, 87, 96, 28, 03, 38, 42, 17, 82, 87, 58, 07, 22, 57)), - new ArrayList(Arrays.asList(06, 17, 51, 17, 07, 93, 9, 07, 75, 97, 95, 78, 87, 8, 53)), - new ArrayList(Arrays.asList(67, 66, 59, 60, 88, 99, 94, 65, 55, 77, 55, 34, 27, 53, 78, 28)), - new ArrayList(Arrays.asList(76, 40, 41, 04, 87, 16, 9, 42, 75, 69, 23, 97, 30, 60, 10, 79, 87)), - new ArrayList(Arrays.asList(12, 10, 44, 26, 21, 36, 32, 84, 98, 60, 13, 12, 36, 16, 63, 31, 91, 35)), - new ArrayList(Arrays.asList(70, 39, 06, 05, 55, 27, 38, 48, 28, 22, 34, 35, 62, 62, 15, 14, 94, 89, 86)), - new ArrayList(Arrays.asList(66, 56, 68, 84, 96, 21, 34, 34, 34, 81, 62, 40, 65, 54, 62, 05, 98, 03, 02, 60)), - new ArrayList(Arrays.asList(38, 89, 46, 37, 99, 54, 34, 53, 36, 14, 70, 26, 02, 90, 45, 13, 31, 61, 83, 73, 47)), - new ArrayList(Arrays.asList(36, 10, 63, 96, 60, 49, 41, 05, 37, 42, 14, 58, 84, 93, 96, 17, 9, 43, 05, 43, 06, 59)), - new ArrayList(Arrays.asList(66, 57, 87, 57, 61, 28, 37, 51, 84, 73, 79, 15, 39, 95, 88, 87, 43, 39, 11, 86, 77, 74, 18)), - new ArrayList(Arrays.asList(54, 42, 05, 79, 30, 49, 99, 73, 46, 37, 50, 02, 45, 9, 54, 52, 27, 95, 27, 65, 19, 45, 26, 45)), - new ArrayList(Arrays.asList(71, 39, 17, 78, 76, 29, 52, 90, 18, 99, 78, 19, 35, 62, 71, 19, 23, 65, 93, 85, 49, 33, 75, 9, 02)), - new ArrayList(Arrays.asList(33, 24, 47, 61, 60, 55, 32, 88, 57, 55, 91, 54, 46, 57, 07, 77, 98, 52, 80, 99, 24, 25, 46, 78, 79, 05)), - new ArrayList(Arrays.asList(92, 9, 13, 55, 10, 67, 26, 78, 76, 82, 63, 49, 51, 31, 24, 68, 05, 57, 07, 54, 69, 21, 67, 43, 17, 63, 12)), - new ArrayList(Arrays.asList(24, 59, 06, 8, 98, 74, 66, 26, 61, 60, 13, 03, 9, 9, 24, 30, 71, 8, 88, 70, 72, 70, 29, 90, 11, 82, 41, 34)), - new ArrayList(Arrays.asList(66, 82, 67, 04, 36, 60, 92, 77, 91, 85, 62, 49, 59, 61, 30, 90, 29, 94, 26, 41, 89, 04, 53, 22, 83, 41, 9, 74, 90)), - new ArrayList(Arrays.asList(48, 28, 26, 37, 28, 52, 77, 26, 51, 32, 18, 98, 79, 36, 62, 13, 17, 8, 19, 54, 89, 29, 73, 68, 42, 14, 8, 16, 70, 37)), - new ArrayList(Arrays.asList(37, 60, 69, 70, 72, 71, 9, 59, 13, 60, 38, 13, 57, 36, 9, 30, 43, 89, 30, 39, 15, 02, 44, 73, 05, 73, 26, 63, 56, 86, 12)), - new ArrayList(Arrays.asList(55, 55, 85, 50, 62, 99, 84, 77, 28, 85, 03, 21, 27, 22, 19, 26, 82, 69, 54, 04, 13, 07, 85, 14, 01, 15, 70, 59, 89, 95, 10, 19)), - new ArrayList(Arrays.asList(04, 9, 31, 92, 91, 38, 92, 86, 98, 75, 21, 05, 64, 42, 62, 84, 36, 20, 73, 42, 21, 23, 22, 51, 51, 79, 25, 45, 85, 53, 03, 43, 22)), - new ArrayList(Arrays.asList(75, 63, 02, 49, 14, 12, 89, 14, 60, 78, 92, 16, 44, 82, 38, 30, 72, 11, 46, 52, 90, 27, 8, 65, 78, 03, 85, 41, 57, 79, 39, 52, 33, 48)), - new ArrayList(Arrays.asList(78, 27, 56, 56, 39, 13, 19, 43, 86, 72, 58, 95, 39, 07, 04, 34, 21, 98, 39, 15, 39, 84, 89, 69, 84, 46, 37, 57, 59, 35, 59, 50, 26, 15, 93)), - new ArrayList(Arrays.asList(42, 89, 36, 27, 78, 91, 24, 11, 17, 41, 05, 94, 07, 69, 51, 96, 03, 96, 47, 90, 90, 45, 91, 20, 50, 56, 10, 32, 36, 49, 04, 53, 85, 92, 25, 65)), - new ArrayList(Arrays.asList(52, 9, 61, 30, 61, 97, 66, 21, 96, 92, 98, 90, 06, 34, 96, 60, 32, 69, 68, 33, 75, 84, 18, 31, 71, 50, 84, 63, 03, 03, 19, 11, 28, 42, 75, 45, 45)), - new ArrayList(Arrays.asList(61, 31, 61, 68, 96, 34, 49, 39, 05, 71, 76, 59, 62, 67, 06, 47, 96, 99, 34, 21, 32, 47, 52, 07, 71, 60, 42, 72, 94, 56, 82, 83, 84, 40, 94, 87, 82, 46)), - new ArrayList(Arrays.asList(01, 20, 60, 14, 17, 38, 26, 78, 66, 81, 45, 95, 18, 51, 98, 81, 48, 16, 53, 88, 37, 52, 69, 95, 72, 93, 22, 34, 98, 20, 54, 27, 73, 61, 56, 63, 60, 34, 63)), - new ArrayList(Arrays.asList(93, 42, 94, 83, 47, 61, 27, 51, 79, 79, 45, 01, 44, 73, 31, 70, 83, 42, 88, 25, 53, 51, 30, 15, 65, 94, 80, 44, 61, 84, 12, 77, 02, 62, 02, 65, 94, 42, 14, 94)), - new ArrayList(Arrays.asList(32, 73, 9, 67, 68, 29, 74, 98, 10, 19, 85, 48, 38, 31, 85, 67, 53, 93, 93, 77, 47, 67, 39, 72, 94, 53, 18, 43, 77, 40, 78, 32, 29, 59, 24, 06, 02, 83, 50, 60, 66)), - new ArrayList(Arrays.asList(32, 01, 44, 30, 16, 51, 15, 81, 98, 15, 10, 62, 86, 79, 50, 62, 45, 60, 70, 38, 31, 85, 65, 61, 64, 06, 69, 84, 14, 22, 56, 43, 9, 48, 66, 69, 83, 91, 60, 40, 36, 61)), - new ArrayList(Arrays.asList(92, 48, 22, 99, 15, 95, 64, 43, 01, 16, 94, 02, 99, 19, 17, 69, 11, 58, 97, 56, 89, 31, 77, 45, 67, 96, 12, 73, 8, 20, 36, 47, 81, 44, 50, 64, 68, 85, 40, 81, 85, 52, 9)), - new ArrayList(Arrays.asList(91, 35, 92, 45, 32, 84, 62, 15, 19, 64, 21, 66, 06, 01, 52, 80, 62, 59, 12, 25, 88, 28, 91, 50, 40, 16, 22, 99, 92, 79, 87, 51, 21, 77, 74, 77, 07, 42, 38, 42, 74, 83, 02, 05)), - new ArrayList(Arrays.asList(46, 19, 77, 66, 24, 18, 05, 32, 02, 84, 31, 99, 92, 58, 96, 72, 91, 36, 62, 99, 55, 29, 53, 42, 12, 37, 26, 58, 89, 50, 66, 19, 82, 75, 12, 48, 24, 87, 91, 85, 02, 07, 03, 76, 86)), - new ArrayList(Arrays.asList(99, 98, 84, 93, 07, 17, 33, 61, 92, 20, 66, 60, 24, 66, 40, 30, 67, 05, 37, 29, 24, 96, 03, 27, 70, 62, 13, 04, 45, 47, 59, 88, 43, 20, 66, 15, 46, 92, 30, 04, 71, 66, 78, 70, 53, 99)), - new ArrayList(Arrays.asList(67, 60, 38, 06, 88, 04, 17, 72, 10, 99, 71, 07, 42, 25, 54, 05, 26, 64, 91, 50, 45, 71, 06, 30, 67, 48, 69, 82, 8, 56, 80, 67, 18, 46, 66, 63, 01, 20, 8, 80, 47, 07, 91, 16, 03, 79, 87)), - new ArrayList(Arrays.asList(18, 54, 78, 49, 80, 48, 77, 40, 68, 23, 60, 88, 58, 80, 33, 57, 11, 69, 55, 53, 64, 02, 94, 49, 60, 92, 16, 35, 81, 21, 82, 96, 25, 24, 96, 18, 02, 05, 49, 03, 50, 77, 06, 32, 84, 27, 18, 38)), - new ArrayList(Arrays.asList(68, 01, 50, 04, 03, 21, 42, 94, 53, 24, 89, 05, 92, 26, 52, 36, 68, 11, 85, 01, 04, 42, 02, 45, 15, 06, 50, 04, 53, 73, 25, 74, 81, 88, 98, 21, 67, 84, 79, 97, 99, 20, 95, 04, 40, 46, 02, 58, 87)), - new ArrayList(Arrays.asList(94, 10, 02, 78, 88, 52, 21, 03, 88, 60, 06, 53, 49, 71, 20, 91, 12, 65, 07, 49, 21, 22, 11, 41, 58, 99, 36, 16, 9, 48, 17, 24, 52, 36, 23, 15, 72, 16, 84, 56, 02, 99, 43, 76, 81, 71, 29, 39, 49, 17)), - new ArrayList(Arrays.asList(64, 39, 59, 84, 86, 16, 17, 66, 03, 9, 43, 06, 64, 18, 63, 29, 68, 06, 23, 07, 87, 14, 26, 35, 17, 12, 98, 41, 53, 64, 78, 18, 98, 27, 28, 84, 80, 67, 75, 62, 10, 11, 76, 90, 54, 10, 05, 54, 41, 39, 66)), - new ArrayList(Arrays.asList(43, 83, 18, 37, 32, 31, 52, 29, 95, 47, 8, 76, 35, 11, 04, 53, 35, 43, 34, 10, 52, 57, 12, 36, 20, 39, 40, 55, 78, 44, 07, 31, 38, 26, 8, 15, 56, 88, 86, 01, 52, 62, 10, 24, 32, 05, 60, 65, 53, 28, 57, 99)), - new ArrayList(Arrays.asList(03, 50, 03, 52, 07, 73, 49, 92, 66, 80, 01, 46, 8, 67, 25, 36, 73, 93, 07, 42, 25, 53, 13, 96, 76, 83, 87, 90, 54, 89, 78, 22, 78, 91, 73, 51, 69, 9, 79, 94, 83, 53, 9, 40, 69, 62, 10, 79, 49, 47, 03, 81, 30)), - new ArrayList(Arrays.asList(71, 54, 73, 33, 51, 76, 59, 54, 79, 37, 56, 45, 84, 17, 62, 21, 98, 69, 41, 95, 65, 24, 39, 37, 62, 03, 24, 48, 54, 64, 46, 82, 71, 78, 33, 67, 9, 16, 96, 68, 52, 74, 79, 68, 32, 21, 13, 78, 96, 60, 9, 69, 20, 36)), - new ArrayList(Arrays.asList(73, 26, 21, 44, 46, 38, 17, 83, 65, 98, 07, 23, 52, 46, 61, 97, 33, 13, 60, 31, 70, 15, 36, 77, 31, 58, 56, 93, 75, 68, 21, 36, 69, 53, 90, 75, 25, 82, 39, 50, 65, 94, 29, 30, 11, 33, 11, 13, 96, 02, 56, 47, 07, 49, 02)), - new ArrayList(Arrays.asList(76, 46, 73, 30, 10, 20, 60, 70, 14, 56, 34, 26, 37, 39, 48, 24, 55, 76, 84, 91, 39, 86, 95, 61, 50, 14, 53, 93, 64, 67, 37, 31, 10, 84, 42, 70, 48, 20, 10, 72, 60, 61, 84, 79, 69, 65, 99, 73, 89, 25, 85, 48, 92, 56, 97, 16)), - new ArrayList(Arrays.asList(03, 14, 80, 27, 22, 30, 44, 27, 67, 75, 79, 32, 51, 54, 81, 29, 65, 14, 19, 04, 13, 82, 04, 91, 43, 40, 12, 52, 29, 99, 07, 76, 60, 25, 01, 07, 61, 71, 37, 92, 40, 47, 99, 66, 57, 01, 43, 44, 22, 40, 53, 53, 9, 69, 26, 81, 07)), - new ArrayList(Arrays.asList(49, 80, 56, 90, 93, 87, 47, 13, 75, 28, 87, 23, 72, 79, 32, 18, 27, 20, 28, 10, 37, 59, 21, 18, 70, 04, 79, 96, 03, 31, 45, 71, 81, 06, 14, 18, 17, 05, 31, 50, 92, 79, 23, 47, 9, 39, 47, 91, 43, 54, 69, 47, 42, 95, 62, 46, 32, 85)), - new ArrayList(Arrays.asList(37, 18, 62, 85, 87, 28, 64, 05, 77, 51, 47, 26, 30, 65, 05, 70, 65, 75, 59, 80, 42, 52, 25, 20, 44, 10, 92, 17, 71, 95, 52, 14, 77, 13, 24, 55, 11, 65, 26, 91, 01, 30, 63, 15, 49, 48, 41, 17, 67, 47, 03, 68, 20, 90, 98, 32, 04, 40, 68)), - new ArrayList(Arrays.asList(90, 51, 58, 60, 06, 55, 23, 68, 05, 19, 76, 94, 82, 36, 96, 43, 38, 90, 87, 28, 33, 83, 05, 17, 70, 83, 96, 93, 06, 04, 78, 47, 80, 06, 23, 84, 75, 23, 87, 72, 99, 14, 50, 98, 92, 38, 90, 64, 61, 58, 76, 94, 36, 66, 87, 80, 51, 35, 61, 38)), - new ArrayList(Arrays.asList(57, 95, 64, 06, 53, 36, 82, 51, 40, 33, 47, 14, 07, 98, 78, 65, 39, 58, 53, 06, 50, 53, 04, 69, 40, 68, 36, 69, 75, 78, 75, 60, 03, 32, 39, 24, 74, 47, 26, 90, 13, 40, 44, 71, 90, 76, 51, 24, 36, 50, 25, 45, 70, 80, 61, 80, 61, 43, 90, 64, 11)), - new ArrayList(Arrays.asList(18, 29, 86, 56, 68, 42, 79, 10, 42, 44, 30, 12, 96, 18, 23, 18, 52, 59, 02, 99, 67, 46, 60, 86, 43, 38, 55, 17, 44, 93, 42, 21, 55, 14, 47, 34, 55, 16, 49, 24, 23, 29, 96, 51, 55, 10, 46, 53, 27, 92, 27, 46, 63, 57, 30, 65, 43, 27, 21, 20, 24, 83)), - new ArrayList(Arrays.asList(81, 72, 93, 19, 69, 52, 48, 01, 13, 83, 92, 69, 20, 48, 69, 59, 20, 62, 05, 42, 28, 89, 90, 99, 32, 72, 84, 17, 8, 87, 36, 03, 60, 31, 36, 36, 81, 26, 97, 36, 48, 54, 56, 56, 27, 16, 91, 8, 23, 11, 87, 99, 33, 47, 02, 14, 44, 73, 70, 99, 43, 35, 33)), - new ArrayList(Arrays.asList(90, 56, 61, 86, 56, 12, 70, 59, 63, 32, 01, 15, 81, 47, 71, 76, 95, 32, 65, 80, 54, 70, 34, 51, 40, 45, 33, 04, 64, 55, 78, 68, 88, 47, 31, 47, 68, 87, 03, 84, 23, 44, 89, 72, 35, 8, 31, 76, 63, 26, 90, 85, 96, 67, 65, 91, 19, 14, 17, 86, 04, 71, 32, 95)), - new ArrayList(Arrays.asList(37, 13, 04, 22, 64, 37, 37, 28, 56, 62, 86, 33, 07, 37, 10, 44, 52, 82, 52, 06, 19, 52, 57, 75, 90, 26, 91, 24, 06, 21, 14, 67, 76, 30, 46, 14, 35, 89, 89, 41, 03, 64, 56, 97, 87, 63, 22, 34, 03, 79, 17, 45, 11, 53, 25, 56, 96, 61, 23, 18, 63, 31, 37, 37, 47)), - new ArrayList(Arrays.asList(77, 23, 26, 70, 72, 76, 77, 04, 28, 64, 71, 69, 14, 85, 96, 54, 95, 48, 06, 62, 99, 83, 86, 77, 97, 75, 71, 66, 30, 19, 57, 90, 33, 01, 60, 61, 14, 12, 90, 99, 32, 77, 56, 41, 18, 14, 87, 49, 10, 14, 90, 64, 18, 50, 21, 74, 14, 16, 88, 05, 45, 73, 82, 47, 74, 44)), - new ArrayList(Arrays.asList(22, 97, 41, 13, 34, 31, 54, 61, 56, 94, 03, 24, 59, 27, 98, 77, 04, 9, 37, 40, 12, 26, 87, 9, 71, 70, 07, 18, 64, 57, 80, 21, 12, 71, 83, 94, 60, 39, 73, 79, 73, 19, 97, 32, 64, 29, 41, 07, 48, 84, 85, 67, 12, 74, 95, 20, 24, 52, 41, 67, 56, 61, 29, 93, 35, 72, 69)), - new ArrayList(Arrays.asList(72, 23, 63, 66, 01, 11, 07, 30, 52, 56, 95, 16, 65, 26, 83, 90, 50, 74, 60, 18, 16, 48, 43, 77, 37, 11, 99, 98, 30, 94, 91, 26, 62, 73, 45, 12, 87, 73, 47, 27, 01, 88, 66, 99, 21, 41, 95, 80, 02, 53, 23, 32, 61, 48, 32, 43, 43, 83, 14, 66, 95, 91, 19, 81, 80, 67, 25, 88)), - new ArrayList(Arrays.asList( 8, 62, 32, 18, 92, 14, 83, 71, 37, 96, 11, 83, 39, 99, 05, 16, 23, 27, 10, 67, 02, 25, 44, 11, 55, 31, 46, 64, 41, 56, 44, 74, 26, 81, 51, 31, 45, 85, 87, 9, 81, 95, 22, 28, 76, 69, 46, 48, 64, 87, 67, 76, 27, 89, 31, 11, 74, 16, 62, 03, 60, 94, 42, 47, 9, 34, 94, 93, 72)), - new ArrayList(Arrays.asList(56, 18, 90, 18, 42, 17, 42, 32, 14, 86, 06, 53, 33, 95, 99, 35, 29, 15, 44, 20, 49, 59, 25, 54, 34, 59, 84, 21, 23, 54, 35, 90, 78, 16, 93, 13, 37, 88, 54, 19, 86, 67, 68, 55, 66, 84, 65, 42, 98, 37, 87, 56, 33, 28, 58, 38, 28, 38, 66, 27, 52, 21, 81, 15, 8, 22, 97, 32, 85, 27)), - new ArrayList(Arrays.asList(91, 53, 40, 28, 13, 34, 91, 25, 01, 63, 50, 37, 22, 49, 71, 58, 32, 28, 30, 18, 68, 94, 23, 83, 63, 62, 94, 76, 80, 41, 90, 22, 82, 52, 29, 12, 18, 56, 10, 8, 35, 14, 37, 57, 23, 65, 67, 40, 72, 39, 93, 39, 70, 89, 40, 34, 07, 46, 94, 22, 20, 05, 53, 64, 56, 30, 05, 56, 61, 88, 27)), - new ArrayList(Arrays.asList(23, 95, 11, 12, 37, 69, 68, 24, 66, 10, 87, 70, 43, 50, 75, 07, 62, 41, 83, 58, 95, 93, 89, 79, 45, 39, 02, 22, 05, 22, 95, 43, 62, 11, 68, 29, 17, 40, 26, 44, 25, 71, 87, 16, 70, 85, 19, 25, 59, 94, 90, 41, 41, 80, 61, 70, 55, 60, 84, 33, 95, 76, 42, 63, 15, 9, 03, 40, 38, 12, 03, 32)), - new ArrayList(Arrays.asList( 9, 84, 56, 80, 61, 55, 85, 97, 16, 94, 82, 94, 98, 57, 84, 30, 84, 48, 93, 90, 71, 05, 95, 90, 73, 17, 30, 98, 40, 64, 65, 89, 07, 79, 9, 19, 56, 36, 42, 30, 23, 69, 73, 72, 07, 05, 27, 61, 24, 31, 43, 48, 71, 84, 21, 28, 26, 65, 65, 59, 65, 74, 77, 20, 10, 81, 61, 84, 95, 8, 52, 23, 70)), - new ArrayList(Arrays.asList(47, 81, 28, 9, 98, 51, 67, 64, 35, 51, 59, 36, 92, 82, 77, 65, 80, 24, 72, 53, 22, 07, 27, 10, 21, 28, 30, 22, 48, 82, 80, 48, 56, 20, 14, 43, 18, 25, 50, 95, 90, 31, 77, 8, 9, 48, 44, 80, 90, 22, 93, 45, 82, 17, 13, 96, 25, 26, 8, 73, 34, 99, 06, 49, 24, 06, 83, 51, 40, 14, 15, 10, 25, 01)), - new ArrayList(Arrays.asList(54, 25, 10, 81, 30, 64, 24, 74, 75, 80, 36, 75, 82, 60, 22, 69, 72, 91, 45, 67, 03, 62, 79, 54, 89, 74, 44, 83, 64, 96, 66, 73, 44, 30, 74, 50, 37, 05, 9, 97, 70, 01, 60, 46, 37, 91, 39, 75, 75, 18, 58, 52, 72, 78, 51, 81, 86, 52, 8, 97, 01, 46, 43, 66, 98, 62, 81, 18, 70, 93, 73, 8, 32, 46, 34)), - new ArrayList(Arrays.asList(96, 80, 82, 07, 59, 71, 92, 53, 19, 20, 88, 66, 03, 26, 26, 10, 24, 27, 50, 82, 94, 73, 63, 8, 51, 33, 22, 45, 19, 13, 58, 33, 90, 15, 22, 50, 36, 13, 55, 06, 35, 47, 82, 52, 33, 61, 36, 27, 28, 46, 98, 14, 73, 20, 73, 32, 16, 26, 80, 53, 47, 66, 76, 38, 94, 45, 02, 01, 22, 52, 47, 96, 64, 58, 52, 39)), - new ArrayList(Arrays.asList(88, 46, 23, 39, 74, 63, 81, 64, 20, 90, 33, 33, 76, 55, 58, 26, 10, 46, 42, 26, 74, 74, 12, 83, 32, 43, 9, 02, 73, 55, 86, 54, 85, 34, 28, 23, 29, 79, 91, 62, 47, 41, 82, 87, 99, 22, 48, 90, 20, 05, 96, 75, 95, 04, 43, 28, 81, 39, 81, 01, 28, 42, 78, 25, 39, 77, 90, 57, 58, 98, 17, 36, 73, 22, 63, 74, 51)), - new ArrayList(Arrays.asList(29, 39, 74, 94, 95, 78, 64, 24, 38, 86, 63, 87, 93, 06, 70, 92, 22, 16, 80, 64, 29, 52, 20, 27, 23, 50, 14, 13, 87, 15, 72, 96, 81, 22, 8, 49, 72, 30, 70, 24, 79, 31, 16, 64, 59, 21, 89, 34, 96, 91, 48, 76, 43, 53, 88, 01, 57, 80, 23, 81, 90, 79, 58, 01, 80, 87, 17, 99, 86, 90, 72, 63, 32, 69, 14, 28, 88, 69)), - new ArrayList(Arrays.asList(37, 17, 71, 95, 56, 93, 71, 35, 43, 45, 04, 98, 92, 94, 84, 96, 11, 30, 31, 27, 31, 60, 92, 03, 48, 05, 98, 91, 86, 94, 35, 90, 90, 8, 48, 19, 33, 28, 68, 37, 59, 26, 65, 96, 50, 68, 22, 07, 9, 49, 34, 31, 77, 49, 43, 06, 75, 17, 81, 87, 61, 79, 52, 26, 27, 72, 29, 50, 07, 98, 86, 01, 17, 10, 46, 64, 24, 18, 56)), - new ArrayList(Arrays.asList(51, 30, 25, 94, 88, 85, 79, 91, 40, 33, 63, 84, 49, 67, 98, 92, 15, 26, 75, 19, 82, 05, 18, 78, 65, 93, 61, 48, 91, 43, 59, 41, 70, 51, 22, 15, 92, 81, 67, 91, 46, 98, 11, 11, 65, 31, 66, 10, 98, 65, 83, 21, 05, 56, 05, 98, 73, 67, 46, 74, 69, 34, 8, 30, 05, 52, 07, 98, 32, 95, 30, 94, 65, 50, 24, 63, 28, 81, 99, 57)), - new ArrayList(Arrays.asList(19, 23, 61, 36, 9, 89, 71, 98, 65, 17, 30, 29, 89, 26, 79, 74, 94, 11, 44, 48, 97, 54, 81, 55, 39, 66, 69, 45, 28, 47, 13, 86, 15, 76, 74, 70, 84, 32, 36, 33, 79, 20, 78, 14, 41, 47, 89, 28, 81, 05, 99, 66, 81, 86, 38, 26, 06, 25, 13, 60, 54, 55, 23, 53, 27, 05, 89, 25, 23, 11, 13, 54, 59, 54, 56, 34, 16, 24, 53, 44, 06)), - new ArrayList(Arrays.asList(13, 40, 57, 72, 21, 15, 60, 8, 04, 19, 11, 98, 34, 45, 9, 97, 86, 71, 03, 15, 56, 19, 15, 44, 97, 31, 90, 04, 87, 87, 76, 8, 12, 30, 24, 62, 84, 28, 12, 85, 82, 53, 99, 52, 13, 94, 06, 65, 97, 86, 9, 50, 94, 68, 69, 74, 30, 67, 87, 94, 63, 07, 78, 27, 80, 36, 69, 41, 06, 92, 32, 78, 37, 82, 30, 05, 18, 87, 99, 72, 19, 99)), - new ArrayList(Arrays.asList(44, 20, 55, 77, 69, 91, 27, 31, 28, 81, 80, 27, 02, 07, 97, 23, 95, 98, 12, 25, 75, 29, 47, 71, 07, 47, 78, 39, 41, 59, 27, 76, 13, 15, 66, 61, 68, 35, 69, 86, 16, 53, 67, 63, 99, 85, 41, 56, 8, 28, 33, 40, 94, 76, 90, 85, 31, 70, 24, 65, 84, 65, 99, 82, 19, 25, 54, 37, 21, 46, 33, 02, 52, 99, 51, 33, 26, 04, 87, 02, 8, 18, 96)), - new ArrayList(Arrays.asList(54, 42, 61, 45, 91, 06, 64, 79, 80, 82, 32, 16, 83, 63, 42, 49, 19, 78, 65, 97, 40, 42, 14, 61, 49, 34, 04, 18, 25, 98, 59, 30, 82, 72, 26, 88, 54, 36, 21, 75, 03, 88, 99, 53, 46, 51, 55, 78, 22, 94, 34, 40, 68, 87, 84, 25, 30, 76, 25, 8, 92, 84, 42, 61, 40, 38, 9, 99, 40, 23, 29, 39, 46, 55, 10, 90, 35, 84, 56, 70, 63, 23, 91, 39)), - new ArrayList(Arrays.asList(52, 92, 03, 71, 89, 07, 9, 37, 68, 66, 58, 20, 44, 92, 51, 56, 13, 71, 79, 99, 26, 37, 02, 06, 16, 67, 36, 52, 58, 16, 79, 73, 56, 60, 59, 27, 44, 77, 94, 82, 20, 50, 98, 33, 9, 87, 94, 37, 40, 83, 64, 83, 58, 85, 17, 76, 53, 02, 83, 52, 22, 27, 39, 20, 48, 92, 45, 21, 9, 42, 24, 23, 12, 37, 52, 28, 50, 78, 79, 20, 86, 62, 73, 20, 59)), - new ArrayList(Arrays.asList(54, 96, 80, 15, 91, 90, 99, 70, 10, 9, 58, 90, 93, 50, 81, 99, 54, 38, 36, 10, 30, 11, 35, 84, 16, 45, 82, 18, 11, 97, 36, 43, 96, 79, 97, 65, 40, 48, 23, 19, 17, 31, 64, 52, 65, 65, 37, 32, 65, 76, 99, 79, 34, 65, 79, 27, 55, 33, 03, 01, 33, 27, 61, 28, 66, 8, 04, 70, 49, 46, 48, 83, 01, 45, 19, 96, 13, 81, 14, 21, 31, 79, 93, 85, 50, 05)), - new ArrayList(Arrays.asList(92, 92, 48, 84, 59, 98, 31, 53, 23, 27, 15, 22, 79, 95, 24, 76, 05, 79, 16, 93, 97, 89, 38, 89, 42, 83, 02, 88, 94, 95, 82, 21, 01, 97, 48, 39, 31, 78, 9, 65, 50, 56, 97, 61, 01, 07, 65, 27, 21, 23, 14, 15, 80, 97, 44, 78, 49, 35, 33, 45, 81, 74, 34, 05, 31, 57, 9, 38, 94, 07, 69, 54, 69, 32, 65, 68, 46, 68, 78, 90, 24, 28, 49, 51, 45, 86, 35)), - new ArrayList(Arrays.asList(41, 63, 89, 76, 87, 31, 86, 9, 46, 14, 87, 82, 22, 29, 47, 16, 13, 10, 70, 72, 82, 95, 48, 64, 58, 43, 13, 75, 42, 69, 21, 12, 67, 13, 64, 85, 58, 23, 98, 9, 37, 76, 05, 22, 31, 12, 66, 50, 29, 99, 86, 72, 45, 25, 10, 28, 19, 06, 90, 43, 29, 31, 67, 79, 46, 25, 74, 14, 97, 35, 76, 37, 65, 46, 23, 82, 06, 22, 30, 76, 93, 66, 94, 17, 96, 13, 20, 72)), - new ArrayList(Arrays.asList(63, 40, 78, 8, 52, 9, 90, 41, 70, 28, 36, 14, 46, 44, 85, 96, 24, 52, 58, 15, 87, 37, 05, 98, 99, 39, 13, 61, 76, 38, 44, 99, 83, 74, 90, 22, 53, 80, 56, 98, 30, 51, 63, 39, 44, 30, 91, 91, 04, 22, 27, 73, 17, 35, 53, 18, 35, 45, 54, 56, 27, 78, 48, 13, 69, 36, 44, 38, 71, 25, 30, 56, 15, 22, 73, 43, 32, 69, 59, 25, 93, 83, 45, 11, 34, 94, 44, 39, 92)), - new ArrayList(Arrays.asList(12, 36, 56, 88, 13, 96, 16, 12, 55, 54, 11, 47, 19, 78, 17, 17, 68, 81, 77, 51, 42, 55, 99, 85, 66, 27, 81, 79, 93, 42, 65, 61, 69, 74, 14, 01, 18, 56, 12, 01, 58, 37, 91, 22, 42, 66, 83, 25, 19, 04, 96, 41, 25, 45, 18, 69, 96, 88, 36, 93, 10, 12, 98, 32, 44, 83, 83, 04, 72, 91, 04, 27, 73, 07, 34, 37, 71, 60, 59, 31, 01, 54, 54, 44, 96, 93, 83, 36, 04, 45)), - new ArrayList(Arrays.asList(30, 18, 22, 20, 42, 96, 65, 79, 17, 41, 55, 69, 94, 81, 29, 80, 91, 31, 85, 25, 47, 26, 43, 49, 02, 99, 34, 67, 99, 76, 16, 14, 15, 93, 8, 32, 99, 44, 61, 77, 67, 50, 43, 55, 87, 55, 53, 72, 17, 46, 62, 25, 50, 99, 73, 05, 93, 48, 17, 31, 70, 80, 59, 9, 44, 59, 45, 13, 74, 66, 58, 94, 87, 73, 16, 14, 85, 38, 74, 99, 64, 23, 79, 28, 71, 42, 20, 37, 82, 31, 23)), - new ArrayList(Arrays.asList(51, 96, 39, 65, 46, 71, 56, 13, 29, 68, 53, 86, 45, 33, 51, 49, 12, 91, 21, 21, 76, 85, 02, 17, 98, 15, 46, 12, 60, 21, 88, 30, 92, 83, 44, 59, 42, 50, 27, 88, 46, 86, 94, 73, 45, 54, 23, 24, 14, 10, 94, 21, 20, 34, 23, 51, 04, 83, 99, 75, 90, 63, 60, 16, 22, 33, 83, 70, 11, 32, 10, 50, 29, 30, 83, 46, 11, 05, 31, 17, 86, 42, 49, 01, 44, 63, 28, 60, 07, 78, 95, 40)), - new ArrayList(Arrays.asList(44, 61, 89, 59, 04, 49, 51, 27, 69, 71, 46, 76, 44, 04, 9, 34, 56, 39, 15, 06, 94, 91, 75, 90, 65, 27, 56, 23, 74, 06, 23, 33, 36, 69, 14, 39, 05, 34, 35, 57, 33, 22, 76, 46, 56, 10, 61, 65, 98, 9, 16, 69, 04, 62, 65, 18, 99, 76, 49, 18, 72, 66, 73, 83, 82, 40, 76, 31, 89, 91, 27, 88, 17, 35, 41, 35, 32, 51, 32, 67, 52, 68, 74, 85, 80, 57, 07, 11, 62, 66, 47, 22, 67)), - new ArrayList(Arrays.asList(65, 37, 19, 97, 26, 17, 16, 24, 24, 17, 50, 37, 64, 82, 24, 36, 32, 11, 68, 34, 69, 31, 32, 89, 79, 93, 96, 68, 49, 90, 14, 23, 04, 04, 67, 99, 81, 74, 70, 74, 36, 96, 68, 9, 64, 39, 88, 35, 54, 89, 96, 58, 66, 27, 88, 97, 32, 14, 06, 35, 78, 20, 71, 06, 85, 66, 57, 02, 58, 91, 72, 05, 29, 56, 73, 48, 86, 52, 9, 93, 22, 57, 79, 42, 12, 01, 31, 68, 17, 59, 63, 76, 07, 77)), - new ArrayList(Arrays.asList(73, 81, 14, 13, 17, 20, 11, 9, 01, 83, 8, 85, 91, 70, 84, 63, 62, 77, 37, 07, 47, 01, 59, 95, 39, 69, 39, 21, 99, 9, 87, 02, 97, 16, 92, 36, 74, 71, 90, 66, 33, 73, 73, 75, 52, 91, 11, 12, 26, 53, 05, 26, 26, 48, 61, 50, 90, 65, 01, 87, 42, 47, 74, 35, 22, 73, 24, 26, 56, 70, 52, 05, 48, 41, 31, 18, 83, 27, 21, 39, 80, 85, 26, 8, 44, 02, 71, 07, 63, 22, 05, 52, 19, 8, 20)), - new ArrayList(Arrays.asList(17, 25, 21, 11, 72, 93, 33, 49, 64, 23, 53, 82, 03, 13, 91, 65, 85, 02, 40, 05, 42, 31, 77, 42, 05, 36, 06, 54, 04, 58, 07, 76, 87, 83, 25, 57, 66, 12, 74, 33, 85, 37, 74, 32, 20, 69, 03, 97, 91, 68, 82, 44, 19, 14, 89, 28, 85, 85, 80, 53, 34, 87, 58, 98, 88, 78, 48, 65, 98, 40, 11, 57, 10, 67, 70, 81, 60, 79, 74, 72, 97, 59, 79, 47, 30, 20, 54, 80, 89, 91, 14, 05, 33, 36, 79, 39)), - new ArrayList(Arrays.asList(60, 85, 59, 39, 60, 07, 57, 76, 77, 92, 06, 35, 15, 72, 23, 41, 45, 52, 95, 18, 64, 79, 86, 53, 56, 31, 69, 11, 91, 31, 84, 50, 44, 82, 22, 81, 41, 40, 30, 42, 30, 91, 48, 94, 74, 76, 64, 58, 74, 25, 96, 57, 14, 19, 03, 99, 28, 83, 15, 75, 99, 01, 89, 85, 79, 50, 03, 95, 32, 67, 44, 8, 07, 41, 62, 64, 29, 20, 14, 76, 26, 55, 48, 71, 69, 66, 19, 72, 44, 25, 14, 01, 48, 74, 12, 98, 07)), - new ArrayList(Arrays.asList(64, 66, 84, 24, 18, 16, 27, 48, 20, 14, 47, 69, 30, 86, 48, 40, 23, 16, 61, 21, 51, 50, 26, 47, 35, 33, 91, 28, 78, 64, 43, 68, 04, 79, 51, 8, 19, 60, 52, 95, 06, 68, 46, 86, 35, 97, 27, 58, 04, 65, 30, 58, 99, 12, 12, 75, 91, 39, 50, 31, 42, 64, 70, 04, 46, 07, 98, 73, 98, 93, 37, 89, 77, 91, 64, 71, 64, 65, 66, 21, 78, 62, 81, 74, 42, 20, 83, 70, 73, 95, 78, 45, 92, 27, 34, 53, 71, 15)), - new ArrayList(Arrays.asList(30, 11, 85, 31, 34, 71, 13, 48, 05, 14, 44, 03, 19, 67, 23, 73, 19, 57, 06, 90, 94, 72, 57, 69, 81, 62, 59, 68, 88, 57, 55, 69, 49, 13, 07, 87, 97, 80, 89, 05, 71, 05, 05, 26, 38, 40, 16, 62, 45, 99, 18, 38, 98, 24, 21, 26, 62, 74, 69, 04, 85, 57, 77, 35, 58, 67, 91, 79, 79, 57, 86, 28, 66, 34, 72, 51, 76, 78, 36, 95, 63, 90, 8, 78, 47, 63, 45, 31, 22, 70, 52, 48, 79, 94, 15, 77, 61, 67, 68)), - new ArrayList(Arrays.asList(23, 33, 44, 81, 80, 92, 93, 75, 94, 88, 23, 61, 39, 76, 22, 03, 28, 94, 32, 06, 49, 65, 41, 34, 18, 23, 8, 47, 62, 60, 03, 63, 33, 13, 80, 52, 31, 54, 73, 43, 70, 26, 16, 69, 57, 87, 83, 31, 03, 93, 70, 81, 47, 95, 77, 44, 29, 68, 39, 51, 56, 59, 63, 07, 25, 70, 07, 77, 43, 53, 64, 03, 94, 42, 95, 39, 18, 01, 66, 21, 16, 97, 20, 50, 90, 16, 70, 10, 95, 69, 29, 06, 25, 61, 41, 26, 15, 59, 63, 35)) - )); + public Problem67(){ + super(); + FILE_NAME = "files/Problem67Pyramid.txt"; } } diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem7.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem7.java index 1220476..58c5573 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem7.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem7.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem7.java //Matthew Ellison // Created: 03-01-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //What is the 10001th prime number? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -34,7 +34,7 @@ public class Problem7 extends Problem{ //Static variables private static final long NUMBER_OF_PRIMES = 10001; //The number of primes we are trying to get //Instance variables - private List primes; + protected List primes; //Functions //Constructor diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem8.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem8.java index 61ed108..183e8ed 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem8.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem8.java @@ -1,33 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem8.java //Matthew Ellison // Created: 03-28-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? -/* -73167176531330624919225119674426574742355349194934 -96983520312774506326239578318016984801869478851843 -85861560789112949495459501737958331952853208805511 -12540698747158523863050715693290963295227443043557 -66896648950445244523161731856403098711121722383113 -62229893423380308135336276614282806444486645238749 -30358907296290491560440772390713810515859307960866 -70172427121883998797908792274921901699720888093776 -65727333001053367881220235421809751254540594752243 -52584907711670556013604839586446706324415722155397 -53697817977846174064955149290862569321978468622482 -83972241375657056057490261407972968652414535100474 -82166370484403199890008895243450658541227588666881 -16427171479924442928230863465674813919123162824586 -17866458359124566529476545682848912883142607690042 -24219022671055626321111109370544217506941658960408 -07198403850962455444362981230987879927244284909188 -84580156166097919133875499200524063689912560717606 -05886116467109405077541002256983155200055935729725 -71636269561882670428252483600823257530420752963450 -*/ //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -44,15 +22,21 @@ */ package com.mattrixwv.project_euler.problems; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.security.InvalidParameterException; +import java.util.List; public class Problem8 extends Problem{ //Variables //Static variables //The 1000 digit number to check - private static final String NUMBER = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"; + protected static String FILE_NAME = "files/Problem8Number.txt"; + protected static String number; //Instance variables - private String maxNums; //Holds the string of the largest product - private long maxProduct; //Holds the largest product of 13 numbers + protected String maxNums; //Holds the string of the largest product + protected long maxProduct; //Holds the largest product of 13 numbers //Functions //Constructor @@ -62,6 +46,25 @@ public class Problem8 extends Problem{ maxProduct = 0; } //Operational functions + //Read number from file into number + private void readFile(){ + if(number != null){ + return; + } + File file = new File(FILE_NAME); + if(file.exists()){ + try{ + List lines = Files.readAllLines(file.toPath()); + number = lines.get(0); + } + catch(IOException error){ + throw new InvalidParameterException("Error reading file", error); + } + } + else{ + throw new InvalidParameterException("Error opening file"); + } + } //Solve the problem @Override public void solve(){ @@ -70,17 +73,20 @@ public class Problem8 extends Problem{ return; } + //Read the file into the number + readFile(); + //Start the timer timer.start(); //Cycle through the string of numbers looking for the maximum product - for(int cnt = 12;cnt < NUMBER.length();++cnt){ - long currentProduct = Long.parseLong(NUMBER.substring(cnt - 12, cnt - 11)) * Long.parseLong(NUMBER.substring(cnt - 11, cnt - 10)) * Long.parseLong(NUMBER.substring(cnt - 10, cnt - 9)) * Long.parseLong(NUMBER.substring(cnt - 9, cnt - 8)) * Long.parseLong(NUMBER.substring(cnt - 8, cnt - 7)) * Long.parseLong(NUMBER.substring(cnt - 7, cnt - 6)) * Long.parseLong(NUMBER.substring(cnt - 6, cnt - 5)) * Long.parseLong(NUMBER.substring(cnt - 5, cnt - 4)) * Long.parseLong(NUMBER.substring(cnt - 4, cnt - 3)) * Long.parseLong(NUMBER.substring(cnt - 3, cnt - 2)) * Long.parseLong(NUMBER.substring(cnt - 2, cnt - 1)) * Long.parseLong(NUMBER.substring(cnt - 1, cnt)) * Long.parseLong(NUMBER.substring(cnt, cnt + 1)); + for(int cnt = 12;cnt < number.length();++cnt){ + long currentProduct = Long.parseLong(number.substring(cnt - 12, cnt - 11)) * Long.parseLong(number.substring(cnt - 11, cnt - 10)) * Long.parseLong(number.substring(cnt - 10, cnt - 9)) * Long.parseLong(number.substring(cnt - 9, cnt - 8)) * Long.parseLong(number.substring(cnt - 8, cnt - 7)) * Long.parseLong(number.substring(cnt - 7, cnt - 6)) * Long.parseLong(number.substring(cnt - 6, cnt - 5)) * Long.parseLong(number.substring(cnt - 5, cnt - 4)) * Long.parseLong(number.substring(cnt - 4, cnt - 3)) * Long.parseLong(number.substring(cnt - 3, cnt - 2)) * Long.parseLong(number.substring(cnt - 2, cnt - 1)) * Long.parseLong(number.substring(cnt - 1, cnt)) * Long.parseLong(number.substring(cnt, cnt + 1)); //Check if the product is greater than the current maximum if(currentProduct > maxProduct){ - maxNums = NUMBER.substring(cnt - 12, cnt + 1); + maxNums = number.substring(cnt - 12, cnt + 1); maxProduct = currentProduct; } } diff --git a/src/main/java/com/mattrixwv/project_euler/problems/Problem9.java b/src/main/java/com/mattrixwv/project_euler/problems/Problem9.java index 604d660..9cf998f 100644 --- a/src/main/java/com/mattrixwv/project_euler/problems/Problem9.java +++ b/src/main/java/com/mattrixwv/project_euler/problems/Problem9.java @@ -1,11 +1,11 @@ //ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem9.java //Matthew Ellison // Created: 03-02-19 -//Modified: 08-20-22 +//Modified: 06-27-23 //There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* - Copyright (C) 2022 Matthew Ellison + Copyright (C) 2023 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -29,17 +29,17 @@ import com.mattrixwv.project_euler.exceptions.Unsolved; public class Problem9 extends Problem{ //Variables //Static variables - private static final int GOAL_SUM = 1000; //The number that we want the sum of a, b, and c to equal + protected int GOAL_SUM = 1000; //The number that we want the sum of a, b, and c to equal //Instance variables - private int a; //The size of the first side - private int b; //The size of the second side - private double c; //The size of the hyp - private boolean found; //A flag to determine if we have found the solution yet + protected int a; //The size of the first side + protected int b; //The size of the second side + protected double c; //The size of the hyp + protected boolean found; //A flag to determine if we have found the solution yet //Functions //Constructor public Problem9(){ - super(String.format("There exists exactly one Pythagorean triplet for which a + b + c = %d. Find the product abc.", GOAL_SUM)); + super(String.format("There exists exactly one Pythagorean triplet for which a + b + c = %d. Find the product abc.", 1000)); a = 1; b = 0; c = 0; diff --git a/src/test/java/com/mattrixwv/project_euler/TestProblemSelection.java b/src/test/java/com/mattrixwv/project_euler/TestProblemSelection.java index 180b287..bd7d347 100644 --- a/src/test/java/com/mattrixwv/project_euler/TestProblemSelection.java +++ b/src/test/java/com/mattrixwv/project_euler/TestProblemSelection.java @@ -1,9 +1,11 @@ package com.mattrixwv.project_euler; + import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; + public class TestProblemSelection{ @Test public void testProblemSelection(){ diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem.java new file mode 100644 index 0000000..e88a387 --- /dev/null +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem.java @@ -0,0 +1,89 @@ +package com.mattrixwv.project_euler.problems; + + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.mattrixwv.project_euler.exceptions.Unsolved; + + +@ExtendWith(MockitoExtension.class) +public class TestProblem{ + private Problem problem; + + + @BeforeEach + public void setup(){ + problem = new Problem1(); + } + + @Test + public void testConstructor(){ + assertNotNull(problem); + assertNotNull(problem.getDescription()); + assertFalse(problem.getSolved()); + } + + @Test + public void testGetDescription(){ + assertNotNull(problem.getDescription()); + } + + @Test + public void testGetTime(){ + assertThrows(Unsolved.class, () -> { + problem.getTime(); + }); + + problem.solved = true; + + assertNotNull(problem.getTime()); + } + + @Test + public void testGetTimer(){ + assertThrows(Unsolved.class, () -> { + problem.getTimer(); + }); + + problem.solved = true; + assertNotNull(problem.getTimer()); + } + + @Test + public void testSolvedCheck(){ + assertThrows(Unsolved.class, () -> { + problem.solvedCheck(""); + }); + + problem.solved = true; + problem.solvedCheck(""); + } + + @Test + public void testGetSolved(){ + assertFalse(problem.getSolved()); + + problem.solved = true; + assertTrue(problem.getSolved()); + } + + @Test + public void testReset(){ + problem.solved = true; + + problem.reset(); + + assertFalse(problem.getSolved()); + problem.solved = true; + assertEquals(0.0D, problem.getTimer().getNano()); + } +} diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java index 61752c7..b3bfd83 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem1.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem1 extends ProblemBaseTest{ +public class TestProblem1 extends TestProblemBase{ @InjectMocks private Problem1 problem = new Problem1(); static{ description = "What is the sum of all the multiples of 3 or 5 that are less than 1000?"; result = "The sum of all numbers < 1000 is 233168"; } + private int fullSum = 233168; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getResult(); }); @@ -37,13 +35,21 @@ public class TestProblem1 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(233168, problem.getSum()); + assertEquals(fullSum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.fullSum = fullSum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.fullSum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java index afc592b..5cc5041 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem10.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem10 extends ProblemBaseTest{ +public class TestProblem10 extends TestProblemBase{ @InjectMocks private Problem10 problem; static{ description = "Find the sum of all the primes below 2000000."; result = "The sum of all the primes < 2000000 is 142913828922"; } + private long sum = 142913828922L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSum(); }); @@ -36,13 +34,21 @@ public class TestProblem10 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(142913828922L, problem.getSum()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java index 4024e6c..769007c 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem11.java @@ -4,33 +4,36 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.security.InvalidParameterException; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem11 extends ProblemBaseTest{ +public class TestProblem11 extends TestProblemBase{ @InjectMocks private Problem11 problem; static{ description = "What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?"; result = String.format("The greatest product of 4 numbers in a line is 70600674%nThe numbers are [89, 94, 97, 87]"); } + private List greatestProduct = List.of(89, 94, 97, 87); + private int product = 70600674; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumbers(); }); @@ -39,14 +42,49 @@ public class TestProblem11 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(89, 94, 97, 87), problem.getNumbers()); - assertEquals(70600674, problem.getProduct()); + assertEquals(greatestProduct, problem.getNumbers()); + assertEquals(product, problem.getProduct()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.greatestProduct = new ArrayList<>(greatestProduct); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.greatestProduct); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem11.grid = null; + RandomAccessFile file = new RandomAccessFile(Problem11.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem11.grid = null; + Problem11.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java index 44524f5..e7b7505 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem12.java @@ -4,31 +4,35 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; +import com.mattrixwv.NumberAlgorithms; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem12 extends ProblemBaseTest{ +public class TestProblem12 extends TestProblemBase{ @InjectMocks private Problem12 problem; static{ description = "What is the value of the first triangle number to have over 500 divisors?"; result = "The triangular number 76576500 is the sum of all numbers >= 12375 and has 576 divisors"; } + private long sum = 76576500; + private long counter = 12375; + private List divisors = NumberAlgorithms.getDivisors(sum); @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTriangularNumber(); }); @@ -39,16 +43,28 @@ public class TestProblem12 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(76576500, problem.getTriangularNumber()); - assertEquals(12375, problem.getLastNumberAdded()); - assertEquals(576, problem.getDivisorsOfTriangularNumber().size()); - assertEquals(576, problem.getNumberOfDivisors()); + assertEquals(sum, problem.getTriangularNumber()); + assertEquals(counter, problem.getLastNumberAdded()); + assertEquals(divisors, problem.getDivisorsOfTriangularNumber()); + assertEquals(divisors.size(), problem.getNumberOfDivisors()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.sum = sum; + problem.counter = counter; + problem.divisors = new ArrayList<>(divisors); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(1, problem.sum); + assertEquals(2, problem.counter); + assertEquals(new ArrayList<>(), problem.divisors); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java index ad16bc1..81f03a6 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem13.java @@ -4,33 +4,34 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.io.IOException; +import java.io.RandomAccessFile; import java.math.BigInteger; +import java.security.InvalidParameterException; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem13 extends ProblemBaseTest{ +public class TestProblem13 extends TestProblemBase{ @InjectMocks private Problem13 problem; static{ description = "Work out the first ten digits of the sum of the one-hundred 50-digit numbers"; result = String.format("The sum of all 100 numbers is 5537376230390876637302048746832985971773659831892672%nThe first 10 digits of the sum of the numbers is 5537376230"); } + private BigInteger sum = new BigInteger("5537376230390876637302048746832985971773659831892672"); @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumbers(); }); @@ -40,13 +41,48 @@ public class TestProblem13 extends ProblemBaseTest{ //Verify result assertEquals(100, problem.getNumbers().size()); - assertEquals(new BigInteger("5537376230390876637302048746832985971773659831892672"), problem.getSum()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(BigInteger.ZERO, problem.sum); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem13.nums = null; + RandomAccessFile file = new RandomAccessFile(Problem13.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem13.nums = null; + Problem13.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java index 69dec98..be6430e 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem14.java @@ -4,31 +4,30 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem14 extends ProblemBaseTest{ +public class TestProblem14 extends TestProblemBase{ @InjectMocks private Problem14 problem; static{ description = "Which starting number, under 1000000, produces the longest chain using the iterative sequence?"; result = "The number 837799 produced a chain of 525 steps"; } + private long maxLength = 525L; + private long maxNum = 837799L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLength(); }); @@ -37,14 +36,24 @@ public class TestProblem14 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(525, problem.getLength()); - assertEquals(837799, problem.getStartingNumber()); + assertEquals(maxLength, problem.getLength()); + assertEquals(maxNum, problem.getStartingNumber()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.maxLength = maxLength; + problem.maxNum = maxNum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0L, problem.maxLength); + assertEquals(0L, problem.maxNum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java index 874affc..abde3f3 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem15.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem15 extends ProblemBaseTest{ +public class TestProblem15 extends TestProblemBase{ @InjectMocks private Problem15Override problem; static{ description = "How many routes from the top left corner to the bottom right corner are there through a 5x5 grid if you can only move right and down?"; result = "The number of routes is 252"; } + private long numOfRoutes = 252; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumberOfRoutes(); }); @@ -36,16 +34,24 @@ public class TestProblem15 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(252, problem.getNumberOfRoutes()); + assertEquals(numOfRoutes, problem.getNumberOfRoutes()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.numOfRoutes = numOfRoutes; + problem.solved = true; + super.testReset(problem); } + @Override + public void verifyReset(){ + assertEquals(0L, problem.numOfRoutes); + } + public static class Problem15Override extends Problem15{ static{ gridWidth = 5; diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java index d78a1eb..186357d 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem16.java @@ -4,45 +4,58 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.math.BigInteger; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem16 extends ProblemBaseTest{ +public class TestProblem16 extends TestProblemBase{ @InjectMocks private Problem16 problem; static{ description = "What is the sum of the digits of the number 2^1000?"; result = String.format("2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376%nThe sum of the elements is 1366"); } + private BigInteger num = new BigInteger("10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376"); + private int sum = 1366; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ + assertThrows(Unsolved.class, () -> {problem.getNumber(); }); assertThrows(Unsolved.class, () -> { problem.getSum(); }); super.testSolve(problem); //Verify result - assertEquals(1366, problem.getSum()); + assertEquals(num, problem.getNumber()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.num = num; + problem.sumOfElements = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(BigInteger.ZERO, problem.num); + assertEquals(0, problem.sumOfElements); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java index e315221..e87b0cb 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem17.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem17 extends ProblemBaseTest{ +public class TestProblem17 extends TestProblemBase{ @InjectMocks private Problem17 problem; static{ description = "If all the numbers from 1 to 1000 inclusive were written out in words, how many letters would be used?"; result = "The sum of all the letters in all the numbers 1-1000 is 21124"; } + private long letterCount = 21124L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLetterCount(); }); @@ -36,13 +34,35 @@ public class TestProblem17 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(21124, problem.getLetterCount()); + assertEquals(letterCount, problem.getLetterCount()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.letterCount = letterCount; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.letterCount); + } + + @Test + public void testMakeWordFromNum_negative(){ + String numberString = problem.makeWordFromNum(-1); + + assertEquals("negative one", numberString); + } + + @Test + public void testMakeWordFromNum_zero(){ + String numberString = problem.makeWordFromNum(0); + + assertEquals("zero", numberString); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java index 310305d..d85cdae 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem18.java @@ -2,33 +2,39 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.io.RandomAccessFile; +import java.security.InvalidParameterException; +import java.util.ArrayList; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; +import com.mattrixwv.project_euler.problems.Problem18.Location; -public class TestProblem18 extends ProblemBaseTest{ +public class TestProblem18 extends TestProblemBase{ @InjectMocks private Problem18 problem; static{ description = "Find the maximum total from top to bottom"; result = "The value of the longest path is 1074"; } + private int total = 1074; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTotal(); }); @@ -36,15 +42,85 @@ public class TestProblem18 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(1074, problem.getTotal()); + assertEquals(total, problem.getTotal()); assertEquals(String.format("75\n95 64\n17 47 82\n18 35 87 10\n20 4 82 47 65\n19 1 23 75 3 34\n88 2 77 73 7 63 67\n99 65 4 28 6 16 70 92\n41 41 26 56 83 40 80 70 33\n41 48 72 33 47 32 37 16 94 29\n53 71 44 65 25 43 91 52 97 51 14\n70 11 33 28 77 73 17 78 39 68 17 57\n91 71 52 38 17 14 91 43 58 50 27 29 48\n63 66 4 68 89 53 67 30 73 16 69 87 40 31\n 4 62 98 27 23 9 70 98 73 93 38 53 60 4 23"), problem.getPyramid()); assertEquals("75->95->47->35->4->23->73->6->40->37->91->78->58->73->93", problem.getTrail()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.actualTotal = total; + problem.foundPoints = new ArrayList<>(); + problem.foundPoints.add(new Location(0, 0, 0, true)); + problem.possiblePoints = new ArrayList<>(); + problem.possiblePoints.add(new Location(0, 0, 0, true)); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals("files/Problem18Pyramid.txt", problem.FILE_NAME); + assertEquals(new ArrayList<>(), problem.foundPoints); + assertEquals(new ArrayList<>(), problem.possiblePoints); + assertEquals(0, problem.actualTotal); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem18.list = null; + RandomAccessFile file = new RandomAccessFile(problem.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem18.list = null; + problem.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } + + @Test + public void testLocation(){ + int x = 1; + int y = 2; + int t = 3; + boolean r = true; + Location location = new Location(x, y, t, r); + + assertEquals(x, location.getXLocation()); + assertEquals(y, location.getYLocation()); + assertEquals(t, location.getTotal()); + assertTrue(location.getFromRight()); + + x = 4; + y = 5; + t = 6; + r = false; + location.setXLocation(x); + location.setYLocation(y); + location.setTotal(t); + location.setFromRight(r); + + assertEquals(x, location.getXLocation()); + assertEquals(y, location.getYLocation()); + assertEquals(t, location.getTotal()); + assertFalse(location.getFromRight()); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java index ac3bc80..630c363 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem19.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem19 extends ProblemBaseTest{ +public class TestProblem19 extends TestProblemBase{ @InjectMocks private Problem19 problem; static{ description = "How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?"; result = "There are 171 Sundays that landed on the first of the months from 1901 to 2000"; } + private long totalSundays = 171L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTotalSundays(); }); @@ -36,13 +34,21 @@ public class TestProblem19 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(171, problem.getTotalSundays()); + assertEquals(totalSundays, problem.getTotalSundays()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.totalSundays = totalSundays; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.totalSundays); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java index 53cf795..d2e8e75 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem2.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem2 extends ProblemBaseTest{ +public class TestProblem2 extends TestProblemBase{ @InjectMocks private Problem2 problem; static{ description = "What is the sum of the even Fibonacci numbers less than 4000000?"; result = "The sum of all even fibonacci numbers <= 3999999 is 4613732"; } + private int fullSum = 4613732; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getResult(); }); @@ -37,13 +35,21 @@ public class TestProblem2 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(4613732, problem.getSum()); + assertEquals(fullSum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.fullSum = fullSum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.fullSum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java index 11a579c..26d1775 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem20.java @@ -6,31 +6,31 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigInteger; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem20 extends ProblemBaseTest{ +public class TestProblem20 extends TestProblemBase{ @InjectMocks private Problem20 problem; static{ description = "What is the sum of the digits of 100!?"; result = String.format("100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000%nThe sum of the digits is: 648"); } + private String numString = "93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"; + private BigInteger num = new BigInteger(numString); + private long sum = 648L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumber(); }); @@ -40,15 +40,25 @@ public class TestProblem20 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(new BigInteger("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000"), problem.getNumber()); - assertEquals("93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000", problem.getNumberString()); - assertEquals(648, problem.getSum()); + assertEquals(numString, problem.getNumberString()); + assertEquals(num, problem.getNumber()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.num = num; + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(BigInteger.ONE, problem.num); + assertEquals(0L, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java index 078d1c1..f4e9a42 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem21.java @@ -4,33 +4,33 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem21 extends ProblemBaseTest{ +public class TestProblem21 extends TestProblemBase{ @InjectMocks private Problem21 problem; static{ description = "Evaluate the sum of all the amicable numbers under 10000"; result = String.format("All amicable numbers less than 10000 are%n220%n284%n1184%n1210%n2620%n2924%n5020%n5564%n6232%n6368%nThe sum of all of these amicable numbers is 31626"); } + private List amicable = List.of(220, 284, 1184, 1210, 2620, 2924, 5020, 5564, 6232, 6368); + private int sum = 31626; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getAmicable(); }); @@ -39,14 +39,27 @@ public class TestProblem21 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(220, 284, 1184, 1210, 2620, 2924, 5020, 5564, 6232, 6368), problem.getAmicable()); - assertEquals(31626, problem.getSum()); + assertEquals(amicable, problem.getAmicable()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.amicable = new ArrayList<>(amicable); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.amicable); + ArrayList divisorSum = new ArrayList<>(10000); + while(divisorSum.size() < 10000){ + divisorSum.add(0); + } + assertEquals(divisorSum, problem.divisorSum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java index 6b74ef7..6bb6be8 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem22.java @@ -4,31 +4,34 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.security.InvalidParameterException; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem22 extends ProblemBaseTest{ +public class TestProblem22 extends TestProblemBase{ @InjectMocks private Problem22 problem; static{ description = "What is the total of all the name scores in this file?"; result = "The answer to the question is 871198282"; } + private long sum = 871198282L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNameScoreSum(); }); @@ -37,13 +40,54 @@ public class TestProblem22 extends ProblemBaseTest{ //Verify result assertEquals(5163, Problem22.getNames().size()); - assertEquals(871198282L, problem.getNameScoreSum()); + assertEquals(sum, problem.getNameScoreSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.sums = new ArrayList<>(); + problem.sums.add(1L); + problem.prod = new ArrayList<>(); + problem.prod.add(2L); + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.sums); + assertEquals(new ArrayList<>(), problem.prod); + assertEquals(0L, problem.sum); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem22.names = new ArrayList<>(); + RandomAccessFile file = new RandomAccessFile(Problem22.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem22.names = new ArrayList<>(); + Problem22.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java index 6dcb4a3..5a11a8c 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem23.java @@ -4,31 +4,38 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem23 extends ProblemBaseTest{ +public class TestProblem23 extends TestProblemBase{ @InjectMocks - private Problem23Override problem; + private Problem23 problem; static{ description = "Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers"; result = "The answer is 2035227"; } + private long sum = 2035227L; + + + @BeforeEach + public void setup(){ + Problem23.maxNum = 5000; + } @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSum(); }); @@ -36,20 +43,26 @@ public class TestProblem23 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(2035227, problem.getSum()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } - - public static class Problem23Override extends Problem23{ - static{ - maxNum = 5000; + @Override + public void verifyReset(){ + assertEquals(0L, problem.sum); + ArrayList divisorSums = new ArrayList<>(5000); + while(divisorSums.size() <= 5000){ + divisorSums.add(0); } + assertEquals(divisorSums, problem.divisorSums); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java index 0e6c077..76a95f5 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem24.java @@ -4,14 +4,15 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem24 extends ProblemBaseTest{ +public class TestProblem24 extends TestProblemBase{ @InjectMocks private Problem24Override problem; static{ @@ -21,14 +22,12 @@ public class TestProblem24 extends ProblemBaseTest{ @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPermutationsList(); }); @@ -42,12 +41,21 @@ public class TestProblem24 extends ProblemBaseTest{ } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.permutations = new ArrayList<>(); + problem.permutations.add("1"); + problem.solved = true; + super.testReset(problem); } + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.permutations); + } + public static class Problem24Override extends Problem24{ static{ diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java index 3461ca4..cbf737e 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem25.java @@ -6,31 +6,33 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigInteger; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem25 extends ProblemBaseTest{ +public class TestProblem25 extends TestProblemBase{ @InjectMocks private Problem25 problem; static{ description = "What is the index of the first term in the Fibonacci sequence to contain 1000 digits?"; result = String.format("The first Fibonacci number with 1000 digits is 1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816%nIts index is 4782"); } + private String numberString = "1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816"; + private BigInteger number = new BigInteger(numberString); + private int indexInt = 4782; + private String indexString = Integer.toString(indexInt); + private BigInteger index = new BigInteger(indexString); @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumber(); }); @@ -42,17 +44,27 @@ public class TestProblem25 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(new BigInteger("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816"), problem.getNumber()); - assertEquals("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816", problem.getNumberString()); - assertEquals(BigInteger.valueOf(4782), problem.getIndex()); - assertEquals("4782", problem.getIndexString()); - assertEquals(4782, problem.getIndexInt()); + assertEquals(number, problem.getNumber()); + assertEquals(numberString, problem.getNumberString()); + assertEquals(index, problem.getIndex()); + assertEquals(indexString, problem.getIndexString()); + assertEquals(indexInt, problem.getIndexInt()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.number = number; + problem.index = index; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(BigInteger.ZERO, problem.number); + assertEquals(BigInteger.TWO, problem.index); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java index e210e02..f8153e1 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem26.java @@ -4,31 +4,30 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem26 extends ProblemBaseTest{ +public class TestProblem26 extends TestProblemBase{ @InjectMocks private Problem26 problem; static{ description = "Find the value of d <= 999 for which 1/d contains the longest recurring cycle in its decimal fraction part."; result = String.format("The longest cycle is 982 digits long%nIt started with the number 983"); } + private int longestCycle = 982; + private int longestNumber = 983; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLongestCycle(); }); @@ -37,14 +36,24 @@ public class TestProblem26 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(982, problem.getLongestCycle()); - assertEquals(983, problem.getLongestNumber()); + assertEquals(longestCycle, problem.getLongestCycle()); + assertEquals(longestNumber, problem.getLongestNumber()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.longestCycle = longestCycle; + problem.longestNumber = longestNumber; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.longestCycle); + assertEquals(1, problem.longestNumber); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java index ce0adce..b51d243 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem27.java @@ -4,31 +4,31 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem27 extends ProblemBaseTest{ +public class TestProblem27 extends TestProblemBase{ @InjectMocks private Problem27 problem; static{ description = "Find the product of the coefficients, |a| <= 999 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0"; result = String.format("The greatest number of primes found is 70%nIt was found with A = -61, B = 971%nThe product of A and B is -59231"); } + private int topA = -61; + private int topB = 971; + private int topN = 70; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTopA(); }); @@ -39,16 +39,28 @@ public class TestProblem27 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(-61, problem.getTopA()); - assertEquals(971, problem.getTopB()); - assertEquals(70, problem.getTopN()); - assertEquals(-59231, problem.getProduct()); + assertEquals(topA, problem.getTopA()); + assertEquals(topB, problem.getTopB()); + assertEquals(topN, problem.getTopN()); + assertEquals(topA * topB, problem.getProduct()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.topA = topA; + problem.topB = topB; + problem.topN = topN; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.topA); + assertEquals(0, problem.topB); + assertEquals(0, problem.topN); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java index 6b9949b..f0110d1 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem28.java @@ -5,31 +5,31 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem28 extends ProblemBaseTest{ +public class TestProblem28 extends TestProblemBase{ @InjectMocks private Problem28 problem; static{ description = "What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction?"; result = "The sum of the diagonals in the given grid is 669171001"; } + private int sum = 669171001; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getGrid(); }); @@ -39,13 +39,28 @@ public class TestProblem28 extends ProblemBaseTest{ //Verify result assertNotNull(problem.getGrid()); - assertEquals(669171001, problem.getSum()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.grid = new ArrayList<>(); + problem.grid.add(new ArrayList<>()); + problem.grid.get(0).add(1); + problem.sumOfDiagonals = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + ArrayList> grid = new ArrayList<>(); + grid.add(new ArrayList<>()); + grid.get(0).add(1); + assertEquals(grid, problem.grid); + assertEquals(0, problem.sumOfDiagonals); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java index f53ffa5..413daaf 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem29.java @@ -4,31 +4,33 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem29 extends ProblemBaseTest{ +public class TestProblem29 extends TestProblemBase{ @InjectMocks private Problem29 problem; static{ description = "How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?"; result = "The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183"; } + private List unique = List.of(BigInteger.ONE); @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getUnique(); }); @@ -39,12 +41,24 @@ public class TestProblem29 extends ProblemBaseTest{ //Verify result assertEquals(9183, problem.getUnique().size()); assertEquals(9183, problem.getNumUnique()); + assertEquals(2, Problem29.getBottomA()); + assertEquals(2, Problem29.getBottomB()); + assertEquals(100, Problem29.getTopA()); + assertEquals(100, Problem29.getTopB()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.unique = new ArrayList<>(unique); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.unique); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java index 3fe404f..972410f 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem3.java @@ -4,25 +4,28 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; -import com.mattrixwv.NumberAlgorithms; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem3 extends ProblemBaseTest{ +public class TestProblem3 extends TestProblemBase{ @InjectMocks private Problem3 problem; static{ description = "What is the largest prime factor of 600851475143?"; result = "The largest factor of the number 600851475143 is 6857"; } + private static List factors = List.of(71L, 839L, 1471L, 6857L); + private long largestFactor = 6857; + @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); @@ -30,7 +33,6 @@ public class TestProblem3 extends ProblemBaseTest{ } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getResult(); }); @@ -40,14 +42,22 @@ public class TestProblem3 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(NumberAlgorithms.getFactors(600851475143L), problem.getFactors()); - assertEquals(6857, problem.getLargestFactor()); + assertEquals(factors, problem.getFactors()); + assertEquals(largestFactor, problem.getLargestFactor()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.factors = new ArrayList<>(factors); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.factors); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java index d026596..cb7a694 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem30.java @@ -4,33 +4,33 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem30 extends ProblemBaseTest{ +public class TestProblem30 extends TestProblemBase{ @InjectMocks private Problem30 problem; static{ description = "Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits."; result = String.format("The sum of all the numbers that can be written as the sum of the fifth powers of their digits is 443839"); } + private List sumOfFifthNumbers = List.of(4150L, 4151L, 54748L, 92727L, 93084L, 194979L); + private long sum = 443839L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getListOfSumOfFifths(); }); @@ -39,14 +39,24 @@ public class TestProblem30 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(4150L, 4151L, 54748L, 92727L, 93084L, 194979L), problem.getListOfSumOfFifths()); - assertEquals(443839L, problem.getSumOfList()); + assertEquals(sumOfFifthNumbers, problem.getListOfSumOfFifths()); + assertEquals(sum, problem.getSumOfList()); + assertEquals(1000000L, Problem30.getTopNum()); } @Test - @Order(3) @Override public void testReset(){ + problem.sumOfFifthNumbers = new ArrayList<>(sumOfFifthNumbers); + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.sumOfFifthNumbers); + assertEquals(0L, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem31.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem31.java index 21a6352..c5329c0 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem31.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem31.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem31 extends ProblemBaseTest{ +public class TestProblem31 extends TestProblemBase{ @InjectMocks private Problem31 problem; static{ description = "How many different ways can 2 pounds be made using any number of coins?"; result = "There are 73682 ways to make 2 pounds with the given denominations of coins"; } + private int permutations = 73682; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPermutations(); }); @@ -36,13 +34,21 @@ public class TestProblem31 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(73682, problem.getPermutations()); + assertEquals(permutations, problem.getPermutations()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.permutations = permutations; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.permutations); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem32.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem32.java index 9d5641f..16463c2 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem32.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem32.java @@ -2,33 +2,35 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; +import com.mattrixwv.project_euler.problems.Problem32.ProductSet; -public class TestProblem32 extends ProblemBaseTest{ +public class TestProblem32 extends TestProblemBase{ @InjectMocks private Problem32 problem; static{ description = "Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital."; result = String.format("There are 7 unique 1-9 pandigitals%nThe sum of the products of these pandigitals is 45228"); } + private long sum = 45228L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSumOfPandigitals(); }); @@ -36,13 +38,40 @@ public class TestProblem32 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(45228, problem.getSumOfPandigitals()); + assertEquals(sum, problem.getSumOfPandigitals()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.listOfProducts = new ArrayList<>(); + problem.listOfProducts.add(problem.new ProductSet(5, 6)); + problem.sumOfPandigitals = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.listOfProducts); + assertEquals(0, problem.sumOfPandigitals); + } + + @Test + public void testProductSet(){ + int multiplicand = 2; + int multiplier = 3; + ProductSet ps = new Problem32().new ProductSet(multiplicand, multiplier); + + assertEquals(multiplicand, ps.getMultiplicand()); + assertEquals(multiplier, ps.getMultiplier()); + assertEquals(multiplicand * multiplier, ps.getProduct()); + assertEquals(ps, ps); + assertNotEquals(ps, 0); + assertEquals(ps, new Problem32().new ProductSet(multiplicand, multiplier)); + assertEquals(((2 * multiplicand) + (3 * multiplier)), ps.hashCode()); + assertEquals("236", ps.toString()); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem33.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem33.java index efb3111..ed0031d 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem33.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem33.java @@ -4,33 +4,34 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem33 extends ProblemBaseTest{ +public class TestProblem33 extends TestProblemBase{ @InjectMocks private Problem33 problem; static{ description = "If the product of these four fractions is given in its lowest common terms, find the value of the denominator"; result = "The denominator of the product is 100"; } + private List numerators = List.of(16, 26, 19, 49); + private List denominators = List.of(64, 65, 95, 98); + private int prod = 100; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumerators(); }); @@ -40,15 +41,27 @@ public class TestProblem33 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(16, 26, 19, 49), problem.getNumerators()); - assertEquals(List.of(64, 65, 95, 98), problem.getDenominators()); - assertEquals(100, problem.getProdDenominator()); + assertEquals(numerators, problem.getNumerators()); + assertEquals(denominators, problem.getDenominators()); + assertEquals(prod, problem.getProdDenominator()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.numerators = new ArrayList<>(numerators); + problem.denominators = new ArrayList<>(denominators); + problem.prodDenominator = prod; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.numerators); + assertEquals(new ArrayList<>(), problem.denominators); + assertEquals(1, problem.prodDenominator); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem34.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem34.java index cd5f13f..89ef7ef 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem34.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem34.java @@ -4,33 +4,33 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem34 extends ProblemBaseTest{ +public class TestProblem34 extends TestProblemBase{ @InjectMocks private Problem34 problem; static{ description = "Find the sum of all numbers which are equal to the sum of the factorial of their digits"; result = "The sum of all numbers that are the sum of their digit's factorials is 40730"; } + private List factorials = List.of(1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880); + private int sum = 40730; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getFactorials(); }); @@ -39,14 +39,24 @@ public class TestProblem34 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880), problem.getFactorials()); - assertEquals(40730, problem.getSum()); + assertEquals(factorials, problem.getFactorials()); + assertEquals(sum, problem.getSum()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.factorials = new ArrayList<>(factorials); + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(List.of(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), problem.factorials); + assertEquals(0, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem35.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem35.java index 2722211..309e83d 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem35.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem35.java @@ -4,14 +4,15 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem35 extends ProblemBaseTest{ +public class TestProblem35 extends TestProblemBase{ @InjectMocks private Problem35Override problem; static{ @@ -21,14 +22,12 @@ public class TestProblem35 extends ProblemBaseTest{ @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPrimes(); }); @@ -44,12 +43,24 @@ public class TestProblem35 extends ProblemBaseTest{ } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.primes = new ArrayList<>(); + problem.primes.add(1); + problem.circularPrimes = new ArrayList<>(); + problem.circularPrimes.add(2); + problem.solved = true; + super.testReset(problem); } + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.primes); + assertEquals(new ArrayList<>(), problem.circularPrimes); + } + public static class Problem35Override extends Problem35{ static{ diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem36.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem36.java index fa148e7..81ee707 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem36.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem36.java @@ -4,31 +4,33 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem36 extends ProblemBaseTest{ +public class TestProblem36 extends TestProblemBase{ @InjectMocks private Problem36 problem; static{ description = "Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2."; result = "The sum of all base 10 and base 2 palindromic numbers < 999999 is 872187"; } + private List palindromes = List.of(1, 3, 5, 7, 9, 33, 99, 313, 585, 717, 7447, 9009, 15351, 32223, 39993, 53235, 53835, 73737, 585585); + private int sum = 872187; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPalindromes(); }); @@ -37,14 +39,23 @@ public class TestProblem36 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(19, problem.getPalindromes().size()); - assertEquals(872187, problem.getSumOfPalindromes()); + assertEquals(palindromes, problem.getPalindromes()); + assertEquals(sum, problem.getSumOfPalindromes()); } @Test - @Order(3) @Override public void testReset(){ + problem.palindromes = new ArrayList<>(palindromes); + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.palindromes); + assertEquals(0, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem37.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem37.java index 1484fff..b94a836 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem37.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem37.java @@ -4,31 +4,33 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem37 extends ProblemBaseTest{ +public class TestProblem37 extends TestProblemBase{ @InjectMocks private Problem37 problem; static{ description = "Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted)."; result = "The sum of all left and right truncatable primes is 748317"; } + private List truncPrimes = List.of(23L, 37L, 53L, 73L, 313L, 317L, 373L, 797L, 3137L, 3797L, 739397L); + private long sum = 748317L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTruncatablePrimes(); }); @@ -37,14 +39,23 @@ public class TestProblem37 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(11, problem.getTruncatablePrimes().size()); - assertEquals(748317L, problem.getSumOfPrimes()); + assertEquals(truncPrimes, problem.getTruncatablePrimes()); + assertEquals(sum, problem.getSumOfPrimes()); } @Test - @Order(3) @Override public void testReset(){ + problem.truncPrimes = new ArrayList<>(truncPrimes); + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.truncPrimes); + assertEquals(0L, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem38.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem38.java index bc6b22a..6bf5aea 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem38.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem38.java @@ -4,31 +4,30 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem38 extends ProblemBaseTest{ +public class TestProblem38 extends TestProblemBase{ @InjectMocks private Problem38 problem; static{ description = "What is the largest 1-9 pandigital number that can be formed as the concatenated product of an integer with 1, 2, ... n where n > 1"; result = "The largest appended product pandigital is 932718654"; } + private long largestNum = 9327L; + private long pandigital = 932718654L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLargestNum(); }); @@ -37,14 +36,23 @@ public class TestProblem38 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(9327L, problem.getLargestNum()); - assertEquals(932718654L, problem.getPandigital()); + assertEquals(largestNum, problem.getLargestNum()); + assertEquals(pandigital, problem.getPandigital()); } @Test - @Order(3) @Override public void testReset(){ + problem.largestNum = largestNum; + problem.pandigital = pandigital; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.largestNum); + assertEquals(0, problem.pandigital); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem39.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem39.java index 9a57c51..e82f0bf 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem39.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem39.java @@ -4,9 +4,10 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -14,24 +15,29 @@ import com.mattrixwv.Triple; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem39 extends ProblemBaseTest{ +public class TestProblem39 extends TestProblemBase{ @InjectMocks - private Problem39Override problem; + private Problem39 problem; static{ description = "If p is the perimeter of a right triangle for which value of p <= 100 is the number of solutions for the sides {a, b, c} maximized"; result = "The perimeter with the largest number of solutions is 90"; } + private List> longestSolutions = List.of(new Triple<>(9L, 40L, 41L), new Triple<>(15L, 36L, 39L)); + + + @BeforeEach + public void setup(){ + Problem39.maxPerimeter = 100; + } @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLongestSolutions(); }); @@ -40,21 +46,21 @@ public class TestProblem39 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(new Triple<>(9L, 40L, 41L), new Triple<>(15L, 36L, 39L)), problem.getLongestSolutions()); - assertEquals(90, problem.getLongestPerimeter()); + assertEquals(longestSolutions, problem.getLongestSolutions()); + assertEquals(90L, problem.getLongestPerimeter()); } @Test - @Order(3) @Override public void testReset(){ + problem.longestSolutions = new ArrayList<>(longestSolutions); + problem.solved = true; + super.testReset(problem); } - - public static class Problem39Override extends Problem39{ - static{ - maxPerimeter = 100; - } + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.longestSolutions); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java index 613f19d..55de9c3 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem4.java @@ -4,14 +4,16 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem4 extends ProblemBaseTest{ +public class TestProblem4 extends TestProblemBase{ @InjectMocks private Problem4 problem; static{ @@ -21,14 +23,12 @@ public class TestProblem4 extends ProblemBaseTest{ @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPalindromes(); }); @@ -42,9 +42,20 @@ public class TestProblem4 extends ProblemBaseTest{ } @Test - @Order(3) @Override public void testReset(){ + //Setup + Problem4 p2 = new Problem4(); + p2.solve(); + List palindromes = p2.getPalindromes(); + problem.palindromes = palindromes; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.palindromes); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem40.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem40.java index cd63a97..b281581 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem40.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem40.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem40 extends ProblemBaseTest{ +public class TestProblem40 extends TestProblemBase{ @InjectMocks private Problem40 problem; static{ description = "An irrational decimal fraction is created by concatenating the positive integers. Find the value of the following expression: d1 * d10 * d100 * d1000 * d10000 * d100000 * d1000000"; result = "The product is 210"; } + private long product = 210L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getIrrationalDecimal(); }); @@ -38,13 +36,22 @@ public class TestProblem40 extends ProblemBaseTest{ //Verify result assertEquals(1000007, problem.getIrrationalDecimal().length()); - assertEquals(210, problem.getProduct()); + assertEquals(product, problem.getProduct()); } @Test - @Order(3) @Override public void testReset(){ + problem.irrationalDecimal = new StringBuilder("Some random string"); + problem.product = product; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals("", problem.irrationalDecimal.toString()); + assertEquals(0, problem.product); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem41.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem41.java index c0edac7..51fcf64 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem41.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem41.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem41 extends ProblemBaseTest{ +public class TestProblem41 extends TestProblemBase{ @InjectMocks private Problem41 problem; static{ description = "What is the largest n-digit pandigital prime?"; result = "The largest n-digit pandigital prime is 7652413"; } + private long largestPrimePandigital = 7652413L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLargestPrimePandigital(); }); @@ -36,13 +34,20 @@ public class TestProblem41 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(7652413L, problem.getLargestPrimePandigital()); + assertEquals(largestPrimePandigital, problem.getLargestPrimePandigital()); } @Test - @Order(3) @Override public void testReset(){ + problem.largestPrimePandigital = largestPrimePandigital; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.largestPrimePandigital); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem42.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem42.java index d37e4a3..6822f30 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem42.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem42.java @@ -4,14 +4,19 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem42 extends ProblemBaseTest{ +public class TestProblem42 extends TestProblemBase{ @InjectMocks private Problem42 problem; static{ @@ -21,14 +26,12 @@ public class TestProblem42 extends ProblemBaseTest{ @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTriangularWords(); }); @@ -42,9 +45,43 @@ public class TestProblem42 extends ProblemBaseTest{ } @Test - @Order(3) @Override public void testReset(){ + problem.triangleWords = new ArrayList<>(List.of("1", "2")); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.triangleWords); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem42.fileWords = new ArrayList<>(); + RandomAccessFile file = new RandomAccessFile(Problem42.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem42.fileWords = new ArrayList<>(); + Problem42.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem43.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem43.java index ecd9399..d246b97 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem43.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem43.java @@ -4,33 +4,40 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem43 extends ProblemBaseTest{ +public class TestProblem43 extends TestProblemBase{ @InjectMocks - private Problem43Override problem; + private Problem43 problem; static{ description = "Find the sum of all 0-9 pandigital numbers with this property"; result = "The sum of all pandigitals with the property is 1113342912"; } + private List subPrimePandigitals = List.of(140635728L, 146035728L, 410635728L, 416035728L); + private long sumSubPrimePandigitals = 1113342912L; + + + @BeforeEach + public void setup(){ + Problem43.nums = "012345678"; + } @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSubPrimePandigitals(); }); @@ -39,21 +46,21 @@ public class TestProblem43 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(List.of(140635728L, 146035728L, 410635728L, 416035728L), problem.getSubPrimePandigitals()); - assertEquals(1113342912L, problem.getSumSubPrimePandigitals()); + assertEquals(subPrimePandigitals, problem.getSubPrimePandigitals()); + assertEquals(sumSubPrimePandigitals, problem.getSumSubPrimePandigitals()); } @Test - @Order(3) @Override public void testReset(){ + problem.subPrimePandigitals = new ArrayList<>(subPrimePandigitals); + problem.solved = true; + super.testReset(problem); } - - public static class Problem43Override extends Problem43{ - static{ - nums = "012345678"; - } + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.subPrimePandigitals); } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem44.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem44.java index 0d0f2ce..87026ef 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem44.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem44.java @@ -4,31 +4,34 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; +import com.mattrixwv.generators.PentagonalNumberGenerator; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem44 extends ProblemBaseTest{ +public class TestProblem44 extends TestProblemBase{ @InjectMocks private Problem44 problem; static{ description = "Find 2 pentagonal numbers whos sum and difference are also pentagonal numbers"; result = "The difference of the pentagonal numbers is 5482660"; } + private long pentagonalNumber1 = 1560090L; + private long pentagonalNumber2 = 7042750L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPentagonalList(); }); @@ -40,15 +43,26 @@ public class TestProblem44 extends ProblemBaseTest{ //Verify result assertEquals(2167, problem.getPentagonalList().size()); - assertEquals(1560090L, problem.getPentagonalNumber1()); - assertEquals(7042750L, problem.getPentagonalNumber2()); - assertEquals(5482660L, problem.getDifference()); + assertEquals(pentagonalNumber1, problem.getPentagonalNumber1()); + assertEquals(pentagonalNumber2, problem.getPentagonalNumber2()); + assertEquals(pentagonalNumber2 - pentagonalNumber1, problem.getDifference()); } @Test - @Order(3) @Override public void testReset(){ + problem.pentagonalList = new ArrayList<>(List.of(1L, 2L, 3L)); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new PentagonalNumberGenerator().next(), problem.generator.next()); + problem.generator = new PentagonalNumberGenerator(); + assertEquals(new ArrayList<>(), problem.pentagonalList); + assertEquals(0, problem.pentagonalNumber1); + assertEquals(0, problem.pentagonalNumber2); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem45.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem45.java index 0952f1f..8cdf1fd 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem45.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem45.java @@ -4,31 +4,32 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; +import com.mattrixwv.generators.HexagonalNumberGenerator; +import com.mattrixwv.generators.PentagonalNumberGenerator; +import com.mattrixwv.generators.TriangularNumberGenerator; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem45 extends ProblemBaseTest{ +public class TestProblem45 extends TestProblemBase{ @InjectMocks private Problem45 problem; static{ description = "Find the next triangle number after 40755 that is also pentagonal and hexagonal"; result = "The next triangular/pentagonal/hexagonal number is 1533776805"; } + private long num = 1533776805L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNum(); }); @@ -36,13 +37,26 @@ public class TestProblem45 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(1533776805L, problem.getNum()); + assertEquals(num, problem.getNum()); } @Test - @Order(3) @Override public void testReset(){ + problem.num = num; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.num); + assertEquals(new TriangularNumberGenerator().next(), problem.triGen.next()); + problem.triGen = new TriangularNumberGenerator(); + assertEquals(new PentagonalNumberGenerator().next(), problem.penGen.next()); + problem.penGen = new PentagonalNumberGenerator(); + assertEquals(new HexagonalNumberGenerator().next(), problem.hexGen.next()); + problem.hexGen = new HexagonalNumberGenerator(); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem46.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem46.java index c02b001..294a6d6 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem46.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem46.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem46 extends ProblemBaseTest{ +public class TestProblem46 extends TestProblemBase{ @InjectMocks private Problem46 problem; static{ description = "What is the smallest odd composite number that connot be written as the sum of a prime and twice a square?"; result = "The smallest odd composite that cannot be written as the sum of a prime and twice a square is 5777"; } + private long compositeNum = 5777L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getCompositeNum(); }); @@ -36,13 +34,20 @@ public class TestProblem46 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(5777, problem.getCompositeNum()); + assertEquals(compositeNum, problem.getCompositeNum()); } @Test - @Order(3) @Override public void testReset(){ + problem.num = compositeNum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0L, problem.num); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem47.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem47.java index 4a6e23d..860c034 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem47.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem47.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem47 extends ProblemBaseTest{ +public class TestProblem47 extends TestProblemBase{ @InjectMocks private Problem47 problem; static{ description = "What is the first of four consecutive integers to have four distinct prime factors each?"; result = "The first number is 134043"; } + private long firstNum = 134043L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getFirstNum(); }); @@ -36,13 +34,20 @@ public class TestProblem47 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(134043, problem.getFirstNum()); + assertEquals(firstNum, problem.getFirstNum()); } @Test - @Order(3) @Override public void testReset(){ + problem.num = firstNum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.num); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem48.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem48.java index 2087d6f..0e2ddfd 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem48.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem48.java @@ -6,31 +6,31 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.math.BigInteger; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem48 extends ProblemBaseTest{ +public class TestProblem48 extends TestProblemBase{ @InjectMocks private Problem48 problem; static{ description = "Find the last ten digits of the series Σn^n for 1<=n<=1000"; result = "The last ten digits of the series Σn^n for 1<=n<=1000 is 9110846700"; } + private String numString = "1000368199144695177095375011227646795567793680622934654583760988100234910747716194381428659099527845945869942643191290894720342979906407679647259860434238468038326040809691037615370376237713648510063115732951461774246705584266865759601815843666442832284556880313114548151539190975398485496645576513465858582712336401166221956188173449531674102688908321764663020306699770408625340766091595022791379368098369306375602813856646358773751558775213460225796579846583334007349358624342339332981334571237888809283103348760261360175950815609179464026871005243652109980863552142014242903434068560936573231079342194031864413918101238151056509267393515760392842472501391594073463001521843811073767021711026307504695733467897821866906648469828346607412967395801797791683609834722432241952845352564681868240369569566192825555323558078061997527689983848863374786789331581565252059172614339424600986143259233167583371070362625554531852054166117148858229508581589614337594463277554380518380921301218836327102231407332201109740102580216469298331766920619646083790732807627360614428085171565006289728508688964226799647192582924058589530750674578385365561878559589685756225692348914746922810913915619834754117648358035814128670294158565669942087736286390942241547226015004471330630113072042704288905042142628193771918594574302202147201188486345913190833752307476966010547423928871063118783026036381319039052008252072057933666712918946233312793697094074224187872045970976444309242782187738320257490080824330074991698698239561125811127607863900355221737846690567707344074494145266662103839812840216303448476913957072355732716627098372245223046792919747259113157425824064858331415400943278213042954635053574045209984512221264241903550178416824551412548637590007779082539288247751653566899882749594405895102587985539527709493510049546445427265617478399107188238681771215904234119392247489751079085948055945098805617963722928469554263782217625160428008228845552540344494860195267115187092227766195753907211126646150140614744233974765273475619964311852858614167819668340124730487710162006793529985758820653677274379563313495454526632718723482339494825759821076401694316043456512117937935456463521463021197726694983558929132357576188594977516630734212863869456164205525536767311298137182511494649463663073759219213056823561667776093739425742883930712609962163464088038826569132032160692637206183085942987973684584276491784843115472077900401692595694119273553511025991265446039366288921743581333200083717105241171504606883543418862024047552177055263424469501298905901938158245938633694105024815166679813689156668341197713475094389904887126794468901893850475050011205225742455555625750560213230387910337983950333245020653238989115507013882956277763880795687210857196493893142656713105966275422144605988058939600603604226921401402096519294250488670297983396353279460453142375542267881989197481789780678955093763193658603690898474826976906544473978017455720367929981796023041785852626797271283465789498383642350667978127819110846700"; + private BigInteger sum = new BigInteger(numString); + private String sumDigits = "9110846700"; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSum(); }); @@ -39,14 +39,21 @@ public class TestProblem48 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(new BigInteger("1000368199144695177095375011227646795567793680622934654583760988100234910747716194381428659099527845945869942643191290894720342979906407679647259860434238468038326040809691037615370376237713648510063115732951461774246705584266865759601815843666442832284556880313114548151539190975398485496645576513465858582712336401166221956188173449531674102688908321764663020306699770408625340766091595022791379368098369306375602813856646358773751558775213460225796579846583334007349358624342339332981334571237888809283103348760261360175950815609179464026871005243652109980863552142014242903434068560936573231079342194031864413918101238151056509267393515760392842472501391594073463001521843811073767021711026307504695733467897821866906648469828346607412967395801797791683609834722432241952845352564681868240369569566192825555323558078061997527689983848863374786789331581565252059172614339424600986143259233167583371070362625554531852054166117148858229508581589614337594463277554380518380921301218836327102231407332201109740102580216469298331766920619646083790732807627360614428085171565006289728508688964226799647192582924058589530750674578385365561878559589685756225692348914746922810913915619834754117648358035814128670294158565669942087736286390942241547226015004471330630113072042704288905042142628193771918594574302202147201188486345913190833752307476966010547423928871063118783026036381319039052008252072057933666712918946233312793697094074224187872045970976444309242782187738320257490080824330074991698698239561125811127607863900355221737846690567707344074494145266662103839812840216303448476913957072355732716627098372245223046792919747259113157425824064858331415400943278213042954635053574045209984512221264241903550178416824551412548637590007779082539288247751653566899882749594405895102587985539527709493510049546445427265617478399107188238681771215904234119392247489751079085948055945098805617963722928469554263782217625160428008228845552540344494860195267115187092227766195753907211126646150140614744233974765273475619964311852858614167819668340124730487710162006793529985758820653677274379563313495454526632718723482339494825759821076401694316043456512117937935456463521463021197726694983558929132357576188594977516630734212863869456164205525536767311298137182511494649463663073759219213056823561667776093739425742883930712609962163464088038826569132032160692637206183085942987973684584276491784843115472077900401692595694119273553511025991265446039366288921743581333200083717105241171504606883543418862024047552177055263424469501298905901938158245938633694105024815166679813689156668341197713475094389904887126794468901893850475050011205225742455555625750560213230387910337983950333245020653238989115507013882956277763880795687210857196493893142656713105966275422144605988058939600603604226921401402096519294250488670297983396353279460453142375542267881989197481789780678955093763193658603690898474826976906544473978017455720367929981796023041785852626797271283465789498383642350667978127819110846700"), problem.getSum()); - assertEquals("9110846700", problem.getSumDigits()); + assertEquals(sum, problem.getSum()); + assertEquals(sumDigits, problem.getSumDigits()); } @Test - @Order(3) @Override public void testReset(){ + problem.sum = sum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(BigInteger.ZERO, problem.sum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem49.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem49.java index b5df146..7982357 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem49.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem49.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem49 extends ProblemBaseTest{ +public class TestProblem49 extends TestProblemBase{ @InjectMocks private Problem49 problem; static{ description = "What is the 12-digit number formed by concatenating the three terms in the sequence?"; result = "The 12-digit number formed by concatenation the three terms in the sequence is 296962999629"; } + private String concatNums = "296962999629"; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getConcatNums(); }); @@ -36,13 +34,20 @@ public class TestProblem49 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals("296962999629", problem.getConcatNums()); + assertEquals(concatNums, problem.getConcatNums()); } @Test - @Order(3) @Override public void testReset(){ + problem.concatenationOfNumbers = concatNums; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals("", problem.concatenationOfNumbers); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java index 0518fe2..c109140 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem5.java @@ -4,31 +4,29 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem5 extends ProblemBaseTest{ +public class TestProblem5 extends TestProblemBase{ @InjectMocks private Problem5 problem; static{ description = "What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?"; result = "The smallest positive number evenly divisible by all numbers 1-20 is 232792560"; } + private int smallestNum = 232792560; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getNumber(); }); @@ -36,13 +34,21 @@ public class TestProblem5 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(232792560, problem.getNumber()); + assertEquals(smallestNum, problem.getNumber()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.smallestNum = smallestNum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0, problem.smallestNum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem50.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem50.java index 58082bc..d40a955 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem50.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem50.java @@ -4,31 +4,32 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; +import java.util.List; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem50 extends ProblemBaseTest{ +public class TestProblem50 extends TestProblemBase{ @InjectMocks private Problem50 problem; static{ description = "Which prime, below 1000000, can be written as the sum of the most consecutive primes?"; result = "The prime below 1000000 that can be written as the sum of the most consecutive primes is 997651"; } + private long prime = 997651L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getConsecutivePrimes(); }); @@ -38,13 +39,20 @@ public class TestProblem50 extends ProblemBaseTest{ //Verify result assertEquals(543, problem.getConsecutivePrimes().size()); - assertEquals(997651L, problem.getPrime()); + assertEquals(prime, problem.getPrime()); } @Test - @Order(3) @Override public void testReset(){ + problem.consecutivePrimes = new ArrayList<>(List.of(1L, 2L)); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.consecutivePrimes); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java index 934f0bf..9419bb1 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem6.java @@ -4,49 +4,61 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem6 extends ProblemBaseTest{ +@Execution(ExecutionMode.CONCURRENT) +public class TestProblem6 extends TestProblemBase{ @InjectMocks private Problem6 problem; static{ description = "Find the difference between the sum of the squares and the square of the sum of the numbers 1-100."; result = "The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150"; } + private long sumOfSquares = 338350L; + private long squareOfSum = 25502500L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSumOfSquares(); }); assertThrows(Unsolved.class, () -> { problem.getSquareOfSum(); }); assertThrows(Unsolved.class, () -> { problem.getDifference(); }); - problem.solve(); + super.testSolve(problem); //Verify result - assertEquals(338350, problem.getSumOfSquares()); - assertEquals(25502500, problem.getSquareOfSum()); - assertEquals(25164150, problem.getDifference()); + assertEquals(sumOfSquares, problem.getSumOfSquares()); + assertEquals(squareOfSum, problem.getSquareOfSum()); + assertEquals(squareOfSum - sumOfSquares, problem.getDifference()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.sumOfSquares = sumOfSquares; + problem.squareOfSum = squareOfSum; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(0L, problem.sumOfSquares); + assertEquals(0L, problem.squareOfSum); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem67.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem67.java index fff2694..8b749eb 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem67.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem67.java @@ -1,32 +1,38 @@ package com.mattrixwv.project_euler.problems; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.security.InvalidParameterException; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; +import com.mattrixwv.project_euler.problems.Problem18.Location; -public class TestProblem67 extends ProblemBaseTest{ + +public class TestProblem67 extends TestProblemBase{ @InjectMocks private Problem67 problem; static{ description = "Find the maximum total from top to bottom"; result = "The value of the longest path is 7273"; } + private int total = 7273; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getTotal(); }); @@ -34,13 +40,54 @@ public class TestProblem67 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(7273, problem.getTotal()); + assertEquals(total, problem.getTotal()); } @Test - @Order(3) @Override public void testReset(){ + problem.actualTotal = total; + problem.foundPoints = new ArrayList<>(); + problem.foundPoints.add(new Location(0, 0, 0, true)); + problem.possiblePoints = new ArrayList<>(); + problem.possiblePoints.add(new Location(0, 0, 0, true)); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals("files/Problem67Pyramid.txt", problem.FILE_NAME); + assertEquals(new ArrayList<>(), problem.foundPoints); + assertEquals(new ArrayList<>(), problem.possiblePoints); + assertEquals(0, problem.actualTotal); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem67.list = null; + RandomAccessFile file = new RandomAccessFile(problem.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem67.list = null; + problem.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java index 1c1fee1..3bd5dd1 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem7.java @@ -4,14 +4,16 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; +import com.mattrixwv.NumberAlgorithms; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem7 extends ProblemBaseTest{ +public class TestProblem7 extends TestProblemBase{ @InjectMocks private Problem7 problem; static{ @@ -21,14 +23,12 @@ public class TestProblem7 extends ProblemBaseTest{ @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getPrime(); }); @@ -36,13 +36,21 @@ public class TestProblem7 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(104743, problem.getPrime()); + assertEquals(104743L, problem.getPrime()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.primes = NumberAlgorithms.getNumPrimes(10001L); + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(new ArrayList<>(), problem.primes); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java index 748ac44..7371032 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem8.java @@ -4,31 +4,34 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.security.InvalidParameterException; + import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem8 extends ProblemBaseTest{ +public class TestProblem8 extends TestProblemBase{ @InjectMocks private Problem8 problem; static{ description = "Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?"; result = String.format("The greatest product is 23514624000%nThe numbers are 5576689664895"); } + private String maxNums = "5576689664895"; + private long maxProduct = 23514624000L; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getLargestNums(); }); @@ -37,14 +40,51 @@ public class TestProblem8 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals("5576689664895", problem.getLargestNums()); - assertEquals(23514624000L, problem.getLargestProduct()); + assertEquals(maxNums, problem.getLargestNums()); + assertEquals(maxProduct, problem.getLargestProduct()); } @Test - @Order(3) @Override public void testReset(){ + //Setup + problem.maxNums = maxNums; + problem.maxProduct = maxProduct; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals("", problem.maxNums); + assertEquals(0L, problem.maxProduct); + } + + @Test + public void testSolve_readError() throws IOException{ + problem.reset(); + + Problem8.number = null; + RandomAccessFile file = new RandomAccessFile(Problem8.FILE_NAME, "rw"); + file.getChannel().lock(); + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + + file.close(); + } + + @Test + public void testSolve_noFile(){ + problem.reset(); + + Problem8.number = null; + Problem8.FILE_NAME = "/a"; + + assertThrows(InvalidParameterException.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java index 8927518..77dcffc 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblem9.java @@ -4,31 +4,31 @@ package com.mattrixwv.project_euler.problems; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import com.mattrixwv.project_euler.exceptions.Unsolved; -public class TestProblem9 extends ProblemBaseTest{ +public class TestProblem9 extends TestProblemBase{ @InjectMocks private Problem9 problem; static{ description = "There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc."; result = String.format("The Pythagorean triplet is 200 + 375 + 425%nThe numbers' product is 31875000"); } + private int a = 200; + private int b = 375; + private int c = 425; @Test - @Order(1) @Override public void testDescription(){ super.testDescription(problem); } @Test - @Order(2) @Override public void testSolve(){ assertThrows(Unsolved.class, () -> { problem.getSideA(); }); @@ -39,16 +39,39 @@ public class TestProblem9 extends ProblemBaseTest{ super.testSolve(problem); //Verify result - assertEquals(200, problem.getSideA()); - assertEquals(375, problem.getSideB()); - assertEquals(425, problem.getSideC()); - assertEquals(31875000, problem.getProduct()); + assertEquals(a, problem.getSideA()); + assertEquals(b, problem.getSideB()); + assertEquals(c, problem.getSideC()); + assertEquals(a * b * c, problem.getProduct()); } @Test - @Order(3) @Override public void testReset(){ + problem.a = a; + problem.b = b; + problem.c = c; + problem.found = true; + problem.solved = true; + super.testReset(problem); } + + @Override + public void verifyReset(){ + assertEquals(1, problem.a); + assertEquals(0, problem.b); + assertEquals(0, problem.c); + assertEquals(false, problem.found); + } + + @Test + public void testSolve_notFound(){ + problem.reset(); + problem.GOAL_SUM = 1; + + assertThrows(Unsolved.class, () -> { + problem.solve(); + }); + } } diff --git a/src/test/java/com/mattrixwv/project_euler/problems/ProblemBaseTest.java b/src/test/java/com/mattrixwv/project_euler/problems/TestProblemBase.java similarity index 74% rename from src/test/java/com/mattrixwv/project_euler/problems/ProblemBaseTest.java rename to src/test/java/com/mattrixwv/project_euler/problems/TestProblemBase.java index ae7fdca..d495445 100644 --- a/src/test/java/com/mattrixwv/project_euler/problems/ProblemBaseTest.java +++ b/src/test/java/com/mattrixwv/project_euler/problems/TestProblemBase.java @@ -5,14 +5,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.atMostOnce; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestMethodOrder; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.TestInstance.Lifecycle; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; @@ -22,9 +17,7 @@ import com.mattrixwv.project_euler.exceptions.Unsolved; @ExtendWith(MockitoExtension.class) -@TestInstance(Lifecycle.PER_CLASS) -@TestMethodOrder(OrderAnnotation.class) -public abstract class ProblemBaseTest{ +public abstract class TestProblemBase{ @Spy protected Stopwatch timer; protected static String description; @@ -33,12 +26,12 @@ public abstract class ProblemBaseTest{ public abstract void testDescription(); public void testDescription(Problem problem){ assertEquals(description, problem.getDescription()); - assertFalse(problem.getSolved()); } public abstract void testSolve(); public void testSolve(Problem problem){ //Verify the results cannot be seen until the problem has been run + assertFalse(problem.getSolved()); assertThrows(Unsolved.class, () -> { problem.getResult(); }); problem.solve(); @@ -47,8 +40,8 @@ public abstract class ProblemBaseTest{ assertTrue(problem.getSolved()); assertEquals(result, problem.getResult()); //Verify timer function were called - verify(timer, atLeastOnce()).start(); - verify(timer, atLeastOnce()).stop(); + verify(timer, times(1)).start(); + verify(timer, times(1)).stop(); //Verify the problem won't be run again problem.solve(); @@ -56,8 +49,8 @@ public abstract class ProblemBaseTest{ //Verify solved is still set assertTrue(problem.getSolved()); //Verify timer functions were not called again - verify(timer, atMostOnce()).start(); - verify(timer, atMostOnce()).stop(); + verify(timer, times(1)).start(); + verify(timer, times(1)).stop(); } public abstract void testReset(); @@ -68,8 +61,13 @@ public abstract class ProblemBaseTest{ //Verify solved was reset assertFalse(problem.getSolved()); + verify(timer, times(1)).reset(); + assertEquals(0, timer.getNano()); + verifyReset(); //Verify the problem can be solved again testSolve(); } + + public abstract void verifyReset(); }