Phone

+919997782184

Email

support@roboticswithpython.com

Geeks of Coding

Join us on Telegram

Week 12 Prof. Sudarshan Iyenger and Prof. Yayati Gupta NPTEL CS

Untitled1

Programming Exam 2

Prof. SRS is on a trip with a set of students of his course. He has taken several packets of candies to be distributed among the students. Unfortunately, the sizes of the packets are not the same and the professor would like to distribute the candies in an unbiased way. A solution is to open all the packets and move some candies from the larger packets to the smaller ones so that each packet contains equal number of candies. Your task is to determine the minimum number of such moves to ensure all packets have the same number of candies.

(One move indicates picking one candy from a packet and moving it to the other)

Input Format:

The first line of the input contains space separated integers indicating the sizes of each packet.

Output Format:

Display a single integer indicating the minimum number of moves required to equalize the size of each packet.

If it is not possible to equalize, display -1 as output.

Example:

Input:

1 1 1 1 6

Output:

4

Input:

3 4

Output:

-1

In [1]:
d=[int(i) for i in input().split()]
s=sum(d)
result=0
if s%len(d)==0:
  for i in range(len(d)):
    if d[i]<(s//len(d)):
      result=result+((s//len(d))-d[i])
  print(result,end='')
else:
  print('-1',end='')
1 1 1 1 6
4
Untitled3

The alphabets are enumerated as A = 0, B = 1, C = 2, … , Z = 25. Consider an encryption scheme where a character with value Ci in the plaintext is replaced by another character with value Cj using the formula Cj = (Ci + 5) % 26. After replacement, the resulting string is shuffled (permuted) at random to obtain the cipher text.

Given a plain text and a possible cipher text, your task is to determine whether the cipher text can be formed from the plain text using the above mentioned scheme.

(Assume that all the strings are in uppercase)

Input Format:

The first line of the input contains a string indicating the plain text.

The second line of the input a string indicating a possible cipher text

Output Format:

Display Yes or No (no newline after the output)

Example:

Input:

PYTHON TDMSUY

Output:

Yes

Input:

JOCPNPTEL JQYVSUTHO

Output:

No

In [4]:
s = input()
p = input()
#s = s[::-1]
t = ''
for c in s:
  t+=chr((ord(c)+5-ord('A'))%26 + ord('A'))
  

def removeSpaces(string): 
    string = string.replace(' ','') 
    string = string.replace(',','')
    return string.lower()
def check(t, p):
     
    # the sorted strings are checked 
    if(sorted(t)== sorted(p)):
        print("Yes",end='') 
    else:
        print("No",end='')         
         
check(t, p)
PYTHON
JOCPNPTEL
No
In [ ]:
 
Untitled

A box is placed at an orientation on the (0,0,0) point. Given other 3 points which are the endpoints. Find the volume of the box.

Input format:

line 1 – Point 1 coordinates

line 2 – Point 2 coordinates

line 3 – Point 3 coordinates

Output format:

Volume of the box

Example:

Input

2 2 -1

1 3 0

-1 1 4

Output

12

In [4]:
### NPTEL ACCEPTED INPUT

import numpy as np
p1=list(map(float,input().split()))
p2=list(map(float,input().split()))
p3=list(map(float,input().split()))
n_array = np.array([p1,p2,p3]) 
ans=abs(np.linalg.det(n_array))
g = float("{0:.1f}". format(ans))
print(g,end="")
2 2 -1
1 3 0
-1 1 4
12.0
In [3]:
### NPTEL ACCEPTED INPUT
import numpy as np

mat = [list(map(float,input().split())) for i in range(3)]

det = np.linalg.det(mat)

if (det)<0:
    det = (-1)*det
    print(det)
else:
    print(det)
Enter the entries row wise:
2
2
-1
1
3
0
-1
1
4
12.0
In [8]:
import numpy as np

entries = list(map(int, input().split()))
  
# For printing the matrix
matrix = np.array(entries).reshape(3, 3)
print(matrix)
det = np.linalg.det(matrix)
print(det)
2 2 -1 1 3 0 -1 1 4
[[ 2  2 -1]
 [ 1  3  0]
 [-1  1  4]]
12.0

Ramesh and Suresh have written GATE this year. They were not prepared for the exam. There were only multiple choice questions. There were 5 options for each question listed 1,2,3,4,5. There was only one valid answer. Each question carries 1 mark and no negative mark. Ramesh and Suresh are so sure that there is no question that both of them have answered correctly, i.e, one of them has given invalid answer.

Now Ramesh wants to know how well he has done the GATE. Given the answers of both Ramesh and Suresh, You should tell me what the maximum marks that Ramesh can get.

Input Format:

Line1 – Number of Questions in the GATE Exam

Line2 – List of Answers given by Ramesh(Answer no given then its represented by ‘.’)

Line3 – List of Answers given by Suresh (Answer no given then its represented by ‘.’)

Output Format:

Maximum score for Ramesh

Input:

6

1 2 3 4 5 1

1 2 2 2 5 1

Output

2

In [5]:
n=int(input())
R=input().split()
S=input().split()
score=0
for r in range(n):
  if R[r] not in S[r] and S[r] != "." and R[r] !=".":
    score+=1
print (score, end="")
6
1 2 3 4 5 1
1 2 2 2 5 1
2

Consider a triangle PQR, ∡PQR is 90o . X is the midpoint of the line PR. Given the input the lengths of PQ and QR find the angle ∡XQR.

Input Format:

Line 1 – Length of side PQ

Line 2 – Length of side PR

Output Format:

angle ∡XQR in degrees. Round to the nearest integer.

Example:

Input

10

10

Output

45

In [6]:
import math
pq=int(input())
pr=int(input())
qr=(pq*pq+pr*pr)**(0.5)
ans=math.asin(pq/qr)
print (round(math.degrees(ans)),end="")
10
10
45

Leave A Comment