Project Euler #71

Click here to read the original problem

After giving the problem a read, this is how I broke it down in my head. From the set \{(n, d) \mid n<d, d\leq1000000\} find max(\frac{n}{d}) where \frac{n}{d} < \frac{3}{7}. Let’s call \frac{3}{7} target for simplicity. In order to do this efficiently I did not want to list down all the numbers as there would be 333332833333500000 fractions to account for in that case. Instead I looked to find the fraction that would place to the immediate left of our target if it were included with all the fractions created with a certain value of d. That leaves us with 1e6 values to work with, significantly reducing the workload. So this value was determined using the simple simplification n = floor(target * d). This gives the largest integer n such that \frac{n}{d} < \frac{3}{7}. All of these fractions are compared to find the largest one and that is our answer fraction. Before we finish, we must reduce this fraction to its simplest form. This is easily done by dividing the numerator with the GCF of the numerator and the denominator. The GCF can be calculated using the python math module’s function or using a self written function of acceptable efficiency. This quotient gives us the final answer.

Output Screenshot
[The answer portion has been blacked out]

This algorithm found the answer in 0.8 seconds!

(Don’t) Plug in to the future

Latest leaks online suggest Apple is going to the ship the soon-to-be-launched iPhone 12 with no chargers and ear-pods in the box. This has caused widespread debate in the online community; some call it a pure money-grab move from Apple and some consider it a sensible move. Let’s dive deeper into it and see.

¿headphone jack?


Apple, since the very beginning, has had the habit of removing ports and virtually deleting technologies. The MacBook Pro in 2008 had 7 different types of ports and now well just 1. Now, I’m not going to argue over the power and capabilities of Thunderbolt 3 over USB-C. Personally, in an ideal world, it was the right move forwards. Up to 100W power delivery and 40 Gbps transfer speeds makes Thunderbolt 3 the port of the present. On to the next major removal – CD/DVD Drives. Apple included their ‘FusionDrive’ in Macs for years and then finally removed it at one keynote. In the coming few years it was no longer seen on any new Mac on the shelf. But this isn’t just about Macs. The iPhone itself received a port drop with the iPhone 7 – the 3.5mm audio jack. Now that was one change that stuck but soon enough other manufacturers followed Apple’s lead and now it seems like a thing of the past with wireless earbuds becoming a standard now.

There is one similarity among all these moves; they were all done to improve the overall design and form factor of the devices. Removing the headphone jack from the iPhone allowed Apple more room to operate with inside the phone and also enabled them to incorporate better water proofing (IP67). Similarly, the removal of the DVD players allowed MacBooks to be significantly thinner in the future. Apple’s design team wishes to create the best overall package with their products. That means, they want the sleekest design while not compromising on performance. Arguably, the current MacBook lineup may have short comings in that regard, but one should have to look no further than the iPad Pro for this vision being implemented correctly.

With this philosophy at it’s core, their vision for the true next generation iPhone is of a truly wireless iPhone. An iPhone that has no physical ports. That is something that may have a played a big part in this decision if the rumors are to be believed. Now, let’s look to answer some questions.

Why do it?

It is no rocket science that not shipping a charger and earbuds in the box in no way affects the iPhone design itself. What it does do is drastically reduce the overall box size. It is basically halved if not more. Smaller packages translates to cost savings. Why? Well, having smaller boxes will allow them to move more boxes in a plane or a shipping container. That translates to lower average costs. On top of that, if you add the selling costs of these two, you end up with about $45 (or ₹5500 in India). It must be noted, this is no indication that Apple will reduce the cost of the iPhone. However, it is possible.

I ask you this, if you are already an iPhone user: do you need a new charger with your new iPhone? An overwhelming majority of iPhone buyers are already iPhone users. It is very likely that they already have a lightning charger. Possibly, an even better one (15W Fast Charger that is not shipped in the box). According to a statistical study, the entirety of chargers and earphones shipped with phones that are thrown away, account for 300,000 tonnes of e-waste. Lately, Apple has been focusing on the environmental aspect to their devices a lot. They usually have one slide where they talk about it in their keynotes right before the pricing. This would a bold but sensible move that is a larger step towards reducing electronic waste.

There is one last possible reason floating around right now. Apple plans of introducing their first port-less iPhone next year and that will almost certainly not ship with a Qi wireless charger (it costs big bucks). This is just Apple trying to get their customers used to this idea of the phone shipping without a charger in the box. Instead of throwing change right at us Apple wants a gradual transition. Nothing to complain about here, but also nothing to read too much into either.


This move appears to be one that will ultimately benefit the entire community in one way or another. It is likely to please sustainability enthusiasts, price-drop advocates and most importantly, Apple executives. In a few months time, we will know for sure what Apple has got up their sleeve.

Project Euler #99

Click here to read the original problem

So the main challenge here was to be able to compare two different exponents (very large ones) like 632382518061 and 519432525806. 100 such had to be compared and the greatest to be found. To compute even one can take a decent machine several minutes, let alone 100 of these. Even if you do go by the long road, you end up comparing values stored with fixed accuracy (significant figures) in scientific form – something python does automatically for very large numbers like these.

Hence, to simplify calculations I did some algebraic manipulations, using logarithms. Take two exponents such that a^b > c^d. For all a,b\geq0, we can take the natural log of both sides and not change the equation (the sign to be specific), resulting in – b\log(a) > d\log(c). We already know that our assumption about a and b is true for the given data, thus, we can continue to calculate the product of the exponent part and the natural log of the base of each number. For whichever datum this is the greatest, is in turn the greatest number of the lot.

With this method, I was able to achieve an execution time of 0.007 seconds. That is fast enough!

Output Screenshot
[The answer portion has been blacked out]
Create your website with
Get started