Restructuring
This commit is contained in:
CT.rbcomposer.jsoncomposer.lockct.bat
data/primes
nbproject
phpunit.xmlsettings.ymlsolutions
CodeChef/easy
CodeGolf/guns-and-zips
Generic
ProjectEuler
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
041
042
043
044
045
048
104
desc.ymlsrc
template.rttests
vendor
13
solutions/CodeChef/easy/HS08TEST/solve.php
Normal file
13
solutions/CodeChef/easy/HS08TEST/solve.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
while($s=explode(' ',trim(fgets(STDIN)))) {
|
||||
|
||||
if($s[1]%5) {
|
||||
echo $s[1];
|
||||
} else {
|
||||
$new = round($s[1]-$s[1]-0.5,2);
|
||||
if($new)
|
||||
echo $new;
|
||||
else
|
||||
echo $s[1];
|
||||
}
|
||||
}
|
7
solutions/CodeChef/easy/TEST/solve.php
Normal file
7
solutions/CodeChef/easy/TEST/solve.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
echo fgets(STDIN);
|
||||
while($s = fgets(STDIN)) {
|
||||
if(trim($s) == '42')
|
||||
die;
|
||||
echo $s;
|
||||
}
|
53
solutions/CodeGolf/guns-and-zips/input.1
Normal file
53
solutions/CodeGolf/guns-and-zips/input.1
Normal file
@ -0,0 +1,53 @@
|
||||
??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???<3F>l(jmm?cG?s?lC
|
||||
?]?(j||<???H?R???J?4M?,+????S]?@?Sp????H$BD?d8??L&?e?;M????'?l??7??|d?X?a? P?H)xK?r???a???R?KKKkkk?1d?PX?G"?la???D????ryA??l7
|
||||
?]??e??eE???
|
||||
?dR?1?N?cF`?`0X??@ ????a?cr?l6???Z???l+
|
||||
+r??g0?b????H$-?{?VVQ?P?eY?Au,?)??f ?n?N??j?????'2s$?D???}?????????R??
|
||||
?@?K?E<>??h?x?"A?5g?iZ???'?"gYvlllaa!?r?T?4??(EQy????????T*?j?*EQUUU???(?<3F>:?w?&*??433#?H?]?.??nw0?Dpm)?w?#???Y????#=
|
||||
? ?`pttTx`NDn4sV8?a????????c?"?X,R?t?=m?Xl4???&??@????~???T*?|>?
|
||||
a?w?;???e?g??k???5?L&`5%w??F??#pC!?f)9?<\?t)?j?????|?@ ???e????<Nk?4???S^^>>>'? ?????V???J~;?j?z??kkk6?-_f!?A??Hdlll3??q?,???H$R(:?nll6?H?Z?F?????OF???;???#??a??azN?r???????1?@?Ev"?x<?J??f?[j??????V?5???@?-?|yy9?
|
||||
G?a?h@+??===###[?Me?O?,D<>??j-?'?!I2z???_???b?o?lC?y0?z????A?<3F>?'?w/\|
|
||||
???,k?X
|
||||
????V?N????l.?!?m?P?33;;[?:?B??"???w??y?C ?D???v{8.?l?$~S???? ????B??>-?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[?<3F>j?:????.??T2???D?T?????I??I+??H????1
|
||||
????6?B{?[A?z????/PK??8I??P? ?T?P??%%%F????#?;??????Kg??F?
|
||||
?^<5E>?(8???????n?V\{?.P?k??C&2?y?Z=????w"&?? =?e?eyh??y??ny??????mV'@???)????????_O?+???~z6??Cr@P?U?PVpm??s?????+**????Je?????<3F>?s???L?>?????i??D???'w(?????g8!???<????*????7M?J??(??????????l?? ?d9? ???rH?b??eY???v????e2?^???t?>?R??j????]]]???]>u?3?J?i???]Zle???G'
|
||||
??-??[S?N?????s?????(?\?????,??B?C~??????G?U??e??[Hnd9?06????"DD$q/?$
|
||||
??????????Z?k?????????<l~6V???=?????og?}??????_???X??o>??#}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<???o?g?^^?z{???IL???m[@Hv?Ag?(J????o??fA?RiUU?K?????\?:5??B
|
||||
?CiB????#I???#???
|
||||
?!??????NZ??K????o???j??r???;??]?b;M??|??;w$f69?3b{+??$I?<p?]R???X?????`??#?????t????o??????Lf?AM???B$??P(?}qm?]I???22?M?&p??+?+??;/??$u?????????k*l??O?|4K?1??x?[?N2??4????w???O???]??#?7?e???? ??0??1??,.?=?????Z?$I~!
|
||||
?`Y6?o?D"iii???p]?0??gb??^????7?t?k?b????????qLY?;?pUu?]m?M?t? _?U?xp?M????????^???`???????<??W?<^?8?R2W|??^?H? "?l??????Iwttd??1?<???????z??????;???s?Kc??????@???j0???'y>??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<??u???d*[<5B>?*B?d?U*????.]R*?\DY??.??Y?eEQnII?u??P(TVV?w??D???.\?gOjXE?X6$??#r??xU*c_ X?~??l????????F??Wa(vj????z?????LCl??:M1 m??%!W*E??Y??&???, ???+???knn9,?0@S4??n?Ve7CpX?????????R4???W??U?D?0??i? ?e????$Yd???u-?Yf??{????$PT?k5q3??Ew[??N+))a???AE+++Q
|
||||
??4Mbkt?e#?H8??????????b??MD?kk?S????2D?Yg?[M)<29>?j??T<>?\??me??F[.?f???H?J?L?p??G?2?U??????;?|??????(K??????{?d9?w??dI??????2(??hmiim?h?W??`??8?cl?v??+?3??d?@??w?u?oe?,?U????Tx??????????6???M0????j?????n?V????E-..???5.N&??8y?,??F???Ht?u?????Ti?v?c???>?~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?-??$??<WW5u-??q?????4??R?P?H$??,A??h4:?N*?R?W\1?u?)?R(???;v????[;;;* ????.\??2??????>??/~??"??e???V?;?>?1?6?u?7???V ?B[<5B>?????{?R?A%??s?????4???#??}J????k7?
|
||||
z????S????!??n
|
||||
???"?(?????uB?'?? +U? ?"%???D?~DZ????3???!??vX,Kk$?????:mK?`Es?4z.?u??@T]W??R?B??r??{????
|
||||
y?ZVZZj4?^/????LNNNNN?wt?,KQI?$I?????????<xpppp??????%%%9??455??vn??w?3???????o???^????=????y?][?o?7n??????????o?\??'????u???'~???=?>??????$???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?l4Vbt???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?<1E>??@ ??q?????i?@ 044t????)sp?nmm?{wcc?F?????~S?T?!n? >??????c#K???%O?m?Jmn?-?/_??^????????????G??G??5??+???%W?F??3W??u_?U?;w?????<???????u
|
||||
A/Duc?W??o}?_B[?>?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<?%?a(
|
||||
???????A??M??????$?r?????9?|zzzjjJ"???????????g????on???Tn?(!??????+?Kre?VSS[^SQ?????Uw(?KJ?????????
|
||||
???????9<>'H?8?I??E?M?G???
|
||||
?I~1k*j?5???'????? ~`&D84M;?N????????s?????Vkg[$immmkk?=??`??\???1??????????A??VUU?4???q\?????????~?TVVR%|??T*moo?
|
||||
??T???d%?E?E Y?"??????? eeei?? ?mK."_XX??|E?a???????d???(???!?xr?F?!?[???????>?o||??Io?#???:???'!??L2;? ?0?????x<??ES?? BQ?F???????25/8??????*??
|
||||
?\.Wuu???q/???D?}9?4MQ????w
|
||||
?????uuu?`?eY?????QE$?-??H$BQ?a???Q?V??O??$944? ???FQT$I?R8??aB??????||?4??2??m?9?P%I??t???T}rN?E?????f~w?qn?????????]??{??Enh???????C.???G??7??M??$???????RIEND?B`??*??
|
53
solutions/CodeGolf/guns-and-zips/output.1
Normal file
53
solutions/CodeGolf/guns-and-zips/output.1
Normal file
@ -0,0 +1,53 @@
|
||||
?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???<3F>l(jmm?cG?s?lC
|
||||
?]?(j||<???H?R???J?4M?,+????S]?@?Sp????H$BD?d8??L&?e?;M????'?l??7??|d?X?a? P?H)xK?r???a???R?KKKkkk?1d?PX?G"?la???D????ryA??l7
|
||||
?]??e??eE???
|
||||
?dR?1?N?cF`?`0X??@ ????a?cr?l6???Z???l+
|
||||
+r??g0?b????H$-?{?VVQ?P?eY?Au,?)??f ?n?N??j?????'2s$?D???}?????????R??
|
||||
?@?K?E<>??h?x?"A?5g?iZ???'?"gYvlllaa!?r?T?4??(EQy????????T*?j?*EQUUU???(?<3F>:?w?&*??433#?H?]?.??nw0?Dpm)?w?#???Y????#=
|
||||
? ?`pttTx`NDn4sV8?a????????c?"?X,R?t?=m?Xl4???&??@????~???T*?|>?
|
||||
a?w?;???e?g??k???5?L&`5%w??F??#pC!?f)9?<\?t)?j?????|?@ ???e????<Nk?4???S^^>>>'? ?????V???J~;?j?z??kkk6?-_f!?A??Hdlll3??q?,???H$R(:?nll6?H?Z?F?????OF???;???#??a??azN?r???????1?@?Ev"?x<?J??f?[j??????V?5???@?-?|yy9?
|
||||
G?a?h@+??===###[?Me?O?,D<>??j-?'?!I2z???_???b?o?lC?y0?z????A?<3F>?'?w/\|
|
||||
???,k?X
|
||||
????V?N????l.?!?m?P?33;;[?:?B??"???w??y?C ?D???v{8.?l?$~S???? ????B??>-?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[?<3F>j?:????.??T2???D?T?????I??I+??H????1
|
||||
????6?B{?[A?z????/PK??8I??P? ?T?P??%%%F????#?;??????Kg??F?
|
||||
?^<5E>?(8???????n?V\{?.P?k??C&2?y?Z=????w"&?? =?e?eyh??y??ny??????mV'@???)????????_O?+???~z6??Cr@P?U?PVpm??s?????+**????Je?????<3F>?s???L?>?????i??D???'w(?????g8!???<????*????7M?J??(??????????l?? ?d9? ???rH?b??eY???v????e2?^???t?>?R??j????]]]???]>u?3?J?i???]Zle???G'
|
||||
??-??[S?N?????s?????(?\?????,??B?C~??????G?U??e??[Hnd9?06????"DD$q/?$
|
||||
??????????Z?k?????????<l~6V???=?????og?}??????_???X??o>??#}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<???o?g?^^?z{???IL???m[@Hv?Ag?(J????o??fA?RiUU?K?????\?:5??B
|
||||
?CiB????#I???#???
|
||||
?!??????NZ??K????o???j??r???;??]?b;M??|??;w$f69?3b{+??$I?<p?]R???X?????`??#?????t????o??????Lf?AM???B$??P(?}qm?]I???22?M?&p??+?+??;/??$u?????????k*l??O?|4K?1??x?[?N2??4????w???O???]??#?7?e???? ??0??1??,.?=?????Z?$I~!
|
||||
?`Y6?o?D"iii???p]?0??gb??^????7?t?k?b????????qLY?;?pUu?]m?M?t? _?U?xp?M????????^???`???????<??W?<^?8?R2W|??^?H? "?l??????Iwttd??1?<???????z??????;???s?Kc??????@???j0???'y>??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<??u???d*[<5B>?*B?d?U*????.]R*?\DY??.??Y?eEQnII?u??P(TVV?w??D???.\?gOjXE?X6$??#r??xU*c_ X?~??l????????F??Wa(vj????z?????LCl??:M1 m??%!W*E??Y??&???, ???+???knn9,?0@S4??n?Ve7CpX?????????R4???W??U?D?0??i? ?e????$Yd???u-?Yf??{????$PT?k5q3??Ew[??N+))a???AE+++Q
|
||||
??4Mbkt?e#?H8??????????b??MD?kk?S????2D?Yg?[M)<29>?j??T<>?\??me??F[.?f???H?J?L?p??G?2?U??????;?|??????(K??????{?d9?w??dI??????2(??hmiim?h?W??`??8?cl?v??+?3??d?@??w?u?oe?,?U????Tx??????????6???M0????j?????n?V????E-..???5.N&??8y?,??F???Ht?u?????Ti?v?c???>?~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?-??$??<WW5u-??q?????4??R?P?H$??,A??h4:?N*?R?W\1?u?)?R(???;v????[;;;* ????.\??2??????>??/~??"??e???V?;?>?1?6?u?7???V ?B[<5B>?????{?R?A%??s?????4???#??}J????k7?
|
||||
z????S????!??n
|
||||
???"?(?????uB?'?? +U? ?"%???D?~DZ????3???!??vX,Kk$?????:mK?`Es?4z.?u??@T]W??R?B??r??{????
|
||||
y?ZVZZj4?^/????LNNNNN?wt?,KQI?$I?????????<xpppp??????%%%9??455??vn??w?3???????o???^????=????y?][?o?7n??????????o?\??'????u???'~???=?>??????$???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?l4Vbt???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?<1E>??@ ??q?????i?@ 044t????)sp?nmm?{wcc?F?????~S?T?!n? >??????c#K???%O?m?Jmn?-?/_??^????????????G??G??5??+???%W?F??3W??u_?U?;w?????<???????u
|
||||
A/Duc?W??o}?_B[?>?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<?%?a(
|
||||
???????A??M??????$?r?????9?|zzzjjJ"???????????g????on???Tn?(!??????+?Kre?VSS[^SQ?????Uw(?KJ?????????
|
||||
???????9<>'H?8?I??E?M?G???
|
||||
?I~1k*j?5???'????? ~`&D84M;?N????????s?????Vkg[$immmkk?=??`??\???1??????????A??VUU?4???q\?????????~?TVVR%|??T*moo?
|
||||
??T???d%?E?E Y?"??????? eeei?? ?mK."_XX??|E?a???????d???(???!?xr?F?!?[???????>?o||??Io?#???:???'!??L2;? ?0?????x<??ES?? BQ?F???????25/8??????*??
|
||||
?\.Wuu???q/???D?}9?4MQ????w
|
||||
?????uuu?`?eY?????QE$?-??H$BQ?a???Q?V??O??$944? ???FQT$I?R8??aB??????||?4??2??m?9?P%I??t???T}rN?E?????f~w?qn?????????]??{??Enh???????C.???G??7??M??$???????RIEND?B`?
|
0
solutions/CodeGolf/guns-and-zips/solve.php
Normal file
0
solutions/CodeGolf/guns-and-zips/solve.php
Normal file
11
solutions/Generic/99Bottles/desc.yml
Normal file
11
solutions/Generic/99Bottles/desc.yml
Normal file
@ -0,0 +1,11 @@
|
||||
title: FizzBuzz
|
||||
url: http://99-bottles-of-beer.net/
|
||||
|
||||
desc: Generate the lyrics to the song 99 Bottles of Beer as an output.
|
||||
|
||||
solution: See the code...
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
18
solutions/Generic/99Bottles/solve.php
Normal file
18
solutions/Generic/99Bottles/solve.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?
|
||||
for ($beer=99; $beer>=0; $beer--)
|
||||
{
|
||||
if ($beer==0) {
|
||||
echo "No more bottles of beer on the wall, no more bottles of beer.".PHP_EOL;
|
||||
echo "Go to the store and buy some more, 99 bottles of beer on the wall.".PHP_EOL;
|
||||
}
|
||||
elseif ($beer==1) {
|
||||
echo "1 bottle of beer on the wall, 1 bottle of beer.".PHP_EOL;
|
||||
echo "Take one down and pass it around, no more bottles of beer on the wall.". PHP_EOL . PHP_EOL;
|
||||
} elseif ($beer==2) {
|
||||
echo $beer." bottles of beer on the wall, ".$beer." bottles of beer." . PHP_EOL;
|
||||
echo "Take one down and pass it around, ".($beer-1)." bottle of beer on the wall.".PHP_EOL . PHP_EOL;
|
||||
} else {
|
||||
echo $beer." bottles of beer on the wall, ".$beer." bottles of beer." . PHP_EOL;
|
||||
echo "Take one down and pass it around, ".($beer-1)." bottles of beer on the wall.".PHP_EOL . PHP_EOL;
|
||||
}
|
||||
}
|
17
solutions/Generic/FIZZBUZZ/desc.yml
Normal file
17
solutions/Generic/FIZZBUZZ/desc.yml
Normal file
@ -0,0 +1,17 @@
|
||||
title: FizzBuzz
|
||||
url: http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
|
||||
|
||||
desc: The classical coding challenge. Write a program that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz.
|
||||
|
||||
solution: See the code...
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
22
solutions/Generic/FIZZBUZZ/solve.c
Normal file
22
solutions/Generic/FIZZBUZZ/solve.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
int i = 0;
|
||||
for(i = 1; i <= 100; i++)
|
||||
{
|
||||
if(i % 3 == 0)
|
||||
{
|
||||
printf( "Fizz" );
|
||||
}
|
||||
if(i % 5 == 0)
|
||||
{
|
||||
printf( "Buzz" );
|
||||
}
|
||||
if(i % 3 && i % 5)
|
||||
{
|
||||
printf( "%d", i );
|
||||
}
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
13
solutions/Generic/FIZZBUZZ/solve.php
Normal file
13
solutions/Generic/FIZZBUZZ/solve.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
for($i=1; $i<=100; $i++) {
|
||||
if($i % 3 == 0) {
|
||||
print "Fizz";
|
||||
}
|
||||
if($i % 5 == 0) {
|
||||
print "Buzz";
|
||||
}
|
||||
if($i % 3 AND $i % 5) {
|
||||
print $i;
|
||||
}
|
||||
print PHP_EOL;
|
||||
}
|
12
solutions/Generic/FIZZBUZZ/solve.rb
Normal file
12
solutions/Generic/FIZZBUZZ/solve.rb
Normal file
@ -0,0 +1,12 @@
|
||||
(1..100).each do |i|
|
||||
if(i % 3 == 0)
|
||||
print "Fizz";
|
||||
end
|
||||
if(i % 5 == 0)
|
||||
print "Buzz"
|
||||
end
|
||||
if(i % 3 != 0 and i % 5 != 0)
|
||||
print i
|
||||
end
|
||||
print "\n";
|
||||
end
|
BIN
solutions/Generic/Fibonacci/a.exe
Normal file
BIN
solutions/Generic/Fibonacci/a.exe
Normal file
Binary file not shown.
51
solutions/Generic/Fibonacci/solve.c
Normal file
51
solutions/Generic/Fibonacci/solve.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define SIZE 20
|
||||
|
||||
|
||||
|
||||
void add(char *a, char *b, char *result, int size) {
|
||||
int i = 0;
|
||||
for(i=0;i<size;i++) {
|
||||
//We have overflow!
|
||||
if((a[i] + b[i] + result[i] < a[i]) || (a[i] + b[i] + result[i] < b[i])) {
|
||||
result[i+1]++;
|
||||
}
|
||||
result[i]+= a[i] + b[i];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main( )
|
||||
{
|
||||
unsigned char prev[SIZE];
|
||||
unsigned char current[SIZE];
|
||||
unsigned char next[SIZE];
|
||||
unsigned int i=0;
|
||||
memset(prev,0x00,SIZE);
|
||||
memset(current,0x00,SIZE);
|
||||
memset(next,0x00,SIZE);
|
||||
prev[0]=1;
|
||||
current[0]=1;
|
||||
next[0]=1;
|
||||
|
||||
for(i=2;i<100;i++) {
|
||||
|
||||
add(current,prev,next,SIZE);
|
||||
memcpy(prev,current,SIZE);
|
||||
memcpy(current,next,SIZE);
|
||||
//prev = current;
|
||||
//current = next;
|
||||
int j;
|
||||
for(j=0;j<SIZE;j++) {
|
||||
printf("%d: %i\n",j,current[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<SIZE;i++) {
|
||||
printf("%d: %i\n",i,current[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
solutions/Generic/Fibonacci/solve.exe
Normal file
BIN
solutions/Generic/Fibonacci/solve.exe
Normal file
Binary file not shown.
19
solutions/Generic/HelloWorld/desc.yml
Normal file
19
solutions/Generic/HelloWorld/desc.yml
Normal file
@ -0,0 +1,19 @@
|
||||
title: HelloWorld
|
||||
url: http://en.wikipedia.org/wiki/Hello_world_program
|
||||
|
||||
desc: A "Hello world" program is a computer program that outputs "Hello, world" on a display device.
|
||||
solution: Do i need to say more
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: js
|
7
solutions/Generic/HelloWorld/solve.c
Normal file
7
solutions/Generic/HelloWorld/solve.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
printf( "Hello World" );
|
||||
|
||||
}
|
1
solutions/Generic/HelloWorld/solve.js
Normal file
1
solutions/Generic/HelloWorld/solve.js
Normal file
@ -0,0 +1 @@
|
||||
console.log("Hello World");
|
2
solutions/Generic/HelloWorld/solve.php
Normal file
2
solutions/Generic/HelloWorld/solve.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo 'Hello World';
|
1
solutions/Generic/HelloWorld/solve.rb
Normal file
1
solutions/Generic/HelloWorld/solve.rb
Normal file
@ -0,0 +1 @@
|
||||
puts "Hello World"
|
20
solutions/Generic/MultiTable/solve.c
Normal file
20
solutions/Generic/MultiTable/solve.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#define SIZE_X 12
|
||||
#define SIZE_Y 12
|
||||
void main()
|
||||
{
|
||||
int x,y;
|
||||
int MemorizeThis[SIZE_X][SIZE_Y];
|
||||
for (x =1; x <= SIZE_X; x++)
|
||||
{
|
||||
for (y = 1; y <= SIZE_Y; y++)
|
||||
{
|
||||
MemorizeThis[x-1][y-1] = x * y;
|
||||
printf("[%03d]", MemorizeThis[x-1][y-1]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
10
solutions/Generic/Seive/desc.yml
Normal file
10
solutions/Generic/Seive/desc.yml
Normal file
@ -0,0 +1,10 @@
|
||||
title: Sieve of Eratosthenes
|
||||
url: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||
|
||||
desc:Generate primes from 2 to 100
|
||||
solution: Do i need to say more
|
||||
|
||||
solutions:
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
22
solutions/Generic/Seive/solve.c
Normal file
22
solutions/Generic/Seive/solve.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void main( )
|
||||
{
|
||||
unsigned char primes[100];
|
||||
int p;
|
||||
int j;
|
||||
memset(&primes, 1, 50 );
|
||||
for( p = 2; p<=10; p++) {
|
||||
if (primes[p]) {
|
||||
for(j = p*p; j <= 100; j+= p){
|
||||
primes[j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf( "Primes:%d\n", sizeof(primes)) ;
|
||||
for(p=0;p<sizeof(primes);p++) {
|
||||
if(primes[p]) {
|
||||
printf( "%d\n",p);
|
||||
}
|
||||
}
|
||||
}
|
4
solutions/Generic/desc.yml
Normal file
4
solutions/Generic/desc.yml
Normal file
@ -0,0 +1,4 @@
|
||||
title: Generic
|
||||
url: http://google.com
|
||||
|
||||
desc: Various problems that doesn't fit any catagory
|
26
solutions/ProjectEuler/001/desc.yml
Normal file
26
solutions/ProjectEuler/001/desc.yml
Normal file
@ -0,0 +1,26 @@
|
||||
title: Add all the natural numbers below one thousand that are multiples of 3 or 5.
|
||||
url: http://projecteuler.net/problem=1
|
||||
|
||||
desc: |
|
||||
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
|
||||
Find the sum of all the multiples of 3 or 5 below 1000.
|
||||
|
||||
solution: |
|
||||
Loop numbers from 1-1000 - Use mod to find the multiples
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: javascript
|
||||
solve.lua:
|
||||
desc: Basic solution
|
||||
language: lua
|
15
solutions/ProjectEuler/001/solve.c
Normal file
15
solutions/ProjectEuler/001/solve.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
for(i = 1; i < 1000; i++)
|
||||
{
|
||||
if(i % 3 == 0 || i % 5 == 0)
|
||||
{
|
||||
sum += i;
|
||||
}
|
||||
}
|
||||
printf( "%i", sum );
|
||||
}
|
9
solutions/ProjectEuler/001/solve.js
Normal file
9
solutions/ProjectEuler/001/solve.js
Normal file
@ -0,0 +1,9 @@
|
||||
sum = 0;
|
||||
i = 0;
|
||||
for(i=1; i<1000;i++) {
|
||||
if(i % 3 == 0 || i % 5 == 0) {
|
||||
sum += i;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(sum);
|
7
solutions/ProjectEuler/001/solve.lua
Normal file
7
solutions/ProjectEuler/001/solve.lua
Normal file
@ -0,0 +1,7 @@
|
||||
sum = 0
|
||||
for i=1,999 do
|
||||
if i % 3 == 0 or i % 5 == 0 then
|
||||
sum = sum + i
|
||||
end
|
||||
end
|
||||
print(sum)
|
10
solutions/ProjectEuler/001/solve.php
Normal file
10
solutions/ProjectEuler/001/solve.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
$sum = 0;
|
||||
$i = 0;
|
||||
for($i=1; $i<1000;$i++) {
|
||||
if($i % 3 == 0 OR $i % 5 == 0) {
|
||||
$sum += $i;
|
||||
}
|
||||
}
|
||||
|
||||
echo $sum;
|
7
solutions/ProjectEuler/001/solve.rb
Normal file
7
solutions/ProjectEuler/001/solve.rb
Normal file
@ -0,0 +1,7 @@
|
||||
sum = 0
|
||||
(1..1000).each do |i|
|
||||
if(i % 3 == 0 or i % 5 == 0)
|
||||
sum += i
|
||||
end
|
||||
end
|
||||
puts sum
|
27
solutions/ProjectEuler/002/desc.yml
Normal file
27
solutions/ProjectEuler/002/desc.yml
Normal file
@ -0,0 +1,27 @@
|
||||
title: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
|
||||
url: http://projecteuler.net/problem=2
|
||||
|
||||
desc: |
|
||||
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
|
||||
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
|
||||
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
|
||||
|
||||
solution: |
|
||||
Step through the fibonacci sequence while you sum each even entry. Quit as you reach 4million
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: javascript
|
||||
solve.lua:
|
||||
desc: Basic solution
|
||||
language: lua
|
18
solutions/ProjectEuler/002/solve.c
Normal file
18
solutions/ProjectEuler/002/solve.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
int sum = 2;
|
||||
int fib[3] = { 1, 2, 3 };
|
||||
|
||||
while(fib[2] < 4000000)
|
||||
{
|
||||
fib[2] = fib[0] + fib[1];
|
||||
if(fib[2] % 2 == 0)
|
||||
sum += fib[2];
|
||||
|
||||
fib[0] = fib[1];
|
||||
fib[1] = fib[2];
|
||||
}
|
||||
printf( "%i", sum );
|
||||
}
|
11
solutions/ProjectEuler/002/solve.js
Normal file
11
solutions/ProjectEuler/002/solve.js
Normal file
@ -0,0 +1,11 @@
|
||||
sum = 2;
|
||||
fib = new Array( 1, 2, 3 );
|
||||
while(fib[2] < 4000000)
|
||||
{
|
||||
fib[2] = fib[0] + fib[1];
|
||||
if(fib[2] % 2 == 0)
|
||||
sum += fib[2];
|
||||
fib[0] = fib[1];
|
||||
fib[1] = fib[2];
|
||||
}
|
||||
console.log(sum );
|
11
solutions/ProjectEuler/002/solve.lua
Normal file
11
solutions/ProjectEuler/002/solve.lua
Normal file
@ -0,0 +1,11 @@
|
||||
sum = 2
|
||||
fib = {1, 2, 3}
|
||||
while fib[2] < 4000000 do
|
||||
fib[3] = fib[1] + fib[2]
|
||||
if(fib[3] % 2 == 0) then
|
||||
sum = sum + fib[3]
|
||||
end
|
||||
fib[1] = fib[2]
|
||||
fib[2] = fib[3]
|
||||
end
|
||||
print (sum )
|
12
solutions/ProjectEuler/002/solve.php
Normal file
12
solutions/ProjectEuler/002/solve.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
$fib = array(1,2,3);
|
||||
$sum = 2;
|
||||
while($fib[2] < 4000000) {
|
||||
$fib[2] = $fib[0] + $fib[1];
|
||||
if($fib[2] % 2 == 0) {
|
||||
$sum += $fib[2];
|
||||
}
|
||||
$fib[0] = $fib[1];
|
||||
$fib[1] = $fib[2];
|
||||
}
|
||||
echo $sum;
|
11
solutions/ProjectEuler/002/solve.rb
Normal file
11
solutions/ProjectEuler/002/solve.rb
Normal file
@ -0,0 +1,11 @@
|
||||
fib = [1, 2, 3];
|
||||
sum = 2;
|
||||
while(fib[2] < 4000000)
|
||||
fib[2] = fib[0] + fib[1];
|
||||
if(fib[2] % 2 == 0)
|
||||
sum += fib[2];
|
||||
end
|
||||
fib[0] = fib[1];
|
||||
fib[1] = fib[2];
|
||||
end
|
||||
puts sum;
|
15
solutions/ProjectEuler/003/desc.yml
Normal file
15
solutions/ProjectEuler/003/desc.yml
Normal file
@ -0,0 +1,15 @@
|
||||
title: Find the largest prime factor of a composite number.
|
||||
url: http://projecteuler.net/problem=3
|
||||
|
||||
desc: |
|
||||
The prime factors of 13195 are 5, 7, 13 and 29.
|
||||
What is the largest prime factor of the number 600851475143 ?
|
||||
|
||||
solution: |
|
||||
Use factorization to find the largest prime factor
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
|
33
solutions/ProjectEuler/003/solve.php
Normal file
33
solutions/ProjectEuler/003/solve.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
$number = 600851475143;
|
||||
|
||||
echo max(factorize($number));
|
||||
|
||||
/**
|
||||
* Returns a sorted array of the prime factorization of $num
|
||||
* @staticvar array $aFactors
|
||||
* @param type int Number to factorize
|
||||
* @return type array Prime factors
|
||||
*/
|
||||
function factorize($num) {
|
||||
// Returns a sorted array of the prime factorization of $num
|
||||
// Caches prior results. Returns empty array for |$num|<2
|
||||
// eg. factorize(360) => [5, 3, 3, 2, 2, 2]
|
||||
static $aFactors = array();
|
||||
if (2 > $num = abs($num))
|
||||
return array(); // negatives, 1, 0
|
||||
|
||||
if ($aFactors[$key = "x$num"]) { // handles doubles
|
||||
// Been there, done that
|
||||
if (($factor = $aFactors[$key]) == $num)
|
||||
return array($num);
|
||||
return array_merge(factorize($num / $factor), array($factor));
|
||||
}
|
||||
|
||||
// Find a smallest factor
|
||||
for ($sqrt = sqrt($num), $factor = 2; $factor <= $sqrt; ++$factor)
|
||||
if (floor($num / $factor) == $num / $factor)
|
||||
return array_merge(factorize($num / $factor), array($aFactors[$key] = $factor));
|
||||
|
||||
return (array($aFactors[$key] = $num));
|
||||
}
|
17
solutions/ProjectEuler/004/desc.yml
Normal file
17
solutions/ProjectEuler/004/desc.yml
Normal file
@ -0,0 +1,17 @@
|
||||
title: Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
url: http://projecteuler.net/problem=4
|
||||
|
||||
desc: |
|
||||
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
|
||||
Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
|
||||
solution: |
|
||||
See code
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
13
solutions/ProjectEuler/004/solve.php
Normal file
13
solutions/ProjectEuler/004/solve.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$max = 0;
|
||||
for($num1 = 1000; $num1>100; $num1--) {
|
||||
for($num2 = 1000; $num2>100; $num2--) {
|
||||
$sum = $num1 * $num2;
|
||||
|
||||
//Check if palindrome
|
||||
if($sum > $max AND strrev($sum) == $sum)
|
||||
$max = $sum;
|
||||
|
||||
}
|
||||
}
|
||||
echo $max;
|
10
solutions/ProjectEuler/004/solve.rb
Normal file
10
solutions/ProjectEuler/004/solve.rb
Normal file
@ -0,0 +1,10 @@
|
||||
max = 0;
|
||||
(100..1000).each do |num1|
|
||||
(100..1000).each do |num2|
|
||||
sum = num1 * num2
|
||||
if( sum > max and sum.to_s.reverse == sum.to_s)
|
||||
max = sum
|
||||
end
|
||||
end
|
||||
end
|
||||
print max
|
20
solutions/ProjectEuler/005/desc.yml
Normal file
20
solutions/ProjectEuler/005/desc.yml
Normal file
@ -0,0 +1,20 @@
|
||||
title: What is the smallest number divisible by each of the numbers 1 to 20?
|
||||
url: http://projecteuler.net/problem=5
|
||||
|
||||
desc: |
|
||||
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
|
||||
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||
|
||||
solution: |
|
||||
See code
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.js:
|
||||
desc: Basic solution for NodeJS
|
||||
language: js
|
11
solutions/ProjectEuler/005/solve.js
Normal file
11
solutions/ProjectEuler/005/solve.js
Normal file
@ -0,0 +1,11 @@
|
||||
for(i=20;true;i+=20) {
|
||||
div = 19;
|
||||
|
||||
while(!(i % div)) {
|
||||
div--;
|
||||
if(div == 0) {
|
||||
console.log( i );
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
12
solutions/ProjectEuler/005/solve.lua
Normal file
12
solutions/ProjectEuler/005/solve.lua
Normal file
@ -0,0 +1,12 @@
|
||||
i=0
|
||||
while(true) do
|
||||
i = i + 20
|
||||
div = 19
|
||||
while((i % div) == 0) do
|
||||
div = div - 1
|
||||
if(div == 0) then
|
||||
print(i)
|
||||
os.exit()
|
||||
end
|
||||
end
|
||||
end
|
12
solutions/ProjectEuler/005/solve.php
Normal file
12
solutions/ProjectEuler/005/solve.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
for($i=20;true;$i+=20) {
|
||||
$div = 19;
|
||||
|
||||
while(!($i % $div)) {
|
||||
$div--;
|
||||
if($div == 0) {
|
||||
echo $i;
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
13
solutions/ProjectEuler/005/solve.rb
Normal file
13
solutions/ProjectEuler/005/solve.rb
Normal file
@ -0,0 +1,13 @@
|
||||
i = 0
|
||||
while (true)
|
||||
i = i + 20
|
||||
div = 19
|
||||
|
||||
while((i % div) == 0)
|
||||
div = div - 1
|
||||
if(div == 0) then
|
||||
puts i
|
||||
exit
|
||||
end
|
||||
end
|
||||
end
|
27
solutions/ProjectEuler/006/desc.yml
Normal file
27
solutions/ProjectEuler/006/desc.yml
Normal file
@ -0,0 +1,27 @@
|
||||
title: What is the smallest number divisible by each of the numbers 1 to 20?
|
||||
url: http://projecteuler.net/problem=6
|
||||
|
||||
desc: |
|
||||
The sum of the squares of the first ten natural numbers is,
|
||||
1^2 + 2^2 + ... + 10^2 = 385
|
||||
The square of the sum of the first ten natural numbers is,
|
||||
(1 + 2 + ... + 10)^2 = 55^2 = 3025
|
||||
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.
|
||||
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
||||
|
||||
solution: |
|
||||
See code
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic Ruby solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: Javascript solution for NodeJS
|
||||
language: javascript
|
19
solutions/ProjectEuler/006/solve.c
Normal file
19
solutions/ProjectEuler/006/solve.c
Normal file
@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
int num;
|
||||
int result;
|
||||
|
||||
int square = 0;
|
||||
int sum = 0;
|
||||
|
||||
for(num=1; num<=100; num++) {
|
||||
square += pow(num,2);
|
||||
sum += num;
|
||||
|
||||
}
|
||||
result = pow(sum,2) - square;
|
||||
printf("%d", result);
|
||||
}
|
9
solutions/ProjectEuler/006/solve.js
Normal file
9
solutions/ProjectEuler/006/solve.js
Normal file
@ -0,0 +1,9 @@
|
||||
square = 0;
|
||||
sum = 0;
|
||||
for(num=1;num<101;num++) {
|
||||
square += Math.pow(num,2);
|
||||
sum += num;
|
||||
|
||||
}
|
||||
console.log( Math.pow(sum,2) - square);
|
||||
|
9
solutions/ProjectEuler/006/solve.php
Normal file
9
solutions/ProjectEuler/006/solve.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
$square =0;
|
||||
$sum =0;
|
||||
for($num=1;$num<101;$num++) {
|
||||
$square += pow($num,2);
|
||||
$sum += $num;
|
||||
|
||||
}
|
||||
echo pow($sum,2) - $square;
|
7
solutions/ProjectEuler/006/solve.rb
Normal file
7
solutions/ProjectEuler/006/solve.rb
Normal file
@ -0,0 +1,7 @@
|
||||
square = 0
|
||||
sum = 0
|
||||
(1..100).each do |num|
|
||||
square += num**2;
|
||||
sum += num;
|
||||
end
|
||||
puts sum**2 - square;
|
20
solutions/ProjectEuler/007/desc.yml
Normal file
20
solutions/ProjectEuler/007/desc.yml
Normal file
@ -0,0 +1,20 @@
|
||||
title: Find the 10001st prime.
|
||||
url: http://projecteuler.net/problem=7
|
||||
|
||||
desc: |
|
||||
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
|
||||
What is the 10 001st prime number?
|
||||
|
||||
solution: |
|
||||
Move up the among the prime numbers till you reach 10001
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C (Compiled with TCC) solution
|
||||
language: c
|
30
solutions/ProjectEuler/007/solve.c
Normal file
30
solutions/ProjectEuler/007/solve.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int is_prime( int prime) {
|
||||
|
||||
int max_test = sqrt( prime );
|
||||
|
||||
int i;
|
||||
for (i = 3; i <= max_test; i+=2){
|
||||
if (prime % i == 0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main( )
|
||||
{
|
||||
//Use start val
|
||||
int i=13;
|
||||
int primes = 6;
|
||||
do{
|
||||
i+= 2;
|
||||
if(is_prime(i)){
|
||||
primes++;
|
||||
}
|
||||
|
||||
} while(primes < 10001);
|
||||
printf("%d", i);
|
||||
}
|
18
solutions/ProjectEuler/007/solve.php
Normal file
18
solutions/ProjectEuler/007/solve.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
function is_prime($prime) {
|
||||
$sqrt = sqrt($prime);
|
||||
for ($i = 3; $i <= $sqrt; $i+=2){
|
||||
if ($prime%$i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$i=13;
|
||||
$primes = 6;
|
||||
do{
|
||||
$i+= 2;
|
||||
if(is_prime($i)){
|
||||
$primes++;
|
||||
}
|
||||
}while($primes < 10001);
|
||||
echo $i;
|
21
solutions/ProjectEuler/007/solve.rb
Normal file
21
solutions/ProjectEuler/007/solve.rb
Normal file
@ -0,0 +1,21 @@
|
||||
def is_prime(prime)
|
||||
sqrt = Math.sqrt(prime)
|
||||
i=3
|
||||
while(i <= sqrt)
|
||||
if (prime % i == 0)
|
||||
return false
|
||||
end
|
||||
i+= 2
|
||||
end
|
||||
return true;
|
||||
end
|
||||
|
||||
i=13
|
||||
primes = 6
|
||||
until (primes == 10001)
|
||||
i+= 2
|
||||
if(is_prime(i))
|
||||
primes+=1
|
||||
end
|
||||
end
|
||||
puts i
|
18
solutions/ProjectEuler/008/desc.yml
Normal file
18
solutions/ProjectEuler/008/desc.yml
Normal file
@ -0,0 +1,18 @@
|
||||
title: Discover the largest product of five consecutive digits in the 1000-digit number.
|
||||
url: http://projecteuler.net/problem=8
|
||||
|
||||
desc: |
|
||||
Find the greatest product of five consecutive digits in the 1000-digit number.
|
||||
|
||||
solution: |
|
||||
Bruteforce (Unless someone found a smarter way)
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Expects the haystack as stdin with optional newlines
|
||||
language: php
|
||||
parameters: < ProjectEuler\008\input
|
||||
solve.rb:
|
||||
desc: Expects the haystack as stdin with optional newlines
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\008\input
|
20
solutions/ProjectEuler/008/input
Normal file
20
solutions/ProjectEuler/008/input
Normal file
@ -0,0 +1,20 @@
|
||||
73167176531330624919225119674426574742355349194934
|
||||
96983520312774506326239578318016984801869478851843
|
||||
85861560789112949495459501737958331952853208805511
|
||||
12540698747158523863050715693290963295227443043557
|
||||
66896648950445244523161731856403098711121722383113
|
||||
62229893423380308135336276614282806444486645238749
|
||||
30358907296290491560440772390713810515859307960866
|
||||
70172427121883998797908792274921901699720888093776
|
||||
65727333001053367881220235421809751254540594752243
|
||||
52584907711670556013604839586446706324415722155397
|
||||
53697817977846174064955149290862569321978468622482
|
||||
83972241375657056057490261407972968652414535100474
|
||||
82166370484403199890008895243450658541227588666881
|
||||
16427171479924442928230863465674813919123162824586
|
||||
17866458359124566529476545682848912883142607690042
|
||||
24219022671055626321111109370544217506941658960408
|
||||
07198403850962455444362981230987879927244284909188
|
||||
84580156166097919133875499200524063689912560717606
|
||||
05886116467109405077541002256983155200055935729725
|
||||
71636269561882670428252483600823257530420752963450
|
8
solutions/ProjectEuler/008/solve.php
Normal file
8
solutions/ProjectEuler/008/solve.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
$haystack = str_replace(array('\n','\r\n'),'',file_get_contents('php://stdin'));
|
||||
for($i=0;$i<1000-4;$i++) {
|
||||
$cmp = $haystack[$i] * $haystack[$i+1] * $haystack[$i+2] * $haystack[$i+3] * $haystack[$i+4];
|
||||
$max = ($cmp > $max) ? $cmp : $max;
|
||||
}
|
||||
|
||||
echo $max;
|
13
solutions/ProjectEuler/008/solve.rb
Normal file
13
solutions/ProjectEuler/008/solve.rb
Normal file
@ -0,0 +1,13 @@
|
||||
haystack = ''
|
||||
ARGF.lines("\n") do |line|
|
||||
haystack << line.strip
|
||||
end
|
||||
|
||||
max = 0
|
||||
(1..(1000-4)).each do |index|
|
||||
compare = haystack[index].to_i * haystack[index+1].to_i * haystack[index+2].to_i * haystack[index+3].to_i * haystack[index+4].to_i
|
||||
if(compare > max)
|
||||
max = compare
|
||||
end
|
||||
end
|
||||
puts max
|
23
solutions/ProjectEuler/009/desc.yml
Normal file
23
solutions/ProjectEuler/009/desc.yml
Normal file
@ -0,0 +1,23 @@
|
||||
title: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.
|
||||
url: http://projecteuler.net/problem=9
|
||||
|
||||
desc: |
|
||||
A Pythagorean triplet is a set of three natural numbers, a b c, for which,
|
||||
a^2 + b^2 = c^2
|
||||
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
|
||||
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
|
||||
Find the product abc.
|
||||
|
||||
solution: |
|
||||
Make a nested forloop for a and b in the range 1-1000 - Then c = 1000-a-b - Test if solution is valid.
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution compiled with TCC
|
||||
language: c
|
24
solutions/ProjectEuler/009/solve.c
Normal file
24
solutions/ProjectEuler/009/solve.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "stdio.h"
|
||||
#include "math.h"
|
||||
|
||||
int main( )
|
||||
{
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int cmp;
|
||||
for(a = 1; a < 1000; a++)
|
||||
{
|
||||
for(b = 1; b < 1000; b++)
|
||||
{
|
||||
//Calculate the only valid value for c
|
||||
c = 1000 - a - b;
|
||||
if( pow(c,2) == (pow(a, 2 ) + pow( b, 2 )))
|
||||
{
|
||||
int result = a * b * c;
|
||||
printf("%i", result);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
solutions/ProjectEuler/009/solve.php
Normal file
11
solutions/ProjectEuler/009/solve.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
for ($a = 1; $a < 1000; $a++) {
|
||||
for ($b = 1; $b < 1000; $b++) {
|
||||
//Make it run reverse in order to find solution quickly
|
||||
$c = 1000 - $a - $b;
|
||||
if (pow($a, 2) + pow($b, 2) == pow($c, 2)) {
|
||||
echo $a * $b * $c;
|
||||
die;
|
||||
}
|
||||
}
|
||||
}
|
9
solutions/ProjectEuler/009/solve.rb
Normal file
9
solutions/ProjectEuler/009/solve.rb
Normal file
@ -0,0 +1,9 @@
|
||||
(1..1000).each do |a|
|
||||
(1..1000).each do |b|
|
||||
c = 1000 - a - b
|
||||
if( a ** 2 + b ** 2 == c ** 2)
|
||||
puts a * b *c
|
||||
exit
|
||||
end
|
||||
end
|
||||
end
|
20
solutions/ProjectEuler/010/desc.yml
Normal file
20
solutions/ProjectEuler/010/desc.yml
Normal file
@ -0,0 +1,20 @@
|
||||
title: Calculate the sum of all the primes below two million.
|
||||
url: http://projecteuler.net/problem=10
|
||||
|
||||
desc: |
|
||||
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
|
||||
Find the sum of all the primes below two million.
|
||||
|
||||
solution: |
|
||||
Use a primenumber tester
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: C solution compiled with gcc-4.3.4 (Support for long long needed)
|
||||
language: c
|
28
solutions/ProjectEuler/010/solve.c
Normal file
28
solutions/ProjectEuler/010/solve.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int is_prime( int prime) {
|
||||
|
||||
int max_test = sqrt( prime );
|
||||
|
||||
int i;
|
||||
for (i = 3; i <= max_test; i+=2){
|
||||
if (prime % i == 0){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main( )
|
||||
{
|
||||
long long sum = 2+3;
|
||||
long number;
|
||||
for(number = 5; number < 2000000; number+=2) {
|
||||
if (is_prime(number))
|
||||
{
|
||||
sum += number;
|
||||
}
|
||||
}
|
||||
printf("%llu",sum);
|
||||
}
|
18
solutions/ProjectEuler/010/solve.php
Normal file
18
solutions/ProjectEuler/010/solve.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
function is_prime($prime) {
|
||||
$sqrt = sqrt($prime);
|
||||
for ($i = 3; $i <= $sqrt; $i+=2){
|
||||
if ($prime%$i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
$sum = 2+3;
|
||||
for($number = 5; $number < 2000000; $number+=2) {
|
||||
if (is_prime($number))
|
||||
{
|
||||
$sum += $number;
|
||||
}
|
||||
}
|
||||
echo $sum;
|
21
solutions/ProjectEuler/010/solve.rb
Normal file
21
solutions/ProjectEuler/010/solve.rb
Normal file
@ -0,0 +1,21 @@
|
||||
def is_prime(prime)
|
||||
sqrt = Math.sqrt(prime)
|
||||
i=3
|
||||
while(i <= sqrt)
|
||||
if (prime % i == 0)
|
||||
return false
|
||||
end
|
||||
i+= 2
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
number = 3
|
||||
sum = 5
|
||||
until(number >= 2000000)
|
||||
number += 2
|
||||
if(is_prime(number))
|
||||
sum += number
|
||||
end
|
||||
end
|
||||
puts sum;
|
20
solutions/ProjectEuler/011/desc.yml
Normal file
20
solutions/ProjectEuler/011/desc.yml
Normal file
@ -0,0 +1,20 @@
|
||||
title: What is the greatest product of four adjacent numbers on the same straight line in the 20 by 20 grid?
|
||||
url: http://projecteuler.net/problem=11
|
||||
|
||||
desc: |
|
||||
In the 2020 grid below, four numbers along a diagonal line have been marked in red.
|
||||
What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or diagonally) in the 2020 grid?
|
||||
(See file input)
|
||||
|
||||
solution: |
|
||||
Bruteforce (Unless someone found a smarter way)
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Expects the matrix as stdin
|
||||
language: php
|
||||
parameters: < ProjectEuler\011\input
|
||||
solve.rb:
|
||||
desc: Expects the matrix as stdin
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\011\input
|
20
solutions/ProjectEuler/011/input
Normal file
20
solutions/ProjectEuler/011/input
Normal file
@ -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
|
39
solutions/ProjectEuler/011/solve.php
Normal file
39
solutions/ProjectEuler/011/solve.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
foreach(file('php://stdin') as $line) {
|
||||
$matrix[] = explode(' ', $line);
|
||||
}
|
||||
$max = 0;
|
||||
//Left and right
|
||||
for ($y = 0; $y < 19; $y++) {
|
||||
for ($x = 0; $x < 16; $x++) {
|
||||
$cmp = $matrix[$y][$x] * $matrix[$y][$x + 1] * $matrix[$y][$x + 2] * $matrix[$y][$x + 3];
|
||||
$max = ($cmp > $max) ? $cmp : $max;
|
||||
}
|
||||
}
|
||||
|
||||
//Vertical
|
||||
for($x = 0; $x < 19; $x++) {
|
||||
for ($y = 0; $y < 16; $y++) {
|
||||
$cmp = $matrix[$y][$x] * $matrix[$y + 1][$x] * $matrix[$y + 2][$x] * $matrix[$y + 3][$x];
|
||||
$max = ($cmp > $max) ? $cmp : $max;
|
||||
}
|
||||
}
|
||||
|
||||
//Diagonally left->down
|
||||
for($x = 0; $x < 16; $x++) {
|
||||
for ($y = 0; $y < 16; $y++) {
|
||||
$cmp = $matrix[$y][$x] * $matrix[$y + 1][$x + 1] * $matrix[$y + 2][$x + 2] * $matrix[$y + 3][$x + 3];
|
||||
$max = ($cmp > $max) ? $cmp : $max;
|
||||
}
|
||||
}
|
||||
|
||||
//Diagonally right->down
|
||||
for($x = 4; $x < 19; $x++) {
|
||||
for ($y = 0; $y < 16; $y++) {
|
||||
$cmp = $matrix[$y][$x] * $matrix[$y + 1][$x - 1] * $matrix[$y + 2][$x - 2] * $matrix[$y + 3][$x - 3];
|
||||
$max = ($cmp > $max) ? $cmp : $max;
|
||||
}
|
||||
}
|
||||
|
||||
echo $max;
|
53
solutions/ProjectEuler/011/solve.rb
Normal file
53
solutions/ProjectEuler/011/solve.rb
Normal file
@ -0,0 +1,53 @@
|
||||
matrix = []
|
||||
linenum = 0
|
||||
ARGF.lines("\n") do |line|
|
||||
matrix[linenum] = Array.new
|
||||
line.split.each do |str|
|
||||
matrix[linenum] << str.to_i
|
||||
end
|
||||
linenum += 1
|
||||
end
|
||||
|
||||
max = 0
|
||||
max = 0;
|
||||
#Left and right
|
||||
(0..19).each do |y|
|
||||
(0..16).each do |x|
|
||||
cmp = matrix[y][x] * matrix[y][x + 1] * matrix[y][x + 2] * matrix[y][x + 3];
|
||||
if (cmp > max)
|
||||
max = cmp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#Vertical
|
||||
(0..16).each do |y|
|
||||
(0..19).each do |x|
|
||||
cmp = matrix[y][x] * matrix[y + 1][x] * matrix[y + 2][x] * matrix[y + 3][x];
|
||||
if (cmp > max)
|
||||
max = cmp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#Diagonally left->down
|
||||
(0..16).each do |y|
|
||||
(0..16).each do |x|
|
||||
cmp = matrix[y][x] * matrix[y + 1][x + 1] * matrix[y + 2][x + 2] * matrix[y + 3][x + 3];
|
||||
if (cmp > max)
|
||||
max = cmp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#Diagonally right->down
|
||||
(0..16).each do |y|
|
||||
(3..19).each do |x|
|
||||
cmp = matrix[y][x] * matrix[y + 1][x - 1] * matrix[y + 2][x - 2] * matrix[y + 3][x - 3];
|
||||
if (cmp > max)
|
||||
max = cmp
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts max
|
30
solutions/ProjectEuler/012/desc.yml
Normal file
30
solutions/ProjectEuler/012/desc.yml
Normal file
@ -0,0 +1,30 @@
|
||||
title: What is the value of the first triangle number to have over five hundred divisors?
|
||||
url: http://projecteuler.net/problem=12
|
||||
|
||||
desc: |
|
||||
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
|
||||
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
|
||||
Let us list the factors of the first seven triangle numbers:
|
||||
1: 1
|
||||
3: 1,3
|
||||
6: 1,2,3,6
|
||||
10: 1,2,5,10
|
||||
15: 1,3,5,15
|
||||
21: 1,3,7,21
|
||||
28: 1,2,4,7,14,28
|
||||
We can see that 28 is the first triangle number to have over five divisors.
|
||||
What is the value of the first triangle number to have over five hundred divisors?
|
||||
|
||||
solution: |
|
||||
Bruteforce - Still kinda slow - Guessing it could be improved
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution compiled with TCC
|
||||
language: c
|
23
solutions/ProjectEuler/012/solve.c
Normal file
23
solutions/ProjectEuler/012/solve.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
long num = 3;
|
||||
long tri_add = 2;
|
||||
long div;
|
||||
int divisors;
|
||||
int max = 0;
|
||||
do
|
||||
{
|
||||
num += ++tri_add;
|
||||
divisors = 2;
|
||||
int square_root = sqrt(num);
|
||||
for(div = 2; div <= square_root; div++)
|
||||
{
|
||||
if(num % div == 0)
|
||||
divisors+=2;
|
||||
}
|
||||
} while(divisors <= 500);
|
||||
printf( "%i", num );
|
||||
}
|
13
solutions/ProjectEuler/012/solve.php
Normal file
13
solutions/ProjectEuler/012/solve.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$num = 3;
|
||||
$tri_add = 2;
|
||||
do {
|
||||
$num += ++$tri_add;
|
||||
$divisors = 2;
|
||||
$square_root = sqrt($num);
|
||||
for($div = 2; $div <= $square_root; $div++) {
|
||||
if($num % $div == 0)
|
||||
$divisors+= 2;
|
||||
}
|
||||
} while ($divisors <= 500);
|
||||
echo $num;
|
17
solutions/ProjectEuler/012/solve.rb
Normal file
17
solutions/ProjectEuler/012/solve.rb
Normal file
@ -0,0 +1,17 @@
|
||||
num = 3;
|
||||
tri_add = 2;
|
||||
begin
|
||||
tri_add += 1
|
||||
num += tri_add
|
||||
|
||||
divisors = 2;
|
||||
square_root = Math.sqrt(num);
|
||||
div = 2
|
||||
while(div <= square_root)
|
||||
if(num % div == 0)
|
||||
divisors += 2;
|
||||
end
|
||||
div += 1
|
||||
end
|
||||
end until (divisors > 500);
|
||||
puts num;
|
19
solutions/ProjectEuler/013/desc.yml
Normal file
19
solutions/ProjectEuler/013/desc.yml
Normal file
@ -0,0 +1,19 @@
|
||||
title: Find the first ten digits of the sum of one-hundred 50-digit numbers.
|
||||
url: http://projecteuler.net/problem=13
|
||||
|
||||
desc: |
|
||||
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
|
||||
(See file input)
|
||||
|
||||
solution: |
|
||||
Use a full precission math lib
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Expects input on STDIN
|
||||
language: php
|
||||
parameters: < ProjectEuler\013\input
|
||||
solve.rb:
|
||||
desc: Expects input on STDIN
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\013\input
|
100
solutions/ProjectEuler/013/input
Normal file
100
solutions/ProjectEuler/013/input
Normal file
@ -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
|
7
solutions/ProjectEuler/013/solve.php
Normal file
7
solutions/ProjectEuler/013/solve.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$numbers = file('php://stdin');
|
||||
$total = 0;
|
||||
foreach($numbers as $number) {
|
||||
$total = bcadd($total,trim($number));
|
||||
}
|
||||
echo substr($total,0,10);
|
13
solutions/ProjectEuler/013/solve.rb
Normal file
13
solutions/ProjectEuler/013/solve.rb
Normal file
@ -0,0 +1,13 @@
|
||||
numbers = []
|
||||
linenum = 0
|
||||
ARGF.lines("\n") do |line|
|
||||
numbers[linenum] = Array.new
|
||||
numbers[linenum] = line.to_i
|
||||
linenum += 1
|
||||
end
|
||||
|
||||
sum=0
|
||||
numbers.each do |num|
|
||||
sum += num
|
||||
end
|
||||
puts sum.to_s[0..9]
|
27
solutions/ProjectEuler/014/desc.yml
Normal file
27
solutions/ProjectEuler/014/desc.yml
Normal file
@ -0,0 +1,27 @@
|
||||
title: Find the longest sequence using a starting number under one million.
|
||||
url: http://projecteuler.net/problem=14
|
||||
|
||||
desc: |
|
||||
The following iterative sequence is defined for the set of positive integers:
|
||||
n -> n/2 (n is even)
|
||||
n -> 3n + 1 (n is odd)
|
||||
Using the rule above and starting with 13, we generate the following sequence:
|
||||
13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
|
||||
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
|
||||
|
||||
Which starting number, under one million, produces the longest chain?
|
||||
NOTE: Once the chain starts the terms are allowed to go above one million.
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C compiled with TCC
|
||||
language: c
|
34
solutions/ProjectEuler/014/solve.c
Normal file
34
solutions/ProjectEuler/014/solve.c
Normal file
@ -0,0 +1,34 @@
|
||||
#define MAX 1000000-1
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
unsigned int max_steps = 0;
|
||||
unsigned int max_start;
|
||||
|
||||
unsigned int test;
|
||||
|
||||
unsigned long ctest;
|
||||
unsigned int steps;
|
||||
|
||||
for(test = MAX; test > 1 ; test--)
|
||||
{
|
||||
|
||||
ctest = test;
|
||||
steps = 1;
|
||||
while(ctest != 1)
|
||||
{
|
||||
ctest = ( ctest % 2 ) ? ctest * 3 + 1 : ctest / 2;
|
||||
steps++;
|
||||
}
|
||||
if(steps > max_steps)
|
||||
{
|
||||
max_start = test;
|
||||
max_steps = steps;
|
||||
}
|
||||
|
||||
}
|
||||
printf( "%lu", max_start );
|
||||
}
|
13
solutions/ProjectEuler/014/solve.php
Normal file
13
solutions/ProjectEuler/014/solve.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
$max_steps = 0;
|
||||
for($test=999999;$test>1;$test--) {
|
||||
$ctest = $test;
|
||||
$steps = 1;
|
||||
while($ctest != 1) {
|
||||
$ctest = ($ctest % 2) ? $ctest*3+1 : $ctest/2;
|
||||
$steps++;
|
||||
}
|
||||
|
||||
if($steps > $max_steps) { $max_start = $test; $max_steps = $steps;}
|
||||
}
|
||||
echo $max_start;
|
18
solutions/ProjectEuler/014/solve.rb
Normal file
18
solutions/ProjectEuler/014/solve.rb
Normal file
@ -0,0 +1,18 @@
|
||||
max_start = 0
|
||||
max_steps = 0
|
||||
test = 1
|
||||
|
||||
while(test < 1000000)
|
||||
ctest = test
|
||||
steps = 1
|
||||
while(ctest != 1)
|
||||
ctest = ( ctest % 2 != 0) ? ctest * 3 + 1 : ctest / 2
|
||||
steps += 1
|
||||
end
|
||||
if(steps > max_steps)
|
||||
max_start = test
|
||||
max_steps = steps
|
||||
end
|
||||
test += 1
|
||||
end
|
||||
puts max_start
|
19
solutions/ProjectEuler/015/desc.yml
Normal file
19
solutions/ProjectEuler/015/desc.yml
Normal file
@ -0,0 +1,19 @@
|
||||
title: Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
|
||||
url: http://projecteuler.net/problem=15
|
||||
|
||||
desc: |
|
||||
Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
|
||||
How many routes are there through a 2020 grid?
|
||||
|
||||
solution: |
|
||||
(2n)!/n!^2 - Where n is the size of the grid -
|
||||
|
||||
todo: Find a more "programmable way" instead of this cheating mathsolution
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Using BCMath to cope with large numbers
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
11
solutions/ProjectEuler/015/solve.php
Normal file
11
solutions/ProjectEuler/015/solve.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
define('GRID_SIZE',20);
|
||||
function factorial($num) {
|
||||
if($num == 0)
|
||||
return 1;
|
||||
else
|
||||
return bcmul($num,factorial(bcsub($num,1)));
|
||||
}
|
||||
|
||||
echo bcdiv(factorial(2* GRID_SIZE),bcpow(factorial( GRID_SIZE),2));
|
||||
|
11
solutions/ProjectEuler/015/solve.rb
Normal file
11
solutions/ProjectEuler/015/solve.rb
Normal file
@ -0,0 +1,11 @@
|
||||
GRID_SIZE = 20
|
||||
|
||||
def factorial(num)
|
||||
if(num == 0)
|
||||
return 1
|
||||
else
|
||||
return num * factorial(num - 1)
|
||||
end
|
||||
end
|
||||
|
||||
puts factorial(2 * GRID_SIZE) / factorial(GRID_SIZE) ** 2
|
17
solutions/ProjectEuler/016/desc.yml
Normal file
17
solutions/ProjectEuler/016/desc.yml
Normal file
@ -0,0 +1,17 @@
|
||||
title: What is the sum of the digits of the number 2^1000?
|
||||
url: http://projecteuler.net/problem=16
|
||||
|
||||
desc: |
|
||||
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
|
||||
What is the sum of the digits of the number 2^1000?
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Using BCMath to cope with large numbers
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
7
solutions/ProjectEuler/016/solve.php
Normal file
7
solutions/ProjectEuler/016/solve.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
$num = bcpow(2,1000);
|
||||
$sum = 0;
|
||||
for($c =0; $c < strlen($num);$c++) {
|
||||
$sum += $num[$c];
|
||||
}
|
||||
echo $sum;
|
6
solutions/ProjectEuler/016/solve.rb
Normal file
6
solutions/ProjectEuler/016/solve.rb
Normal file
@ -0,0 +1,6 @@
|
||||
num = 2 ** 1000
|
||||
sum = 0
|
||||
num.to_s.chars do |digit|
|
||||
sum += digit.to_i
|
||||
end
|
||||
puts sum
|
15
solutions/ProjectEuler/017/desc.yml
Normal file
15
solutions/ProjectEuler/017/desc.yml
Normal file
@ -0,0 +1,15 @@
|
||||
title: How many letters would be needed to write all the numbers in words from 1 to 1000?
|
||||
url: http://projecteuler.net/problem=17
|
||||
|
||||
desc: |
|
||||
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
|
||||
What is the sum of the digits of the number 2^1000?
|
||||
|
||||
solution: Just a matter of having a correct number-to-word function
|
||||
|
||||
todo: Make a clean implementation
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Urggh - Solve using a lib from bas@startpunt.cc and corrected a small error so 210 whould include an "and" correctly
|
||||
language: php
|
79
solutions/ProjectEuler/017/solve.php
Normal file
79
solutions/ProjectEuler/017/solve.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
function n2w_hunderds($number)
|
||||
{
|
||||
|
||||
$test=$number*1;
|
||||
if (empty($test))return;
|
||||
$lasts=array('one','two','three','four','five','six','seven','eight','nine');
|
||||
$teens=array('eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');
|
||||
$teen=array('ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety');
|
||||
|
||||
/* written by bas@startpunt.cc */
|
||||
|
||||
$string='';
|
||||
$j=strlen($number);
|
||||
$done=false;
|
||||
for($i=0; $i<strlen($number); $i++)
|
||||
{
|
||||
|
||||
|
||||
if($j==2)
|
||||
{
|
||||
if(strlen($number)>2)
|
||||
{
|
||||
if($number[0]!=0)$string.= ' hundred ';
|
||||
if($number % 100 != 0)$string.= 'and ';
|
||||
}
|
||||
if ($number[$i]==1)
|
||||
{
|
||||
if($number[$i+1]==0) $string.=$teen[$number[$i]-1];
|
||||
else
|
||||
{
|
||||
$string.=$teens[$number[$i+1]-1];
|
||||
$done=true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!empty($teen[$number[$i]-1]))$string.=$teen[$number[$i]-1].' ';
|
||||
}
|
||||
}
|
||||
|
||||
elseif($number[$i]!=0 && !$done) $string.=$lasts[$number[$i]-1];
|
||||
|
||||
$j--;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function n2w($number,$uk=0)
|
||||
{
|
||||
if(!is_string($number))$number.="";
|
||||
if(!$uk)$many=array('', ' thousand ',' million ',' billion ',' trillion ');
|
||||
else $many=array('', ' thousand ',' million ',' milliard ',' billion ');
|
||||
$string='';
|
||||
if(strlen($number)%3!=0)
|
||||
{
|
||||
$string.=n2w_hunderds(substr($number,0, strlen($number)%3 ));
|
||||
$string.=$many[floor(strlen($number)/3)];
|
||||
|
||||
}
|
||||
for($i=0; $i<floor(strlen($number)/3); $i++)
|
||||
{
|
||||
|
||||
$string.=n2w_hunderds(substr($number,strlen($number)%3+($i*3),3));
|
||||
if($number[strlen($number)%3+($i*3)]!=0)$string.=$many[floor(strlen($number)/3)-1-$i];
|
||||
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
$len = 0;
|
||||
for($i = 1; $i <= 1000; $i++) {
|
||||
$len += strlen(str_replace(' ','',n2w($i)));
|
||||
}
|
||||
|
||||
echo $len;
|
25
solutions/ProjectEuler/018/desc.yml
Normal file
25
solutions/ProjectEuler/018/desc.yml
Normal file
@ -0,0 +1,25 @@
|
||||
title: Find the maximum sum travelling from the top of the triangle to the base.
|
||||
url: http://projecteuler.net/problem=18
|
||||
|
||||
desc: |
|
||||
By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.
|
||||
3
|
||||
7 4
|
||||
2 4 6
|
||||
8 5 9 3
|
||||
That is, 3 + 7 + 4 + 9 = 23.
|
||||
Find the maximum total from top to bottom of the triangle below
|
||||
(See file input)
|
||||
|
||||
|
||||
solution: Instead of bruteforcing from top to bottom simply add the numbers from the bottom up and let the "highest" number win in a shootout
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
parameters: < ProjectEuler\018\input
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\018\input
|
15
solutions/ProjectEuler/018/input
Normal file
15
solutions/ProjectEuler/018/input
Normal file
@ -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
|
16
solutions/ProjectEuler/018/solve.php
Normal file
16
solutions/ProjectEuler/018/solve.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
foreach(file('php://stdin') as $line) {
|
||||
$tri[] = explode(' ',trim($line));
|
||||
}
|
||||
for($y=count($tri);$y>=0;$y--) {
|
||||
|
||||
for($x=0;$x<count($tri[$y]);$x++) {
|
||||
$cur = $tri[$y][$x];
|
||||
if($cur + $tri[$y+1][$x] > $cur + $tri[$y+1][$x+1]) {
|
||||
$tri[$y][$x] = $cur + $tri[$y+1][$x];
|
||||
} else {
|
||||
$tri[$y][$x] = $cur + $tri[$y+1][$x+1];
|
||||
}
|
||||
}
|
||||
}
|
||||
echo $tri[0][0];
|
20
solutions/ProjectEuler/018/solve.rb
Normal file
20
solutions/ProjectEuler/018/solve.rb
Normal file
@ -0,0 +1,20 @@
|
||||
tri = []
|
||||
linenum = 0
|
||||
ARGF.lines("\n") do |line|
|
||||
tri[linenum] = Array.new
|
||||
line.split.each do |str|
|
||||
tri[linenum] << str.to_i
|
||||
end
|
||||
linenum += 1
|
||||
end
|
||||
|
||||
(0..13).reverse_each do |y|
|
||||
0.upto(tri[y].size()-1) do |x|
|
||||
if( tri[y+1][x] > tri[y+1][x+1])
|
||||
tri[y][x] = tri[y][x] + tri[y+1][x]
|
||||
else
|
||||
tri[y][x] = tri[y][x] + tri[y+1][x+1]
|
||||
end
|
||||
end
|
||||
end
|
||||
puts tri[0][0]
|
25
solutions/ProjectEuler/019/desc.yml
Normal file
25
solutions/ProjectEuler/019/desc.yml
Normal file
@ -0,0 +1,25 @@
|
||||
title: How many Sundays fell on the first of the month during the twentieth century?
|
||||
url: http://projecteuler.net/problem=19
|
||||
|
||||
desc: |
|
||||
You are given the following information, but you may prefer to do some research for yourself.
|
||||
1 Jan 1900 was a Monday.
|
||||
Thirty days has September,
|
||||
April, June and November.
|
||||
All the rest have thirty-one,
|
||||
Saving February alone,
|
||||
Which has twenty-eight, rain or shine.
|
||||
And on leap years, twenty-nine.
|
||||
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
|
||||
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
||||
|
||||
|
||||
solution: Instead of using buildtin DateTime language features this use a homemade algorithm
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
38
solutions/ProjectEuler/019/solve.php
Normal file
38
solutions/ProjectEuler/019/solve.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
$days_in_month = array(
|
||||
1 => 31,
|
||||
2 => 28,
|
||||
3 => 31,
|
||||
4 => 30,
|
||||
5 => 31,
|
||||
6 => 30,
|
||||
7 => 31,
|
||||
8 => 31,
|
||||
9 => 30,
|
||||
10 => 31,
|
||||
11 => 30,
|
||||
12 => 31
|
||||
);
|
||||
$day_cycle = 0;
|
||||
for($year=1900; $year <= 2000; $year++) {
|
||||
for($month=1; $month <= 12; $month++) {
|
||||
|
||||
$cdates = $days_in_month[$month];
|
||||
if($month == 2) {
|
||||
if($year % 4 == 0) {
|
||||
$cdates = 29;
|
||||
}
|
||||
if($years % 100 == 0) {
|
||||
$cdates = 28;
|
||||
}
|
||||
if($years % 400 == 0) {
|
||||
$cdates = 29;
|
||||
}
|
||||
}
|
||||
$day_cycle += $cdates;
|
||||
if($day_cycle % 7 == 0) {
|
||||
if($year >= 1901) {$sum++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
echo $sum;
|
9
solutions/ProjectEuler/019/solve.rb
Normal file
9
solutions/ProjectEuler/019/solve.rb
Normal file
@ -0,0 +1,9 @@
|
||||
require "date"
|
||||
sundays = 0
|
||||
(1901..2000).each do |year|
|
||||
(1..12).each do |month|
|
||||
dt = Date.new(year,month,1)
|
||||
sundays += (dt.wday == 0) ? 1 : 0
|
||||
end
|
||||
end
|
||||
puts sundays
|
18
solutions/ProjectEuler/020/desc.yml
Normal file
18
solutions/ProjectEuler/020/desc.yml
Normal file
@ -0,0 +1,18 @@
|
||||
title: Find the sum of digits in 100!
|
||||
url: http://projecteuler.net/problem=20
|
||||
|
||||
desc: |
|
||||
n! means n * (n - 1) * ... 3 * 2 * 1
|
||||
For example, 10! = 10 * 9 * ... * 3 * 2 * 1 = 3628800,
|
||||
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
|
||||
Find the sum of the digits in the number 100!
|
||||
|
||||
solution: Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
15
solutions/ProjectEuler/020/solve.php
Normal file
15
solutions/ProjectEuler/020/solve.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
define('FACTORIAL',100);
|
||||
|
||||
function factorial($num) {
|
||||
if($num == 0)
|
||||
return 1;
|
||||
else
|
||||
return bcmul($num,factorial(bcsub($num,1)));
|
||||
}
|
||||
$sum = 0;
|
||||
$fac = factorial(FACTORIAL);
|
||||
for($c = 0; $c < strlen($fac); $c++) {
|
||||
$sum += $fac[$c];
|
||||
}
|
||||
echo $sum;
|
16
solutions/ProjectEuler/020/solve.rb
Normal file
16
solutions/ProjectEuler/020/solve.rb
Normal file
@ -0,0 +1,16 @@
|
||||
FACTORIAL = 100
|
||||
def factorial(num)
|
||||
if(num == 0)
|
||||
return 1
|
||||
else
|
||||
return num * factorial(num - 1)
|
||||
end
|
||||
end
|
||||
|
||||
number = factorial(FACTORIAL)
|
||||
sum = 0
|
||||
|
||||
number.to_s.each_char do |c|
|
||||
sum += c.to_i
|
||||
end
|
||||
puts sum
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user