What is Project Euler?
Project Euler is a series of challenging problems that require mathematical and programming skills. Somebody who enjoys learning new area of mathematics, project Euler is going to be a fun journey.
Where are the problems ?
The problems are right here in their official archive.
Let’s solve a problem from the archive and understand its complexity. Randomly I have chosen Problem no 116.
Problem 116 : Red, green or blue tiles
Problem Statement

Solution: [ IT IS ADVISED TO TRY YOURSELF FIRST]
A red tile is of length 2, green is of length 3 and blue is of length 4.
Since, we need to count total ways for 50 units of black colored square tiles, say k = 50.
def E_116(i, k):
ways = [1] * i + [0] * (k-i+1)
for j in range(i, k+1):
ways[j] += ways[j - 1] + ways[j - i]
return ways[k] - 1
Here, we are initializing our function E_116() which holds the logic of the solution to the problem.The function E_116() has two parameters i = number of black coloured square tiles covered by the new coloured (red, green or blue) tiles and k = total number of black coloured square tiles.
In the function,
ways = [1] * i + [0] * (k-i+1)

So, ways is a list which holds the total number of ways which the i length block can cover 50 black coloured square tiles.For e.g:

In the above example x = [1, 1, 1, 0, 0, 0] , has 1 (x3) and 0 (x3) , where 1 represents possible solution case and 0 represents failure.As we can compare for i = 3 and k = 5 from the question, we get total 3 possible ways.Hence there are 1 (x3) in the list, ways.

for j in range(i, k+1):
ways[j] += ways[j - 1] + ways[j - i]
Using the for loop we are iterating from i to 50, we have written k+1 since iterating in the loop through range() will exclude the last case.In ways[j] += ways[j – 1] + ways[j – i], we are updating the jth index of the list ways with the summation of (j-1) and (j+i)th index’s value and also the jth index value (Since +=).
These are the possible values of j, for i=3 and k =5.

Finally we return our list as return ways[k] – 1.So, for i=3 and k=5, this gives the solution(i.e, Ans = 3)

Lastly in our code,
print("Number of black tiles =", k, "units")
print("Number of ways to fill:", E_116(2, k) + E_116(3, k) + E_116(4, k))
We print away our result using the print() function. The first statement prints Number of black tiles = 50 and the second statement prints Number of ways to fill: 20492570929 which is the desired answer to the problem.
k = 50
def E_116(i, k):
ways = [1] * i + [0] * (k-i+1)
for j in range(i, k+1):
ways[j] += ways[j - 1] + ways[j - i]
return ways[k] - 1
print("Number of black tiles =", k, "units")
print("Number of ways to fill:", E_116(2, k) + E_116(3, k) + E_116(4, k))
|
Resources:
Similar Reads
Python Projects - Beginner to Advanced
Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow. Hereâs a list
10 min read
10 Project Ideas That Use Prim's Algorithm
Prim's algorithm is a greedy algorithm used to find the minimum spanning tree (MST) of a weighted undirected graph. A spanning tree of a graph is a tree that spans all the vertices of the graph, i.e., it is a subgraph that includes all the vertices and is also a tree. A minimum spanning tree is a sp
9 min read
Top 7 Python Project Ideas for Beginners in 2024
The Python programming language has garnered widespread adoption across a multitude of technical domains, including data science, web development, and machine learning. For aspiring Python programmers, however, the initial learning curve can present a significant challenge. This meticulously curated
8 min read
Project Schedule Tracking Tools in Software Engineering
Project Planning is an important activity performed by Project Managers. Project Managers can use the tools and techniques to develop, monitor, and control project timelines and schedules. The tracking tools can automatically produce a pictorial representation of the project plan. These tools also i
8 min read
Flipkart Interview | Set 11
Checking your coding capabilities and thinking level is their main motive. Hence the whole procedure I was involved in dealt only with coding questions.There were total 4 Rounds. Online Coding Machine Coding Face to face Technical Interview Technical + HR Round 1 : Online Coding :Time: 1 hour 30 Min
5 min read
Intuit Interview | Set 8 (On-Campus)
Intuit came to our college campus for placements. Shortlisted 13 students after written and then selected 4 students for Full Time Job. There were 3 coding questions and 21 (apti+puzzles) to be done in 90 minutes. Apti n puzzle questions were 5 marks each and coding questions were 100 marks each. On
5 min read
Morgan Stanley Interview | Set 11 (On-Campus)
Multiple Choice Questions Questions ranging from give the output of following C program to some theoretical concepts of OS etc. Coding 1. Give maximum subarray product in a given input array which can contain integers (including negative and zero). 2. Given a set of n coins of some denominations (ma
4 min read
Microsoft Interview Experience | Set 110 (Internship)
Round 1 It was an online coding round conducted on cocubes.com. It was a 75 minutes round consisting of 3 coding questions only. Questions were: An array of integers is given which represents the heights of n buildings.Sun start falling from the left side. If there is a building of certain Height, a
4 min read
LinkedIn Interview Experience | Set 3 (On-Campus)
LinkedIn Interview Experience (On Campus - Day 1) Online Round : 3 coding Questions in 1 hour : 1. We have to implement int getIntComplement(int N) function , that will give complement (bitwise complement. ) of b a given integer . Start unsetting from the left most set bit of the number. 0 There are
3 min read
Amazon Interview | Set 34
First of all, a very very big thanks to whole team of geeks for geeks. It is because of them only that I was able to crack the interview process of amazon and get a job in my dream company. No of Rounds: 1 MCQ round + 2 online test round + 4 PI Type of Interviews: Campus Interview for freshers MCQ r
6 min read