diff --git a/www/statics/euler/Euler_Problem-102.b93 b/www/statics/euler/Euler_Problem-102.b93 new file mode 100644 index 0000000..21e84ce --- /dev/null +++ b/www/statics/euler/Euler_Problem-102.b93 @@ -0,0 +1,18 @@ +003p>013p>053p023p033p143p>23g13g9+g:59*-!#v_:48*-!#v_ :92+4*-!#v_vv1g55*-g50g< + |-***8555< ^p32+1g3245g05g-25^ + >03g.@ ^p34-10$13g1+:13p^ ^ < >33g43g*53g5p45g 05g-:*55g1^ +XXXXXXX v+*:-g51g53*:-g50g52p42+*g51-g51g55*g50-g50g54p41+*-g51g53-< +OOOOOO >34p25g05g-05g*35g15g-15g*+44p14g44g*34g24g*-54p14g24g*04g4v + ^p30+g30!++!`+g45g46g47`g460`g450p47-*g41g41*g43g40p46-*g4 < + + +-340,495,-153,-910,835,-947 +-175,41,-421,-714,574,-645 +-547,712,-352,579,951,-786 +419,-864,-83,650,-399,171 +-429,-89,-357,-930,296,-29 +-734,-702,823,-745,-684,-62 +... +... +... \ No newline at end of file diff --git a/www/statics/euler/Euler_Problem-102.php b/www/statics/euler/Euler_Problem-102.php new file mode 100644 index 0000000..69e549f --- /dev/null +++ b/www/statics/euler/Euler_Problem-102.php @@ -0,0 +1,19 @@ + 102, + 'title' => 'Triangle containment', + 'description' => function(){ return file_get_contents(__DIR__ . '/Euler_Problem-102_description.md'); }, + 'code' => function(){ return file_get_contents(__DIR__ . '/Euler_Problem-102.b93'); }, + 'explanation' => function(){ return file_get_contents(__DIR__ . '/Euler_Problem-102_explanation.md'); }, + 'url_euler' => 'http://projecteuler.net/problem=102', + 'url_raw' => 'https://raw.githubusercontent.com/Mikescher/Project-Euler_Befunge/master/processed/Euler_Problem-102.b93', + 'url_github' => 'https://github.com/Mikescher/Project-Euler_Befunge', + 'abbreviated' => true, + 'steps' => 1995449, + 'time' => 281, + 'width' => 80, + 'height' => 1009, + 'value' => 228, +]; diff --git a/www/statics/euler/Euler_Problem-102_description.md b/www/statics/euler/Euler_Problem-102_description.md new file mode 100644 index 0000000..c7069aa --- /dev/null +++ b/www/statics/euler/Euler_Problem-102_description.md @@ -0,0 +1,16 @@ +Three distinct points are plotted at random on a Cartesian plane, for which `-1000 <= x,y <= 1000`, such that a triangle is formed. + +Consider the following two triangles: + +~~~ +A(-340,495), B(-153,-910), C(835,-947) + +X(-175,41), Y(-421,-714), Z(574,-645) +~~~ + +It can be verified that triangle ABC contains the origin, whereas triangle XYZ does not. + +Using [triangles.txt](https://projecteuler.net/project/resources/p102_triangles.txt), a 27K text file containing the co-ordinates +of one thousand "random" triangles, find the number of triangles for which the interior contains the origin. + +NOTE: The first two examples in the file represent the triangles in the example given above. \ No newline at end of file diff --git a/www/statics/euler/Euler_Problem-102_explanation.md b/www/statics/euler/Euler_Problem-102_explanation.md new file mode 100644 index 0000000..29a2168 --- /dev/null +++ b/www/statics/euler/Euler_Problem-102_explanation.md @@ -0,0 +1,7 @@ +Not much to say here, a bit of input parsing, +then looping through all lines and testing the triangles +with [this](http://blackpawn.com/texts/pointinpoly/default.html) basic algorithm. + +Because the program is already pretty fast we don't spend much time optimizing it, +that means most variables have fixed grid values, even though I could optimize a few +to live only on the stack.