Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ass #1 (11 May 2020) and Ass #2 (12 May 2020) #132

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
Binary file added 15 May 2020/Q1_15_05_2020 - Output.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions 15 May 2020/Q1_15_05_2020.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include<vector>
#include<iostream>
using namespace std;
int run =0;

class team{
public :

int run = 0;
int ball=0,input,count=0;
vector<int> m1({-2,-1,0,1,2,3,4,5,6});

int SuperOver(){
while(ball<6){
cin>>input;
if(input == (-2))
ball++;
else if(input == (-1))
run++;

else if(input == 0)
ball++;

else if(input == (1)){
run++;
ball++;
}

else if(input == 2){
run+=2;
ball++;
}
else if(input == 3){
run+=3;
ball++;
}

else if(input == 4){
run+=4;
ball++;
}
else if(input == 5){
run+=4;
ball++;
}
else if(input == 6){
run+=6;
ball++;
}

else
cout<<"Envalid Entry"<<endl;
}
cout<<"Total Run : "<<run<<endl;
cout<<"Ball : "<<ball<<endl;
}
};
int main(){
vector<int> m1({-2,-1,0,1,2,3,4,5,6});
team Team1 , Team2;
cout<<"Team1 :: Bowling and Team2 :: Batting "<<endl;
Team1.SuperOver();
cout<<"Team2 :: Bowling and Team1 :: Batting "<<endl;
Team2.SuperOver();

if(Team1.run<Team2.run){
cout<<"Team2 Win The Match "<<endl;
}
else if (Team2.run<Team1.run){
cout<<"Team1 Win The Match "<<endl;
}
else
cout<<"Match Tie "<<endl;


}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Mohammad Farukh/11 May 2020/Q1_11 May 2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def findSingleOne(arr, n):
temp = arr[0]
for i in range(1,n):
temp = temp^arr[i]

return temp


# creating an empty list
arr = []

# number of elemetns as input
n = int(input("Enter number of elements : "))

# Input from the user
print("Gives the Elements of Array")
for i in range(0, n):
ele = int(input())
arr.append(ele) # adding the element

# Printing That Element

print("Element that Occuring once is : ", findSingleOne(arr, len(arr)))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Mohammad Farukh/11 May 2020/Q2_11 May 2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def MinXorValue(arr,n):
# Sort the Given array for Finding the Minimum Values
arr.sort()

min_xor=999999
value = 0 # set a temporary Value


# here the Main Logic
for i in range(0, n - 1):
for j in range(i + 1, n - 1):
# update minimum xor value
val = arr[i] ^ arr[j]
min_xor = min(min_xor, val)
return min_xor

return


# creating an empty list
arr = []

# number of elemetns as input
n = int(input("Enter number of elements : "))

# Input from the user
print("Gives the Elements of Array")
for i in range(0, n):
ele = int(input())
arr.append(ele) # adding the element

print("Minimun Xor value is : ",MinXorValue(arr,len(arr)))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions Mohammad Farukh/11 May 2020/Q3_11 May 2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def maxst(n):
temp = 0
while True:
if temp + 1 < n:
temp += 1
n = n - temp + 1
else:
break
return temp


i = int(input("Enter number"))
print("Number of staircase", maxst(i))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions Mohammad Farukh/11 May 2020/Q4_11 May 2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def path_of_grid(m):
ls = []
for i in range(m):
temp = []
for j in range(m):
temp.append(0)
ls.append(temp)
for i in range(m):
for j in range(m):
ls[i][0] = 1
if i >= j:
ls[i][j] = ls[i-1][j] + ls[i][j-1]
else:
break
return ls[-1][-1]


n = int(input("Enter array size:"))
print(path_of_grid(n) % (10 ^ 9 + 7))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions Mohammad Farukh/11 May 2020/Q5_11 May 2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def sqrtSearch(low, high, N):
# If the range is still valid
if (low <= high):

# Find the mid-value of the range
mid = (low + high) // 2;

# Base Case
if ((mid * mid <= N) and ((mid + 1) * (mid + 1) > N)):
return mid;

# Condition to check if the
# left search space is useless
elif (mid * mid < N):
return sqrtSearch(mid + 1, high, N);

else:
return sqrtSearch(low, mid - 1, N);

return low;


# Driver Code
if __name__ == "__main__":

N = float(input("Enter the Value to find the SqureRoot : "))
print(sqrtSearch(0, N, N))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Mohammad Farukh/12 May 2020/Q1_12_05_2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def prime(n):
if n>1:
for i in range(2,n//2):
if(n%i)==0:
return False
else:
return True
else:
return False


l= [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
n=3
m=4
count=0
for i in range(n):
for j in range(m):
sum=0
if 0<=i-1:
sum+=l[i-1][j]
if 0<=j-1:
sum+=+l[i][j-1]
if i+1<= n-1:
sum+=l[i+1][j]
if j+1<= m-1:
sum+=l[i][j+1]
#print(sum)
if prime(sum):
count+=1
print("Number of adjacent prime sum",count)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions Mohammad Farukh/12 May 2020/Q2_12_05_2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# The Main logic

def search(mat, n, x):
i = 0

# set indexes for top right element
j = n - 1
while (i < n and j >= 0):

if (mat[i][j] == x):
print(" n is Found at ", i, ", ", j)
return 1

if (mat[i][j] > x):
j -= 1


else:
i += 1

print("Element not found")
return 0



# Code for matrix input from user

N = int(input("Enter the number of rows:"))

# Initialize matrix
mat = []
print("Enter the entries rowwise:")

# For user input
for i in range(N): # A for loop for row entries
a = []
for j in range(N): # A for loop for column entries
a.append(int(input()))
mat.append(a)

# Input Element to be Search
Search = int(input("Enter the Element to Search:"))

# Call the Function
search(mat,N,Search)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions Mohammad Farukh/12 May 2020/Q3_12_05_2020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Code for matrix input from user

R = int(input("Enter the number of rows:"))
C = int(input("Enter the number of columns:"))

# Initialize matrix
matrix = []
print("Enter the entries rowwise:")

# For user input
for i in range(R): # A for loop for row entries
a = []
for j in range(C): # A for loop for column entries
a.append(int(input()))
matrix.append(a)
count =0
sum = 0

#logic is Here
for i in range(R):
for j in range(C):
if ((matrix[j][i]) == 1):
count = count + 1
if count % 2 == 1:
sum = sum + 1

print(sum)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Mohammad Farukh/13 May 2020/Q1_13_05_2020.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#include <iostream>
using namespace std;

// Area of triagle using : 1/2(h*b)
int Area(int height,int base){
return (height*base)/2;
}
// Area of triagle using : 1/2(a+b+c)
int Area(int a, int b, int c){
return (a+b+c)/2;
}
int main(){
cout<<"Area of Triangle 1/2(h*b) : "<<Area(12,9)<<endl;
cout<<"Area of Triangle 1/2(a+b+c): "<<Area(10,14,20)<<endl;

return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions Mohammad Farukh/13 May 2020/Q2_13_05_2020.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

/*
h1 = 4 meter 99cm
h2 = 5 meter 99 cm
98

h2 = h1+h2;

*/

#include <iostream>
using namespace std;
class height {
int meter,centimeter;

public:
void Entry(){
cout<< " Enter Meter : ";
cin>>meter;
cout<< " Enter Centimeter : ";
cin>>centimeter;
}
void show(){
cout << "Meter:" <<meter << "\t" << "Centimeter:" << centimeter << endl;

}
height operator +(height H){
height temp;
temp.meter = meter + H.meter;
temp.centimeter = centimeter + H.centimeter;
if(temp.centimeter >=100){
temp.centimeter%=100;
temp.meter++;
}
return temp;
}

};

int main(){

height H1,H2,H3;
H1.Entry();
cout<<endl;
H2.Entry();
cout<<endl;

H3 = H1+H2;

cout<<"Total : ";
H3.show();

return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading