From ed83a3afc324d668512745fac53684ca9a514542 Mon Sep 17 00:00:00 2001 From: Jens True Date: Wed, 31 Jul 2024 07:16:44 +0000 Subject: [PATCH] Gitignore --- .gitignore | 2 + .phpcs.xml | 52 ++++++++++++++++++ solutions/CodeGolf/guns-and-zips/input.1 | 53 ------------------ solutions/CodeGolf/guns-and-zips/output.1 | 53 ------------------ solutions/CodeGolf/guns-and-zips/solve.php | 0 src/Numerical.php | 32 +++++------ src/Prime.php | 63 +++++++++++----------- tests/NumericalTest.php | 41 ++++++++++++++ tests/PrimeTest.php | 8 ++- 9 files changed, 147 insertions(+), 157 deletions(-) create mode 100644 .gitignore create mode 100644 .phpcs.xml delete mode 100644 solutions/CodeGolf/guns-and-zips/input.1 delete mode 100644 solutions/CodeGolf/guns-and-zips/output.1 delete mode 100644 solutions/CodeGolf/guns-and-zips/solve.php create mode 100644 tests/NumericalTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..111d7ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +output/ +.*.cache/ diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..41fd719 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,52 @@ + + + Coding standard + + src/ + tests/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/solutions/CodeGolf/guns-and-zips/input.1 b/solutions/CodeGolf/guns-and-zips/input.1 deleted file mode 100644 index 9907707..0000000 --- a/solutions/CodeGolf/guns-and-zips/input.1 +++ /dev/null @@ -1,53 +0,0 @@ -??r?Jlogo.png?)??PNG - - -IHDRLK?~)sBIT??O? pHYs  ??~?tEXtSoftwareMacromedia Fireworks 8?h?xtEXtCreation Time20/7/06?t?-IDATx???{ts??{???=?F??Foi???lK????Bx8??/???k?5??d7?? -96K?n8,7a??@K??!k`?!61Y$| ?d -?,y?????Hc?C???????????3?IT???[??j???W??FX?[??f?H$E?B!A??h4"?h?2?lC?-???l>w????po?e ????+--?l@ ? -dkZ???? ?D?~W?~PE?dOOOSS?d?l??-?g?}&?H???òl(jmm?cG?s?lC -?]?(j||? -a?w?;???e?g??k???5?L&`5%w??F??#pC!?f)9?<\?t)?j?????|?@ ???e????>>'? ?????V???J~;?j?z??kkk6?-_f!?A??Hdlll3??q?,???H$R(:?nll 6?H?Z?F?????OF???;???#??a??azN?r?????? ?1?@?Ev"?x-?SSS8?*(?(rA???3::*???$)???~????hSt???ry?8???r?Zm4??? q??!???l?81y?/o?)????rya??e?8?KS=?e?q??;?jEUuUs?????4 -$)?*???,\(????N'? ??{????^_8w@??9?c#???p???[???"???85=???{?f???J??}??g_??P???]????u??wGP???|?,?[????*?J?*))?|?rggg!2PB??|??!wZ\???VB???/_7y??w^x??F/?LN??a??#?}???<B?\4?????z{{O?:??????g7??G????????b??hh(o???w??5U(???Rn[?·j?:????.??T2???D?T?????I??I+??H????1 -????6?B {?[A?z????/PK??8I??P? ?T?P??%%%F????#?;??????Kg??F? -?^ä?(8???????n?V\{?.P?k??C&2?y?Z=????w"&?? =?e?eyh??y??ny??????mV'@???)????????_O?+???~z6??Cr@P?U?PVpm??s?????+**????Je?????Í?s???L?>?????i??D???'w(?????g8!????R??j????]]]???]>u?3?J?i???]Zle???G' -??-??[S?N?????s?????(?\?????,??B?C~??????G?U??e??[Hnd9?06????"DD$q/?$ -??????????Z?k???????????#}E?G]zpr ?????????3???,]???@???DP???]?r??mt??L??????f?o???=?lT??['??;??K????????W7??F????l]?b??? ??*?$??????b?a>???o???????s?c??6?#???=????v}?`m\??}?bJ?V?h??t??"?Q?-?A??W}aD?b<?O????%?*?k*??:?ut?w???W??S?F??????g???p?O??????ub???;U???m???bfC?B???>V??Y?_?x -???D"???2?LB6I??OQ?(r?$?Z-????B???????9??w??;??k????%?7?F;????????? ?S?????????Jq~?????:XE?????A??8?:?ap???s#??.Rqq?dt ?V/g]^a5??? P? O??????. ?$m6?R??h?v? x?????????????J????)?(???a?L????????w?}7??=????c??g2 ????t:????QO????E???2? ??[P??on??l????+g?O?? eO?7???(@:??s???+'_O? ?????uy???R ??????L&?B????????Z?H??2?~dG_?%UeD[f???????b???q????]????+?????o.?????+4???r????DUR?R(d -a?(?-Ml????????**?u??:?????n-?cy?w??H$J?????H?h.???QG ?\??{D???J?$=?2??"B???2'? +???F?4^? -*????????}?DW4U?s3?r}?x?f?J??j`?}?Ib9i??1????;A?E??????L&??[W?a - - -???$I?|?P(???b?Z???s??aX?eYV"?????????[S???`0??L?| YQC{78?U?>??K#?????O??????a?7.???? -?%?S???L~2@Ug?,????_NvU? -?E?t??u?3????O??l?(^?= s??e?4?X -???????C+???N????s?Ri?t-???;?B??j??o\`??m&Z??0???h^)n??U9?h?? d -* Pl???~o$?u?Y?1 (???p???biz????W?-??$????/~??"??e???V?;?>?1?6?u?7???V ?B[ÿ?????{?R?A%??s?????4???#??}J????k7? -z????S????!??n -???"?(?????uB?'?? +U? ?"%???D?~DZ????3???!??vX,Kk$?????:m K?`Es?4z.?u??@T]W??R?B??r??{???? -y?ZVZZj4?^/????LNNNNN?wt?,KQI?$I???????????????$???1???of{??O-?w??U??7_???{l??1?{o????b&G?uy7???<2?>??/|?JGGG8?9?C???^O?Nx?? -? E#??, ?!???(e?w-.oB,D"$??J?J?.??)???Qmk?N??+???Sy?Z?2 B????????hB?\t4M;????E?)_ -?0???????>n???h*++?Z?L&?W??H$?????????{??????~??>r?{W[?8?d?j?l4Vb t???v????-??o??`???i??N?}-???w??_??Hq??q~x?5????????[?vW??|???;]???????Zc?8c? ???^???????-?H???f?L/ ??orCy????oN?{j??????45?q?]_n/`n???y7&?????????o??"}??J?A8??????,?????\@??Z??B@-l?d?J\???CH%??+T???"T|?EX4?MJK?B?8?f??J ?>\Y%K1H?(???[?ZXt?k???????T?V?D^"1?Xy?œ??@ ??q?????i?@ 044t????)sp?nmm?{wcc?F?????~S?T?!n? >??????c#K???%O?m?Jmn?-?/_??^????????????G??G??5??+???%W?F??3W??u_?U?;w??????Y?w????a??? Ue[^???o???+?]???????rC?????~??-q?X????{?j?z?t: ????#?Z??m?e???^Y -1??R?B????????_?i?)?3?X?\]Z^YY?????$? -?2?ZZ??????7?,Q??m&ZP+T?f6/???n??D??b?N?O?)%DbZ^rI4???????Bp??T?*q???+5 ??@A?? I,cI???.?x?b5??z?$?p8??????4X8???i?D"?????.};?y?f??l??????W~????'S -q???????[?}K???o?????q]??'???I????u -??h???t??x#?C?_?. -???u?b?Uu??? ??Q?"???_??????6?i???/?{?Nm?k9???.????T?O????G;???O??-C??????miiI ?FH.pG??,C? ?a?o||? ?I o?#???:???'!??L2;? ?0?????xw????po?e ????+--?l@ ? -dkZ???? ?D?~W?~PE?dOOOSS?d?l??-?g?}&?H???òl(jmm?cG?s?lC -?]?(j||? -a?w?;???e?g??k???5?L&`5%w??F??#pC!?f)9?<\?t)?j?????|?@ ???e????>>'? ?????V???J~;?j?z??kkk6?-_f!?A??Hdlll3??q?,???H$R(:?nll 6?H?Z?F?????OF???;???#??a??azN?r?????? ?1?@?Ev"?x-?SSS8?*(?(rA???3::*???$)???~????hSt???ry?8???r?Zm4??? q??!???l?81y?/o?)????rya??e?8?KS=?e?q??;?jEUuUs?????4 -$)?*???,\(????N'? ??{????^_8w@??9?c#???p???[???"???85=???{?f???J??}??g_??P???]????u??wGP???|?,?[????*?J?*))?|?rggg!2PB??|??!wZ\???VB???/_7y??w^x??F/?LN??a??#?}???<B?\4?????z{{O?:??????g7??G????????b??hh(o???w??5U(???Rn[?·j?:????.??T2???D?T?????I??I+??H????1 -????6?B {?[A?z????/PK??8I??P? ?T?P??%%%F????#?;??????Kg??F? -?^ä?(8???????n?V\{?.P?k??C&2?y?Z=????w"&?? =?e?eyh??y??ny??????mV'@???)????????_O?+???~z6??Cr@P?U?PVpm??s?????+**????Je?????Í?s???L?>?????i??D???'w(?????g8!????R??j????]]]???]>u?3?J?i???]Zle???G' -??-??[S?N?????s?????(?\?????,??B?C~??????G?U??e??[Hnd9?06????"DD$q/?$ -??????????Z?k???????????#}E?G]zpr ?????????3???,]???@???DP???]?r??mt??L??????f?o???=?lT??['??;??K????????W7??F????l]?b??? ??*?$??????b?a>???o???????s?c??6?#???=????v}?`m\??}?bJ?V?h??t??"?Q?-?A??W}aD?b<?O????%?*?k*??:?ut?w???W??S?F??????g???p?O??????ub???;U???m???bfC?B???>V??Y?_?x -???D"???2?LB6I??OQ?(r?$?Z-????B???????9??w??;??k????%?7?F;????????? ?S?????????Jq~?????:XE?????A??8?:?ap???s#??.Rqq?dt ?V/g]^a5??? P? O??????. ?$m6?R??h?v? x?????????????J????)?(???a?L????????w?}7??=????c??g2 ????t:????QO????E???2? ??[P??on??l????+g?O?? eO?7???(@:??s???+'_O? ?????uy???R ??????L&?B????????Z?H??2?~dG_?%UeD[f???????b???q????]????+?????o.?????+4???r????DUR?R(d -a?(?-Ml????????**?u??:?????n-?cy?w??H$J?????H?h.???QG ?\??{D???J?$=?2??"B???2'? +???F?4^? -*????????}?DW4U?s3?r}?x?f?J??j`?}?Ib9i??1????;A?E??????L&??[W?a - - -???$I?|?P(???b?Z???s??aX?eYV"?????????[S???`0??L?| YQC{78?U?>??K#?????O??????a?7.???? -?%?S???L~2@Ug?,????_NvU? -?E?t??u?3????O??l?(^?= s??e?4?X -???????C+???N????s?Ri?t-???;?B??j??o\`??m&Z??0???h^)n??U9?h?? d -* Pl???~o$?u?Y?1 (???p???biz????W?-??$????/~??"??e???V?;?>?1?6?u?7???V ?B[ÿ?????{?R?A%??s?????4???#??}J????k7? -z????S????!??n -???"?(?????uB?'?? +U? ?"%???D?~DZ????3???!??vX,Kk$?????:m K?`Es?4z.?u??@T]W??R?B??r??{???? -y?ZVZZj4?^/????LNNNNN?wt?,KQI?$I???????????????$???1???of{??O-?w??U??7_???{l??1?{o????b&G?uy7???<2?>??/|?JGGG8?9?C???^O?Nx?? -? E#??, ?!???(e?w-.oB,D"$??J?J?.??)???Qmk?N??+???Sy?Z?2 B????????hB?\t4M;????E?)_ -?0???????>n???h*++?Z?L&?W??H$?????????{??????~??>r?{W[?8?d?j?l4Vb t???v????-??o??`???i??N?}-???w??_??Hq??q~x?5????????[?vW??|???;]???????Zc?8c? ???^???????-?H???f?L/ ??orCy????oN?{j??????45?q?]_n/`n???y7&?????????o??"}??J?A8??????,?????\@??Z??B@-l?d?J\???CH%??+T???"T|?EX4?MJK?B?8?f??J ?>\Y%K1H?(???[?ZXt?k???????T?V?D^"1?Xy?œ??@ ??q?????i?@ 044t????)sp?nmm?{wcc?F?????~S?T?!n? >??????c#K???%O?m?Jmn?-?/_??^????????????G??G??5??+???%W?F??3W??u_?U?;w??????Y?w????a??? Ue[^???o???+?]???????rC?????~??-q?X????{?j?z?t: ????#?Z??m?e???^Y -1??R?B????????_?i?)?3?X?\]Z^YY?????$? -?2?ZZ??????7?,Q??m&ZP+T?f6/???n??D??b?N?O?)%DbZ^rI4???????Bp??T?*q???+5 ??@A?? I,cI???.?x?b5??z?$?p8??????4X8???i?D"?????.};?y?f??l??????W~????'S -q???????[?}K???o?????q]??'???I????u -??h???t??x#?C?_?. -???u?b?Uu??? ??Q?"???_??????6?i???/?{?Nm?k9???.????T?O????G;???O??-C??????miiI ?FH.pG??,C? ?a?o||? ?I o?#???:???'!??L2;? ?0?????x1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { - return true; - } else { - return false; - } + return self::isDigitsPresent($input, [49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1]); } - function isPandigitalWithZero(int $input) + public static function isPandigitalWithZero(int $input): bool { - $array = count_chars($input,1); + return self::isDigitsPresent($input, [48 => 0, 49 => 1, 50 => 1, 51 => 1, 52 => 1, 53 => 1, 54 => 1, 55 => 1, 56 => 1, 57 => 1]); + } + + private static function isDigitsPresent(int $input, array $count): bool + { + $array = count_chars((string)$input, 1); ksort($array); - if($array == array(48=>0, 49=>1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { - return true; + if ($array == $count) { + return TRUE; } else { - return false; + return FALSE; } } -} \ No newline at end of file +} diff --git a/src/Prime.php b/src/Prime.php index 54b500b..cd8508a 100644 --- a/src/Prime.php +++ b/src/Prime.php @@ -1,46 +1,47 @@ assertTrue(Numerical::isPandigital(123456789)); + $this->assertTrue(Numerical::isPandigital(987654321)); + $this->assertTrue(Numerical::isPandigital(789456123)); + $this->assertTrue(Numerical::isPandigital(321654987)); + + $this->assertFalse(Numerical::isPandigital(0)); + $this->assertFalse(Numerical::isPandigital(1)); + $this->assertFalse(Numerical::isPandigital(111111111)); + $this->assertFalse(Numerical::isPandigital(999999999)); + $this->assertFalse(Numerical::isPandigital(1234567890)); + } + + public function testisPandigitalWithZero(): void + { + $this->assertTrue(Numerical::isPandigitalWithZero(1234567890)); + $this->assertTrue(Numerical::isPandigitalWithZero(9876543210)); + $this->assertTrue(Numerical::isPandigitalWithZero(7894561230)); + $this->assertTrue(Numerical::isPandigitalWithZero(3216549870)); + + $this->assertFalse(Numerical::isPandigitalWithZero(123456780)); + $this->assertFalse(Numerical::isPandigitalWithZero(123456789)); + $this->assertFalse(Numerical::isPandigitalWithZero(987654321)); + $this->assertFalse(Numerical::isPandigitalWithZero(789456123)); + $this->assertFalse(Numerical::isPandigitalWithZero(321654987)); + } +} diff --git a/tests/PrimeTest.php b/tests/PrimeTest.php index 80303b6..5fd270f 100644 --- a/tests/PrimeTest.php +++ b/tests/PrimeTest.php @@ -12,14 +12,12 @@ use CodingTests\Prime; #[CoversClass(Prime::class)] final class PrimeTest extends \PHPUnit\Framework\TestCase { - public function testisPrime(): void + public function isPandigital(): void { $primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]; - for($test=-100;$test<=100;$test++) - { + for ($test = -100; $test <= 100; $test++) { $ret = Prime::isPrime($test); $this->assertEquals(in_array($test, $primes), $ret, "Testing $test"); - } } -} \ No newline at end of file +}