<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2023-03-08T11:18:38+00:00</updated><id>/feed.xml</id><title type="html">Jordan McIntyre’s portfolio website</title><subtitle>This is my portfolio website, containing information about my studies, interests and work experience.</subtitle><author><name>Jordan McIntyre</name></author><entry><title type="html">Project Euler #91</title><link href="/posts/2023/02/27/project-euler-91.html" rel="alternate" type="text/html" title="Project Euler #91" /><published>2023-02-27T02:31:00+00:00</published><updated>2023-02-27T02:31:00+00:00</updated><id>/posts/2023/02/27/project-euler-91</id><content type="html" xml:base="/posts/2023/02/27/project-euler-91.html">&lt;p&gt;Hello and welcome to my first post, in these I will try to share interesting things I’ll be working on which
could range from problem solving to game development.&lt;/p&gt;

&lt;p&gt;In this post I will be highlighting my experience with &lt;a href=&quot;https://projecteuler.net/problem=91&quot;&gt;this&lt;/a&gt; problem.&lt;/p&gt;

&lt;p&gt;In this problem it asks to solve for all right triangles starting from the origin &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;O(0, 0)&lt;/code&gt; in the 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;range 0 &amp;lt;= x1,y1, x2,y2 &amp;lt;= 50&lt;/code&gt;. For a while this problem seemed intimidating, I always kind of knew what I needed to solve the problem but I just wasn’t sure how to go about it.&lt;/p&gt;

&lt;p&gt;Since we already have one of the triangle’s points at the origin we only need to find points &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;P(x1, y1)&lt;/code&gt; and
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Q(x2, y2)&lt;/code&gt;. To do so I simply made nested loops to test all values needed. The next challenge comes from
determining if the created triangle has a right angle in it. Luckily since a triangle only has three sides that’ll only be three angles to check from our points.&lt;/p&gt;

&lt;p&gt;An angle can be calculated like this in python:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;math&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atan2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;degrees&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;calculate_angle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;tuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;tuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;tuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;tuple&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;degrees&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;atan2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atan2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;It is important to note that the order of these points matter. By testing a different order of points with
this function I was able to get the angles I needed to determine if the triangle was right angled.&lt;/p&gt;

&lt;p&gt;Now however comes another hurdle, duplicates!&lt;/p&gt;

&lt;p&gt;With my nested loops it’s very easy to have duplicate points &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;P&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Q&lt;/code&gt; pass the inspection and be counted, so to make sure to avoid this scenario I tried storing my triangles in a list. This proved not to work because of how inefficient searching lists can be. Even leaving my program running over night didn’t yield a result, but by changing the list to a dictionary and using a hashable object, searching becomes much more efficient.&lt;/p&gt;

&lt;p&gt;Though still not the most efficient solution, switching from lists to dictionaries made my algorithm go from running (and not finishing) overnight to finishing in a few minutes on my machine.&lt;/p&gt;

&lt;p&gt;If you’re curious about my solution you can view it &lt;a href=&quot;https://github.com/Staggier/ProjectEuler/blob/master/python/PE%23091.py&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content><author><name>Jordan McIntyre</name></author><category term="posts" /><summary type="html">Hello and welcome to my first post</summary></entry></feed>