Compare commits
No commits in common. "0fbf5ed2507c332de8887a38c2a39805bbb01ad6" and "c6c387d17f15c7cab63d9131da14d70d9357f0f8" have entirely different histories.
0fbf5ed250
...
c6c387d17f
77
CT.rb
77
CT.rb
@ -1,58 +1,33 @@
|
||||
require "yaml"
|
||||
require 'erb'
|
||||
require 'open3'
|
||||
require 'pp'
|
||||
require 'benchmark'
|
||||
include Benchmark
|
||||
cli = { 'php' => 'php', 'ruby' => 'ruby', 'lua'=> 'lua', 'javascript'=>'node', 'js'=>'node', 'c' => 'tcc -run'}
|
||||
settings = YAML::load_file("settings.yml")
|
||||
|
||||
|
||||
problem = YAML::load_file(ARGV[0] + "/desc.yml")
|
||||
output = ERB.new(IO.read('template.rt'))
|
||||
puts output.result()
|
||||
|
||||
case ARGV[1]
|
||||
when 'test'
|
||||
if(problem['solutions'])
|
||||
problem['solutions'].each do |sol|
|
||||
if(cli[sol[1]['language']])
|
||||
puts "--------------\n|"+sol[0]+"\n--------------"
|
||||
puts sol[1]['desc']
|
||||
parameter = (sol[1]['parameters']) ? " " + sol[1]['parameters'] : ""
|
||||
stdin, stdout, stderr = Open3.popen3(cli[sol[1]['language']] + " "+ARGV[0]+"/"+sol[0] + parameter)
|
||||
puts "Result: " + stdout.readlines[0]
|
||||
|
||||
end
|
||||
if(ARGV[1] == 'table')
|
||||
require 'terminal-table'
|
||||
files = Dir[ARGV[0]+"/**/*/desc.yml"]
|
||||
files.sort
|
||||
entry = []
|
||||
files.each do |file|
|
||||
yaml = YAML::load_file(file)
|
||||
nested = file.split('/')
|
||||
count = 0
|
||||
if( yaml['solution'] and yaml['solutions'])
|
||||
yaml['solutions'].each do |sol|
|
||||
count += 1
|
||||
end
|
||||
else
|
||||
puts "No solutions for said problem"
|
||||
end
|
||||
|
||||
when 'table'
|
||||
entry << {'title'=>yaml['title'],'code'=>nested[-2].to_s,'solved'=>count}
|
||||
end
|
||||
|
||||
require 'terminal-table'
|
||||
files = Dir[ARGV[0]+"/**/*/desc.yml"]
|
||||
files.sort!
|
||||
entry = []
|
||||
files.each do |file|
|
||||
yaml = YAML::load_file(file)
|
||||
nested = file.split('/')
|
||||
count = 0
|
||||
if( yaml['solution'] and yaml['solutions'])
|
||||
yaml['solutions'].each do |sol|
|
||||
count += 1
|
||||
end
|
||||
end
|
||||
entry << {'title'=>yaml['title'],'code'=>nested[-2].to_s,'solved'=>count}
|
||||
end
|
||||
|
||||
rows = []
|
||||
entry.each do |e|
|
||||
solvedstring = (e['solved'] == 0) ? "No" : "Yes("+e['solved'].to_s+")"
|
||||
row = [e['code'],e['title'],solvedstring]
|
||||
rows << row
|
||||
end
|
||||
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
||||
puts table
|
||||
else
|
||||
output = ERB.new(IO.read('template.rt'))
|
||||
puts output.result()
|
||||
end
|
||||
rows = []
|
||||
entry.each do |e|
|
||||
solvedstring = (e['solved'] == 0) ? "No" : "Yes("+e['solved'].to_s+")"
|
||||
row = [e['code'],e['title'],solvedstring]
|
||||
rows << row
|
||||
end
|
||||
table = Terminal::Table.new(:headings => ['Code','Title','Solved'],:rows => rows)
|
||||
puts table
|
||||
end
|
@ -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||<???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???(?¾:?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?ñ?'?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[?·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!???<????*????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*[õ?*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)´?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[ÿ?????{?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?œ??@ ??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`??*??
|
@ -1,53 +0,0 @@
|
||||
?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||<???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???(?¾:?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?ñ?'?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[?·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!???<????*????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*[õ?*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)´?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[ÿ?????{?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?œ??@ ??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`?
|
Binary file not shown.
@ -1,51 +0,0 @@
|
||||
#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;
|
||||
}
|
Binary file not shown.
@ -13,7 +13,4 @@ solutions:
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: js
|
||||
language: c
|
@ -1 +0,0 @@
|
||||
console.log("Hello World");
|
@ -1,20 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
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
|
@ -1,22 +0,0 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
@ -21,6 +21,3 @@ solutions:
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: javascript
|
||||
solve.lua:
|
||||
desc: Basic solution
|
||||
language: lua
|
||||
|
@ -1,7 +0,0 @@
|
||||
sum = 0
|
||||
for i=1,999 do
|
||||
if i % 3 == 0 or i % 5 == 0 then
|
||||
sum = sum + i
|
||||
end
|
||||
end
|
||||
print(sum)
|
@ -21,7 +21,4 @@ solutions:
|
||||
language: c
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: javascript
|
||||
solve.lua:
|
||||
desc: Basic solution
|
||||
language: lua
|
||||
language: javascript
|
@ -5,7 +5,7 @@ fib = new Array( 1, 2, 3 );
|
||||
fib[2] = fib[0] + fib[1];
|
||||
if(fib[2] % 2 == 0)
|
||||
sum += fib[2];
|
||||
fib[0] = fib[1];
|
||||
fib[0] = fib[1];
|
||||
fib[1] = fib[2];
|
||||
}
|
||||
console.log(sum );
|
||||
|
@ -1,11 +0,0 @@
|
||||
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 )
|
@ -15,6 +15,3 @@ solutions:
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.js:
|
||||
desc: Basic solution for NodeJS
|
||||
language: js
|
@ -1,11 +0,0 @@
|
||||
for(i=20;true;i+=20) {
|
||||
div = 19;
|
||||
|
||||
while(!(i % div)) {
|
||||
div--;
|
||||
if(div == 0) {
|
||||
console.log( i );
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
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
|
@ -1,13 +1,10 @@
|
||||
i = 0
|
||||
while (true)
|
||||
i = i + 20
|
||||
div = 19
|
||||
|
||||
while((i % div) == 0)
|
||||
div = div - 1
|
||||
if(div == 0) then
|
||||
puts i
|
||||
exit
|
||||
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
|
||||
end
|
||||
print max
|
@ -19,9 +19,6 @@ solutions:
|
||||
solve.rb:
|
||||
desc: Basic Ruby solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
solve.rb:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: Javascript solution for NodeJS
|
||||
language: javascript
|
||||
language: c
|
@ -1,9 +0,0 @@
|
||||
square = 0;
|
||||
sum = 0;
|
||||
for(num=1;num<101;num++) {
|
||||
square += Math.pow(num,2);
|
||||
sum += num;
|
||||
|
||||
}
|
||||
console.log( Math.pow(sum,2) - square);
|
||||
|
@ -11,8 +11,6 @@ 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
|
||||
language: ruby
|
@ -16,5 +16,5 @@ solutions:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: C solution compiled with gcc-4.3.4 (Support for long long needed)
|
||||
desc: ANSI C solution compiled with gcc-4.3.4
|
||||
language: c
|
@ -13,8 +13,6 @@ 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
|
||||
language: ruby
|
@ -12,8 +12,6 @@ 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
|
||||
|
@ -18,8 +18,6 @@ solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
parameters: < ProjectEuler\018\input
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
||||
parameters: < ProjectEuler\018\input
|
@ -11,5 +11,4 @@ solution: Bruteforce
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Expects data on STDIN
|
||||
language: php
|
||||
parameters: < ProjectEuler\022\input
|
||||
language: php
|
@ -1,23 +0,0 @@
|
||||
title: Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||
url: http://projecteuler.net/problem=26
|
||||
|
||||
desc: |
|
||||
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
|
||||
1/2 = 0.5
|
||||
1/3 = 0.(3)
|
||||
1/4 = 0.25
|
||||
1/5 = 0.2
|
||||
1/6 = 0.1(6)
|
||||
1/7 = 0.(142857)
|
||||
1/8 = 0.125
|
||||
1/9 = 0.(1)
|
||||
1/10 = 0.1
|
||||
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
|
||||
Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||
|
||||
solution: Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic Solution - needs BCMath
|
||||
language: php
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
define('MAX',1000);
|
||||
|
||||
$max_len = 0;
|
||||
for($div = MAX; $div > 2; $div--) {
|
||||
$result = bcdiv('1',(string)$div,2000);
|
||||
|
||||
for($len = 2; $len < 1000; $len++) {
|
||||
if(substr($result,10,$len) === substr($result,10+$len,$len)) {
|
||||
if($len > $max_len) {
|
||||
echo "Div: ".$div. " Len: ".$len."\n";
|
||||
$max_len = $len;
|
||||
$max_div = $div;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
echo $max_div;
|
@ -1,13 +0,0 @@
|
||||
DIGITS = 1000
|
||||
|
||||
max = 10 ** (DIGITS-1)
|
||||
fcurrent = 1
|
||||
fprev = 1
|
||||
term = 2
|
||||
while fcurrent < max do
|
||||
term = term + 1
|
||||
fnext = fcurrent + fprev
|
||||
fprev = fcurrent;
|
||||
fcurrent = fnext;
|
||||
end
|
||||
puts term
|
@ -1,20 +0,0 @@
|
||||
title: Quadratic primes
|
||||
url: http://projecteuler.net/problem=27
|
||||
|
||||
desc: |
|
||||
Euler discovered the remarkable quadratic formula:
|
||||
n² + n + 41
|
||||
It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly divisible by 41.
|
||||
The incredible formula n² - 79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, -79 and 1601, is -126479.
|
||||
Considering quadratics of the form:
|
||||
n² + an + b, where |a| < 1000 and |b| < 1000
|
||||
where |n| is the modulus/absolute value of n
|
||||
e.g. |11| = 11 and |-4| = 4
|
||||
Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0
|
||||
|
||||
solution: Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic Solution - needs BCMath
|
||||
language: php
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
function is_prime($prime) {
|
||||
if($prime < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if($prime == 1)
|
||||
return true;
|
||||
if($prime == 2)
|
||||
return true;
|
||||
$sqrt = sqrt($prime);
|
||||
for ($i = 3; $i <= $sqrt; $i+=2){
|
||||
if ($prime%$i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
$high = 0;
|
||||
$max_primes = 0;
|
||||
for($a=-999; $a<1000; $a++) {
|
||||
for($b=-999; $b<1000; $b=$b+2) {
|
||||
$n=0;
|
||||
while(is_prime($n*$n + $a * $n + $b)) {
|
||||
$n++;
|
||||
if($n > $max_primes) {
|
||||
$max_primes = $n;
|
||||
echo "max: $n a: $a b: $b\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
function is_prime($prime) {
|
||||
if($prime == 1)
|
||||
return true;
|
||||
if($prime == 2)
|
||||
return true;
|
||||
$sqrt = sqrt($prime);
|
||||
for ($i = 3; $i <= $sqrt; $i+=2){
|
||||
if ($prime%$i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
$high = 0;
|
||||
$max_primes = 0;
|
||||
for($a=-999; $a<1000; $a++) {
|
||||
for($b=-999; $b<1000; $b=$b+2) {
|
||||
|
||||
$n=0;
|
||||
while(true) {
|
||||
echo $n*$n + $a * $n + $b . "\n";
|
||||
if(!is_prime($n*$n + $a * $n + $b)) {
|
||||
if($n > $max_primes) {
|
||||
$max_primes = $n;
|
||||
echo "max: $n a: $a b: $b\n";
|
||||
}
|
||||
break;
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
DIGITS = 1000
|
||||
|
||||
max = 10 ** (DIGITS-1)
|
||||
fcurrent = 1
|
||||
fprev = 1
|
||||
term = 2
|
||||
while fcurrent < max do
|
||||
term = term + 1
|
||||
fnext = fcurrent + fprev
|
||||
fprev = fcurrent;
|
||||
fcurrent = fnext;
|
||||
end
|
||||
puts term
|
@ -1,32 +0,0 @@
|
||||
title: What is the sum of both diagonals in a 1001 by 1001 spiral?
|
||||
url: http://projecteuler.net/problem=28
|
||||
|
||||
desc: |
|
||||
Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:
|
||||
21 22 23 24 25
|
||||
20 7 8 9 10
|
||||
19 6 1 2 11
|
||||
18 5 4 3 12
|
||||
17 16 15 14 13
|
||||
It can be verified that the sum of the numbers on the diagonals is 101.
|
||||
What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
|
||||
|
||||
solution: |
|
||||
Step around in the spiral (add 2 - 3 times, then add 4 - 3times, then 6 - times etc)
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
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
|
@ -1,19 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#define SIZE 1001
|
||||
#define SIDES 4
|
||||
|
||||
int main( )
|
||||
{
|
||||
|
||||
int sum = 1;
|
||||
int result=1;
|
||||
int addition;
|
||||
for(addition = 2; addition <= SIZE; addition+=2) {
|
||||
int cside;
|
||||
for(cside = 0; cside < SIDES; cside++) {
|
||||
sum += addition;
|
||||
result += sum;
|
||||
}
|
||||
}
|
||||
printf( "%i", result );
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
SIZE = 1001;
|
||||
SIDES = 4
|
||||
|
||||
sum = 1;
|
||||
result=1;
|
||||
for(addition = 2; addition <= SIZE; addition+=2) {
|
||||
for(cside = 0; cside < SIDES; cside++) {
|
||||
sum += addition;
|
||||
result += sum;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(result);
|
@ -1,12 +0,0 @@
|
||||
SIZE = 1001;
|
||||
SIDES = 4;
|
||||
sum = 1;
|
||||
result=1;
|
||||
for addition = 2,SIZE,2 do
|
||||
for cside=0,(SIDES-1) do
|
||||
sum = sum + addition;
|
||||
result = result + sum;
|
||||
end
|
||||
end
|
||||
|
||||
print(result)
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
define('SIZE',1001);
|
||||
define('SIDES',4);
|
||||
$sum = 1;
|
||||
$result=1;
|
||||
for($addition = 2; $addition <= SIZE; $addition+=2) {
|
||||
for($cside = 0; $cside < SIDES; $cside++) {
|
||||
$sum += $addition;
|
||||
$result += $sum;
|
||||
}
|
||||
}
|
||||
echo $result;
|
@ -1,12 +0,0 @@
|
||||
|
||||
SIZE = 1001
|
||||
SIDES = 4
|
||||
sum = 1;
|
||||
result=1;
|
||||
(2...SIZE).step(2) { |add|
|
||||
SIDES.downto(1) {
|
||||
sum += add;
|
||||
result += sum;
|
||||
}
|
||||
}
|
||||
puts result
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
define("TOTAL", 200);
|
||||
$combo=0;
|
||||
$sum = 200;
|
||||
|
||||
for ($a = 0; $a <= (TOTAL / 200); $a++) {
|
||||
$sum_a = TOTAL - ($a * 200);
|
||||
for ($b = 0; $b <= ($sum_a / 100); $b++) {
|
||||
$sum_b = $sum_a - ($b * 100);
|
||||
for ($c = 0; $c <= ($sum_b / 50); $c++) {
|
||||
$sum_c = $sum_b - ($c * 50);
|
||||
for ($d = 0; $d <= ($sum_c / 20); $d++) {
|
||||
$sum_d = $sum_c - ($d * 20);
|
||||
for ($e = 0; $e <= ($sum_d / 10); $e++) {
|
||||
$sum_e = $sum_d - ($e * 10);
|
||||
for ($f = 0; $f <= ($sum_e / 5); $f++) {
|
||||
$sum_f = $sum_e - ($f * 5);
|
||||
for ($g = 0; $g <= ($sum_e / 2); $g++) {
|
||||
$sum_g = $sum_f - ($g * 2);
|
||||
for ($h = 0; $h <= ($sum_g / 1); $h++) {
|
||||
|
||||
if ($a * 200 + $b * 100 + $c * 50 + $d * 20 + $e * 10 + $f * 5 + $g * 2 + $h == TOTAL) {
|
||||
$combo++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo $combo;
|
6
ProjectEuler/032/solve.php
Normal file
6
ProjectEuler/032/solve.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
function pandigital($number) {
|
||||
$array = count_chars($number,1);
|
||||
ksort($array);
|
||||
if($array == array(49=>1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { return true;} else { return false; }
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
$sum = [];
|
||||
|
||||
for($n = 10; $n <= 99; $n++)
|
||||
{
|
||||
for($d=$n+1;$d <= 99; $d++)
|
||||
{
|
||||
foreach([1,2,3,4,5,6,7,8,9] as $digit)
|
||||
{
|
||||
$ns = (int)str_replace($digit, '', $n);
|
||||
$ds = (int)str_replace($digit, '', $d);
|
||||
|
||||
if($n != $ns && $d != $ds && $d != 0 && $ds != 0)
|
||||
{
|
||||
if($n/$d == $ns/$ds)
|
||||
{
|
||||
echo "$n/$d = $ns/$ds\n";
|
||||
$sum[] = $ns/$ds;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
echo array_product($sum).PHP_EOL;
|
@ -6,7 +6,7 @@ desc: |
|
||||
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
|
||||
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
|
||||
solution: Bruteforce
|
||||
solutions:
|
||||
solutons:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
|
@ -1,11 +0,0 @@
|
||||
title: How many circular primes are there below one million?
|
||||
url: http://projecteuler.net/problem=35
|
||||
|
||||
desc: |
|
||||
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
|
||||
There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
|
||||
How many circular primes are there below one million?
|
||||
solution: Bruteforce
|
||||
solutions:
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
function is_prime($prime) {
|
||||
if($prime < 1)
|
||||
return false;
|
||||
|
||||
if($prime == 1)
|
||||
return true;
|
||||
if($prime == 2)
|
||||
return true;
|
||||
$sqrt = sqrt($prime);
|
||||
for ($i = 3; $i <= $sqrt; $i+=2){
|
||||
if ($prime%$i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($handle = fopen("primes1000000.txt", "r")) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
|
||||
if ($data[1] >= 1000000)
|
||||
break;
|
||||
//If there's an even digit (or a 5) we can instantly exclude it as when rotated it will not not be a prime.
|
||||
if (
|
||||
strpos((string) $data[1], "0") !== false ||
|
||||
strpos((string) $data[1], "2") !== false ||
|
||||
strpos((string) $data[1], "4") !== false ||
|
||||
strpos((string) $data[1], "5") !== false ||
|
||||
strpos((string) $data[1], "6") !== false ||
|
||||
strpos((string) $data[1], "8") !== false
|
||||
) {
|
||||
|
||||
continue;
|
||||
}
|
||||
$primes[] = (int) $data[1];
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
echo "File read\n";
|
||||
|
||||
$count = 1+1; //2 and 5 are primes but not included
|
||||
foreach($primes as $prime)
|
||||
{
|
||||
//echo "Now testing $prime\n";
|
||||
$newprime = $prime;
|
||||
for($rotate = 1; $rotate < strlen($prime); $rotate++)
|
||||
{
|
||||
$newprime = substr($newprime, -1, 1).substr($newprime, 0, -1);
|
||||
//echo "New prime: $newprime\n";
|
||||
if(!in_array($newprime, $primes))
|
||||
{
|
||||
continue 2;
|
||||
}
|
||||
|
||||
}
|
||||
$count++;
|
||||
echo $prime.PHP_EOL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo "Total: $count\n";
|
@ -1,18 +0,0 @@
|
||||
title: Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2.
|
||||
url: http://projecteuler.net/problem=36
|
||||
|
||||
desc: |
|
||||
The decimal number, 585 = 1001001001 (binary), is palindromic in both bases.
|
||||
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
|
||||
(Please note that the palindromic number, in either base, may not include leading zeros.)
|
||||
|
||||
solution: We can skip all even numbers since a even number would end in binary 10 - In reverse that would be 01 and we are told to skip leading 0's
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
|
@ -1,12 +0,0 @@
|
||||
<?php
|
||||
define('MAX',1000000);
|
||||
$result = 0;
|
||||
for($i=1;$i<MAX;$i+=2) {
|
||||
if($i == strrev($i)) {
|
||||
$bin = decbin($i);
|
||||
if($bin == strrev($bin)) {
|
||||
$result += $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo $result;
|
@ -1,10 +0,0 @@
|
||||
MAX = 1000000
|
||||
result = 0
|
||||
(1..MAX).step(2) { |i|
|
||||
if(i.to_s == i.to_s.reverse)
|
||||
if(i.to_s(2) == i.to_s(2).reverse)
|
||||
result += i
|
||||
end
|
||||
end
|
||||
}
|
||||
print result
|
@ -1,19 +0,0 @@
|
||||
title: What is the largest 1 to 9 pandigital that can be formed by multiplying a fixed number by 1, 2, 3, ... ?
|
||||
url: http://projecteuler.net/problem=38
|
||||
|
||||
desc: |
|
||||
Take the number 192 and multiply it by each of 1, 2, and 3:
|
||||
192 x 1 = 192
|
||||
192 x 2 = 384
|
||||
192 x 3 = 576
|
||||
By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)
|
||||
The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).
|
||||
What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n 1?
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
function pandigital($number) {
|
||||
$array = count_chars($number,1);
|
||||
ksort($array);
|
||||
if($array == array(49=>1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { return true;} else { return false; }
|
||||
}
|
||||
|
||||
while(true) {
|
||||
$value++;
|
||||
|
||||
$test = array(1,2);
|
||||
$key = 2;
|
||||
while(true) {
|
||||
$new = array();
|
||||
foreach($test as $p) {
|
||||
$new[] = $value * $p;
|
||||
}
|
||||
$var = implode('',$new);
|
||||
if(strlen($var) != 9) { break; }
|
||||
if(strlen($var) == 9 AND pandigital($var)) { $good[] = $var; break; }
|
||||
$test[] = $key++;
|
||||
}
|
||||
if($value > 9999) { break; }
|
||||
}
|
||||
|
||||
rsort($good);
|
||||
echo $good[0];
|
@ -1,18 +0,0 @@
|
||||
title: Integer right triangles
|
||||
url: http://projecteuler.net/problem=39
|
||||
|
||||
desc: |
|
||||
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
|
||||
{20,48,52}, {24,45,51}, {30,40,50}
|
||||
For which value of p <=1000, is the number of solutions maximised?
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.c:
|
||||
desc: Basic solution
|
||||
language: c
|
@ -1,28 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#define P_VALUE 1000
|
||||
|
||||
int p, a, b, c, max, key, result = 0;
|
||||
int main( )
|
||||
{
|
||||
for(p=2;p<P_VALUE;p++)
|
||||
{
|
||||
|
||||
for(a=2;a<p;a++)
|
||||
{
|
||||
for(b=a;b<p;b++)
|
||||
{
|
||||
//Find C so it runs faster...
|
||||
c = p - a - b;
|
||||
if(a*a+b*b == c*c) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(result > max) {
|
||||
max = result;
|
||||
key = p;
|
||||
}
|
||||
result = 0;
|
||||
}
|
||||
printf( "%i", key);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
define('P_VALUE',1000);
|
||||
|
||||
for($p=2;$p<P_VALUE;$p++) {
|
||||
|
||||
for($a=2;$a<$p;$a++) {
|
||||
for($b=$a;$b<$p;$b++) {
|
||||
//Find C so it runs faster...
|
||||
$c = $p - $a - $b;
|
||||
if($a*$a+$b*$b == $c*$c) {
|
||||
$result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($result > $max) {
|
||||
$max = $result; $key = $p;
|
||||
}
|
||||
$result = 0;
|
||||
}
|
||||
echo $key;
|
@ -1,14 +0,0 @@
|
||||
title: Integer right triangles
|
||||
url: http://projecteuler.net/problem=41
|
||||
|
||||
desc: |
|
||||
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
|
||||
What is the largest n-digit pandigital prime that exists?
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
function pandigital_less($number) {
|
||||
|
||||
$array = count_chars($number,1);
|
||||
|
||||
foreach(range(1,count($array)) as $char) {
|
||||
if( $array[ord($char)]!== 1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function is_prime($prime) {
|
||||
//if($prime%2 == 0) return false;
|
||||
|
||||
$sqrt = sqrt($prime);
|
||||
for ($i = 3; $i <= $sqrt; $i+=2){
|
||||
if ($prime%$i == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//We don't need to check uneven numbers
|
||||
//Has to start with a 7 and therefor be 7 digits long
|
||||
for($var = 7000001; $var < 8000000; $var=$var+2) {
|
||||
if(is_prime($var) AND pandigital_less($var)) { $result = $var; }
|
||||
}
|
||||
echo $result;
|
@ -1,15 +0,0 @@
|
||||
title: Coded triangle numbers
|
||||
url: http://projecteuler.net/problem=42
|
||||
|
||||
desc: |
|
||||
The nth term of the sequence of triangle numbers is given by, tn = 0.5n(n+1); so the first ten triangle numbers are:
|
||||
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
|
||||
By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
|
||||
Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?
|
||||
solution: Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Expects data on STDIN
|
||||
language: php
|
||||
parameters: < ProjectEuler\042\words.txt
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
$words = explode('","',substr(file_get_contents('php://STDIN'),1,-1));
|
||||
|
||||
//Find triangles
|
||||
for($t=1;$t<40;$t++) {
|
||||
$triangle_numbers[] = 0.5*$t*($t+1);
|
||||
}
|
||||
|
||||
foreach($words as $word) {
|
||||
for($c =0; $c < strlen($word); $c++) {
|
||||
$char_sum += ord($word[$c]) - 64;
|
||||
}
|
||||
if(in_array($char_sum,$triangle_numbers)) {
|
||||
$result++;
|
||||
}
|
||||
$char_sum = 0;
|
||||
}
|
||||
echo $result;
|
File diff suppressed because one or more lines are too long
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Triangle Tn = n*(n+1)/2
|
||||
* Pentagonal Pn = n*(3n-1)/2
|
||||
* Hexagonal Hn = n*(2n-1)
|
||||
* T(285) = P(165) = H(143) = 40755
|
||||
* Find next
|
||||
*/
|
||||
|
||||
function Tn($n)
|
||||
{
|
||||
return $n*($n+1)/2;
|
||||
}
|
||||
|
||||
function Pn($n)
|
||||
{
|
||||
return $n*(3*$n-1)/2;
|
||||
}
|
||||
|
||||
function Hn($n)
|
||||
{
|
||||
return $n*(2*$n-1);
|
||||
}
|
||||
|
||||
echo "Tn(285)=".Tn(285).PHP_EOL;
|
||||
echo "Pn(165)=".Pn(165).PHP_EOL;
|
||||
echo "Hn(143)=".Hn(143).PHP_EOL;
|
||||
|
||||
|
||||
for($t = 285; $t < 100000; $t++)
|
||||
{
|
||||
$triangle[$t] = Tn($t);
|
||||
}
|
||||
|
||||
for($p = 165; $p < 100000; $p++)
|
||||
{
|
||||
$pentagonal[$p] = Pn($p);
|
||||
}
|
||||
|
||||
for($h = 143; $h < 100000; $h++)
|
||||
{
|
||||
$hexagonal[$h] = Hn($h);
|
||||
}
|
||||
|
||||
$result = array_intersect($triangle, $pentagonal, $hexagonal);
|
||||
|
||||
print_r($result);
|
@ -1,17 +0,0 @@
|
||||
title: Find the last ten digits of 11 + 22 + ... + 10001000.
|
||||
url: http://projecteuler.net/problem=48
|
||||
|
||||
desc: |
|
||||
The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
|
||||
Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Using BCMath to cope with large numbers
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
define('MAX',1000);
|
||||
$sum = 0;
|
||||
for($c =1; $c <= MAX;$c++) {
|
||||
$sum = bcadd($sum,bcpow($c,$c));
|
||||
}
|
||||
echo substr($sum,-10,10);
|
@ -1,6 +0,0 @@
|
||||
MAX = 1000
|
||||
sum = 0
|
||||
(1..MAX).each do |digit|
|
||||
sum += digit**digit
|
||||
end
|
||||
puts sum.to_s[-10..-1]
|
@ -1,16 +0,0 @@
|
||||
title: Finding Fibonacci numbers for which the first and last nine digits are pandigital.
|
||||
url: http://projecteuler.net/problem=104
|
||||
|
||||
desc: |
|
||||
The Fibonacci sequence is defined by the recurrence relation:
|
||||
Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.
|
||||
It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.
|
||||
Given that Fk is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Bruteforce - Sooooo slow
|
||||
language: php
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
function pandigital($num) {
|
||||
for ($i = 1; $i <= 9; $i++) {
|
||||
if(strpos($n,(string)$i) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
$var = 1;
|
||||
$k = 1;
|
||||
while(true) {
|
||||
$k++;
|
||||
$new = bcadd($var,$prev);
|
||||
$prev = $var;
|
||||
$var = $new;
|
||||
|
||||
if(pandigital(substr($var,-9)) AND pandigital(substr($var,0,9))) { echo $k; die; }
|
||||
}
|
1
ct.bat
1
ct.bat
@ -1,2 +1 @@
|
||||
@ECHO OFF
|
||||
ruby CT.rb %1 %2
|
@ -1,5 +0,0 @@
|
||||
copy.src.files=false
|
||||
copy.src.target=
|
||||
index.file=
|
||||
run.as=SCRIPT
|
||||
url=http://localhost/codingtests/
|
@ -1,7 +0,0 @@
|
||||
include.path=${php.global.include.path}
|
||||
php.version=PHP_54
|
||||
source.encoding=UTF-8
|
||||
src.dir=.
|
||||
tags.asp=false
|
||||
tags.short=true
|
||||
web.root=.
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.php.project</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/php-project/1">
|
||||
<name>codingtests</name>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
100
primes100.txt
100
primes100.txt
@ -1,100 +0,0 @@
|
||||
1, 2, 2
|
||||
2, 3, 1
|
||||
3, 5, 2
|
||||
4, 7, 2
|
||||
5, 11, 4
|
||||
6, 13, 2
|
||||
7, 17, 4
|
||||
8, 19, 2
|
||||
9, 23, 4
|
||||
10, 29, 6
|
||||
11, 31, 2
|
||||
12, 37, 6
|
||||
13, 41, 4
|
||||
14, 43, 2
|
||||
15, 47, 4
|
||||
16, 53, 6
|
||||
17, 59, 6
|
||||
18, 61, 2
|
||||
19, 67, 6
|
||||
20, 71, 4
|
||||
21, 73, 2
|
||||
22, 79, 6
|
||||
23, 83, 4
|
||||
24, 89, 6
|
||||
25, 97, 8
|
||||
26, 101, 4
|
||||
27, 103, 2
|
||||
28, 107, 4
|
||||
29, 109, 2
|
||||
30, 113, 4
|
||||
31, 127, 14
|
||||
32, 131, 4
|
||||
33, 137, 6
|
||||
34, 139, 2
|
||||
35, 149, 10
|
||||
36, 151, 2
|
||||
37, 157, 6
|
||||
38, 163, 6
|
||||
39, 167, 4
|
||||
40, 173, 6
|
||||
41, 179, 6
|
||||
42, 181, 2
|
||||
43, 191, 10
|
||||
44, 193, 2
|
||||
45, 197, 4
|
||||
46, 199, 2
|
||||
47, 211, 12
|
||||
48, 223, 12
|
||||
49, 227, 4
|
||||
50, 229, 2
|
||||
51, 233, 4
|
||||
52, 239, 6
|
||||
53, 241, 2
|
||||
54, 251, 10
|
||||
55, 257, 6
|
||||
56, 263, 6
|
||||
57, 269, 6
|
||||
58, 271, 2
|
||||
59, 277, 6
|
||||
60, 281, 4
|
||||
61, 283, 2
|
||||
62, 293, 10
|
||||
63, 307, 14
|
||||
64, 311, 4
|
||||
65, 313, 2
|
||||
66, 317, 4
|
||||
67, 331, 14
|
||||
68, 337, 6
|
||||
69, 347, 10
|
||||
70, 349, 2
|
||||
71, 353, 4
|
||||
72, 359, 6
|
||||
73, 367, 8
|
||||
74, 373, 6
|
||||
75, 379, 6
|
||||
76, 383, 4
|
||||
77, 389, 6
|
||||
78, 397, 8
|
||||
79, 401, 4
|
||||
80, 409, 8
|
||||
81, 419, 10
|
||||
82, 421, 2
|
||||
83, 431, 10
|
||||
84, 433, 2
|
||||
85, 439, 6
|
||||
86, 443, 4
|
||||
87, 449, 6
|
||||
88, 457, 8
|
||||
89, 461, 4
|
||||
90, 463, 2
|
||||
91, 467, 4
|
||||
92, 479, 12
|
||||
93, 487, 8
|
||||
94, 491, 4
|
||||
95, 499, 8
|
||||
96, 503, 4
|
||||
97, 509, 6
|
||||
98, 521, 12
|
||||
99, 523, 2
|
||||
100, 541, 18
|
1000
primes1000.txt
1000
primes1000.txt
File diff suppressed because it is too large
Load Diff
10000
primes10000.txt
10000
primes10000.txt
File diff suppressed because it is too large
Load Diff
1000000
primes1000000.txt
1000000
primes1000000.txt
File diff suppressed because it is too large
Load Diff
16
settings.yml
16
settings.yml
@ -1,16 +0,0 @@
|
||||
languages:
|
||||
javascript:
|
||||
command: node
|
||||
ext: [js,javascript]
|
||||
php:
|
||||
command: php
|
||||
ext: [php]
|
||||
ruby:
|
||||
command: ruby
|
||||
ext: [ruby,rb]
|
||||
tcc:
|
||||
command: tcc -run
|
||||
ext: [c]
|
||||
lua:
|
||||
command: lua
|
||||
ext: [lua]
|
Loading…
Reference in New Issue
Block a user