Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CONTRIBUTING
To contribute, create a new folder for each problem (if it doesn't exist) and work on your code there. Ex: Problem_1's solution should be in the same directory as the question.
PR's will not be accepted otherwise. Make sure your GitHub username is at the top of your code in a comment.
Keep the code clean, simple and well commented so that anyone in the future can understand easily. Any of these languages are
fine:
> C (`GNU GCC 6+`), C++ (`GNU GCC 6+`), Java (`Java SE 8+`), Python (`Python 3.6.5+`)

If you want to use another language, create a new issue and a maintainer will respond.
# CONTRIBUTING
To contribute, create a new folder for each problem (if it doesn't exist) and work on your code there. Ex: Problem_1's solution should be in the same directory as the question.
PR's will not be accepted otherwise. Make sure your GitHub username is at the top of your code in a comment.
Keep the code clean, simple and well commented so that anyone in the future can understand easily. Any of these languages are
fine:
> C (`GNU GCC 6+`), C++ (`GNU GCC 6+`), Java (`Java SE 8+`), Python (`Python 3.6.5+`)
If you want to use another language, create a new issue and a maintainer will respond.
12 changes: 6 additions & 6 deletions Problems/Problem_1/Problem_1.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Let start off with a simple one...
Have you heard of the convex hull problem?, it involves a very simple problem statement with a deceptively simple solution, however depending on your approach and ingenuity your solution could take 15 seconds or 15 minutes, so code effectively (HINT: Brute force is not the answer).

Problem : You are given a set of points on a 2-d plane, you have to come up with the points that form the boundary of the entire set of points, i.e find the points that make up the boundary of all the points given to you.

Also pls dont look up the answers online, that kinda violates the purpose of the whole problem.
Let start off with a simple one...
Have you heard of the convex hull problem?, it involves a very simple problem statement with a deceptively simple solution, however depending on your approach and ingenuity your solution could take 15 seconds or 15 minutes, so code effectively (HINT: Brute force is not the answer).
Problem : You are given a set of points on a 2-d plane, you have to come up with the points that form the boundary of the entire set of points, i.e find the points that make up the boundary of all the points given to you.
Also pls dont look up the answers online, that kinda violates the purpose of the whole problem.
80 changes: 40 additions & 40 deletions Problems/Problem_1/Test_cases.txt
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
0.3215348546593775 0.03629583077160248
0.02402358131857918 -0.2356728797179394
0.04590851212470659 -0.4156409924995536
0.3218384001607433 0.1379850698988746
0.11506479756447 -0.1059521474930943
0.2622539999543261 -0.29702873322836
-0.161920957418085 -0.4055339716426413
0.1905378631228002 0.3698601009043493
0.2387090918968516 -0.01629827079949742
0.07495888748668034 -0.1659825110491202
0.3319341836794598 -0.1821814101954749
0.07703635755650362 -0.2499430638271785
0.2069242999022122 -0.2232970760420869
0.04604079532068295 -0.1923573186549892
0.05054295812784038 0.4754929463150845
-0.3900589168910486 0.2797829520700341
0.3120693385713448 -0.0506329867529059
0.01138812723698857 0.4002504701728471
0.009645149586391732 0.1060251100976254
-0.03597933197019559 0.2953639456959105
0.1818290866742182 0.001454397571696298
0.444056063372694 0.2502497166863175
-0.05301752458607545 -0.06553921621808712
0.4823896228171788 -0.4776170002088109
-0.3089226845734964 -0.06356112199235814
-0.271780741188471 0.1810810595574612
0.4293626522918815 0.2980897964891882
-0.004796652127799228 0.382663812844701
0.430695573269106 -0.2995073500084759
0.1799668387323309 -0.2973467472915973
0.4932166845474547 0.4928094162538735
-0.3521487911717489 0.4352656197131292
-0.4907368011686362 0.1865826865533206
-0.1047924716070224 -0.247073392148198
0.4374961861758457 -0.001606279519951237
0.003256207800708899 -0.2729194320486108
0.04310378203457577 0.4452604050238248
0.4916198379282093 -0.345391701297268
0.001675087028811806 0.1531837672490476
-0.4404289572876217 -0.2894855991839297
0.3215348546593775 0.03629583077160248
0.02402358131857918 -0.2356728797179394
0.04590851212470659 -0.4156409924995536
0.3218384001607433 0.1379850698988746
0.11506479756447 -0.1059521474930943
0.2622539999543261 -0.29702873322836
-0.161920957418085 -0.4055339716426413
0.1905378631228002 0.3698601009043493
0.2387090918968516 -0.01629827079949742
0.07495888748668034 -0.1659825110491202
0.3319341836794598 -0.1821814101954749
0.07703635755650362 -0.2499430638271785
0.2069242999022122 -0.2232970760420869
0.04604079532068295 -0.1923573186549892
0.05054295812784038 0.4754929463150845
-0.3900589168910486 0.2797829520700341
0.3120693385713448 -0.0506329867529059
0.01138812723698857 0.4002504701728471
0.009645149586391732 0.1060251100976254
-0.03597933197019559 0.2953639456959105
0.1818290866742182 0.001454397571696298
0.444056063372694 0.2502497166863175
-0.05301752458607545 -0.06553921621808712
0.4823896228171788 -0.4776170002088109
-0.3089226845734964 -0.06356112199235814
-0.271780741188471 0.1810810595574612
0.4293626522918815 0.2980897964891882
-0.004796652127799228 0.382663812844701
0.430695573269106 -0.2995073500084759
0.1799668387323309 -0.2973467472915973
0.4932166845474547 0.4928094162538735
-0.3521487911717489 0.4352656197131292
-0.4907368011686362 0.1865826865533206
-0.1047924716070224 -0.247073392148198
0.4374961861758457 -0.001606279519951237
0.003256207800708899 -0.2729194320486108
0.04310378203457577 0.4452604050238248
0.4916198379282093 -0.345391701297268
0.001675087028811806 0.1531837672490476
-0.4404289572876217 -0.2894855991839297
6 changes: 3 additions & 3 deletions Problems/Problem_2/Prob_2.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
The Fibonacci series is an interesting series of numbers which are dependant on the past two values of the series, based on the recursive relation f(n) = f(n-1) + f(n-2).

As asking a question based on the fibonacci sequence would be boring and cliche, your task is to write a recursive code solving the recursive relation f(n) = f(n-1)^(n-1) + f(n-2)^(n-2).
The Fibonacci series is an interesting series of numbers which are dependant on the past two values of the series, based on the recursive relation f(n) = f(n-1) + f(n-2).
As asking a question based on the fibonacci sequence would be boring and cliche, your task is to write a recursive code solving the recursive relation f(n) = f(n-1)^(n-1) + f(n-2)^(n-2).
Binary file added Problems/Problem_2/a.out
Binary file not shown.
34 changes: 34 additions & 0 deletions Problems/Problem_2/prob2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int power(int a, int b)
{
int val=1;;
while(b!=0)
{
val=val*a;
b--;
}
return val;
}
int recurse(int n)
{
if(n==0)
{
return 0;
}
else if(n==1)
{
return 1;
}
else
{
return (power(recurse(n-1),n-1)+power(recurse(n-2),n-2));
}

}
void main(int argc,char** argv)
{
printf("%d\n",power(5,5));
printf("%d\n",recurse(atoi(argv[1])));
}
46 changes: 23 additions & 23 deletions Problems/Problem_2/problem_2.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include <stdio.h>
#include <math.h>

int fibonacci(int n){
if (n==1 || n==2){
return n-1;
}
else{
return pow(fibonacci(n-1),n-1) + pow(fibonacci(n-2),n-2);
}
}

int main(void){
int N;
printf("\nRecursive fibonacci relation = f(n) = f(n-1)^(n-1) + f(n-2)^(n-2)\n\n");
printf("Please enter a number (Nth term of the sequence): ");
scanf("%d", &N);
int result;
result = fibonacci(N);
printf("f(%d) = %d\n", N, result);

return 0;
}
#include <stdio.h>
#include <math.h>
int fibonacci(int n){
if (n==1 || n==2){
return n-1;
}
else{
return pow(fibonacci(n-1),n-1) + pow(fibonacci(n-2),n-2);
}
}
int main(void){
int N;
printf("\nRecursive fibonacci relation = f(n) = f(n-1)^(n-1) + f(n-2)^(n-2)\n\n");
printf("Please enter a number (Nth term of the sequence): ");
scanf("%d", &N);
int result;
result = fibonacci(N);
printf("f(%d) = %d\n", N, result);
return 0;
}
48 changes: 24 additions & 24 deletions Problems/Problem_2/problem_2.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 26 18:53:36 2019

@author: ANANTA SRIKAR
"""

def f(n):

if n == 1 or n == 2:
"""Assuming the first two values are same as that of fibonacci"""
return n-1
else:
return (f(n-1)**(n-1) + f(n-2)**(n-2))

def main():

print('f(n) = f(n-1)^(n-1) + f(n-2)^(n-2)')
n = int(input('Enter Nth term : '))
val = f(n)
print('f(' + str(n) + ') = ' + str(val))

if __name__ == '__main__':
main()
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 26 18:53:36 2019
@author: ANANTA SRIKAR
"""
def f(n):
if n == 1 or n == 2:
"""Assuming the first two values are same as that of fibonacci"""
return n-1
else:
return (f(n-1)**(n-1) + f(n-2)**(n-2))
def main():
print('f(n) = f(n-1)^(n-1) + f(n-2)^(n-2)')
n = int(input('Enter Nth term : '))
val = f(n)
print('f(' + str(n) + ') = ' + str(val))
if __name__ == '__main__':
main()

2 changes: 1 addition & 1 deletion Problems/Problem_3/Prob_3.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Find an efficient way to find the Nth prime in the series of natural numbers, Brute force will take you far but will it help if I asked you to find the 42,000th prime?
Find an efficient way to find the Nth prime in the series of natural numbers, Brute force will take you far but will it help if I asked you to find the 42,000th prime?
62 changes: 31 additions & 31 deletions Problems/Problem_3/Problem_3.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
def isPrime(n):
if n == 2:
return True

# Even numbers above 2 can't be prime
if n % 2 == 0:
return False

# All primes above 3 are neighbors of a multiple of 6
if n>3 and (n+1) % 6 != 0 and (n-1) % 6 != 0:
return False

# For the rest, we check up to sqrt(n) for factors
i = 3
while i*i <= n:
if n % i == 0:
return False
i+=2

return True

def main():
n = int(input())
p = 2
for i in range(n,0,-1):
while not isPrime(p):
p+=1
p+=1
print(str(n)+"th prime: "+str(p-1))

main()
def isPrime(n):
if n == 2:
return True
# Even numbers above 2 can't be prime
if n % 2 == 0:
return False
# All primes above 3 are neighbors of a multiple of 6
if n>3 and (n+1) % 6 != 0 and (n-1) % 6 != 0:
return False
# For the rest, we check up to sqrt(n) for factors
i = 3
while i*i <= n:
if n % i == 0:
return False
i+=2
return True
def main():
n = int(input())
p = 2
for i in range(n,0,-1):
while not isPrime(p):
p+=1
p+=1
print(str(n)+"th prime: "+str(p-1))
main()
6 changes: 3 additions & 3 deletions Problems/Problem_4/Problem_4.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Find the sum of the digits of 78!
(! is the factorial sign, meaning that you multiply all the numbers from 1 up till the number n.
EG; 4! = 4 x 3 x 2 x 1)
Find the sum of the digits of 78!
(! is the factorial sign, meaning that you multiply all the numbers from 1 up till the number n.
EG; 4! = 4 x 3 x 2 x 1)
36 changes: 36 additions & 0 deletions Problems/Problem_4/prblm4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<stdio.h>
#include<stdlib.h>

int fact(int n)
{
if(n==0)
{
return 1;
}
else if(n==1)
{
return 1;
}
else
{
return fact(n-1)*n;
}
}
int summed(int a)
{
int num = fact(a);
int d,sum=0;
while(num>0)
{
d=num%10;
sum=sum+d;
num=num/10;
}
return sum;

}
void main(int argc, char** argv)
{
printf("%d\n",fact(atoi(argv[1])));
printf("%d\n",summed(atoi(argv[1])));
}
Loading