Sunday 22 October 2017

Blog is Temporarily unavailable.



 The Blog has not been updated from very long and will not be done this semester. Apologies from the admin side. 
 

Saturday 16 September 2017

PPS 6


Practice Problems 6 Fall 17

1) Elizabeth visits her friend Andrew and then returns home by the same route. She always walks 2 kilometers per hour (km/h) when walking uphill, 6 km/h when walking downhill, and 4 km/h when walking on level ground. Suppose the path from Elizabeth's home to Andrew's home consists of 'x' meter in the level ground, 'y' meter in the uphill, 'z' meter in the  downhill and Elizabeth starts from home by 6 a.m.Write an algorithm and the subsequent Python code to determine when Elizabeth will reach Andrew's home and when she will reach her home back if she spends 'm1' minutes in Andrew's home. For example, if x is 1000, 'y' is 500, 'z' is 300  and m1 is '30' minutes, then Elizabeth takes 30 min to reach Andrew's home so she will reach Andrew's home by 6 hour 30 min. Elizabeth will take 26 min to walk from Andrew's home to her home and time when will reach her home back is 7 hour 26 min.

The hour can be expressed in 12-hour format (not 24-hour format).  The minutes elapsed should be rounded down to the nearest integer.

CODE:

x=float(input())
y=float(input())
z=float(input())
ml=float(input())
hr=6
def round2(n):
    if(n-round(n)>=0.5):
        return(round(n)+1)
    else:
        return(round(n))
tmin=round2(x/4*(18/(5*60)))+round2(y/2*(18/(5*60)))+round2(z/6*(18/(5*60)))
if(tmin<60):
    print(hr,' ',tmin)
else:
    hr=hr+tmin//60
    tmin=tmin%60
    print(hr,' ',tmin)
tmin2=tmin+ml+round2(x/4*(18/(5*60)))+round2(y/6*(18/(5*60)))+round2(z/2*(18/(5*60)))
if(tmin2<60):
    print(hr,' ',tmin2)
else:
    hr=int(hr+tmin2//60)
    tmin2=int(tmin2%60)
    print(hr,' ',tmin2)
___________________________________________________________
-----------------------------------------------------------------------------------------
2) CSE1701 Pengram (Id-3079)
Pengrams are words or sentences containing every letter of the English alphabet at the most once. Write an algorithm and  a subsequent Python code to check whether a string is a pengram or not. Write a function to check if a given string is a pengram. For example, "He is at work" is a pengram. Since every letter of the english alphabet occurs at the most once.
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)

def pengram(word):
 p=list(word)
 p=list(filter(lambda a: a != ' ', p))
 flag=0
 for i in p:
  if(p.count(i)>1):
   flag=1
   break
 if(flag==0):
  print('Pengram')
 else:
  print('Not pengram')

w=input().lower()
pengram(w)
________________________________________________
------------------------------------------------
3) CSE1701 Oddophic Numbers (Id-3086)
Given ‘n’ integers, write an algorithm and the subsequent Python code to print all numbers that are oddophic to the first number. Two numbers with non-distinct (numbers in which digits get repeated) digits are said to be oddophic if they have the same number of digits in it and the sets of positions having the same digits contains only odd positions. Positions of digits are numbered from left to right starting from 1.
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)

def same_pos(p):
 p=str(p)
 pos=[]
 for i in range(len(p)-1):
  for j in range(i+1,len(p)):
   if(p[i]==p[j]):
    pos.append(int(i)+1)
    pos.append(int(j)+1)
 return pos

def odd_list(p1):
 flag=1
 for i in p1:
  if(int(i)%2==0):
   flag=0
 return flag 

def oddo(num1,num2):
 f=0
 if(len(num1)==len(num2)):
  if(same_pos(num1)!=[] and same_pos(num2)!=[]):
   if(odd_list(same_pos(num1))==1 and odd_list(same_pos(num2))==1):
    f=1
 return(f)
 
n=int(input())
list_of_n=[]
print_list=[]
for i in range(n):
 list_of_n.append(int(input()))
flag=0 
for i in range(len(list_of_n)):
 if(oddo(str(list_of_n[0]),str(list_of_n[i]))==1):
  flag=1
  print_list.append(list_of_n[i])
if(flag==0):
 print('No oddophic')
else:
 for i in print_list:
  print(i)
______________________________________________________
------------------------------------------------------
4) CSE1701 Non-Isomorphic Numbers (Id-3084)
Given ‘n’ integers, write an algorithm and the subsequent Python code to print all numbers that are Non-isomorphic to the first number. Two numbers with non-distinct digits ( numbers in which digits are repeated)  are said to be non-isomorphic if they have the same number of digits in it and the sets of positions  having the same  digits are different. 
CODE:(Verified👍)

def same_pos(p):
 pos=[]
 for i in range(len(p)-1):
  for j in range(i+1,len(p)):
   if(p[i]==p[j]):
    pos.append((i,j))
 return pos

def same_list(p1,p2):
 flag=0
 if(p1!=p2):
  flag=1
 return flag

def non_iso(num1,num2):
 f=0
 if(len(num1)==len(num2)):
  if(same_pos(num1)!=[] and same_pos(num2)!=[]):
   if(same_list(same_pos(str(num1)),same_pos(str(num2)))==1):
    f=1
 return(f)
 
n=int(input())
list_of_n=[]
print_list=[]
for i in range(n):
 list_of_n.append(int(input()))
flag=0 
for i in range(len(list_of_n)):
 if(non_iso(str(list_of_n[0]),str(list_of_n[i]))==1):
  flag=1
  print_list.append(list_of_n[i])
if(flag==0):
 print('No non-isomorphic')
else:
 print(list_of_n[0])
 for i in print_list:
  print(i)
**************************************
Algorithm and Functions Used:
  • same_pos(p) : This function is defined to find the set of positions having same characters in a string 'p'. It returns a list.
  • same_list(p1,p2) : This function checks whether the set of positions in the two lists 'p1' and 'p2' are same or not.
______________________________________________________________
-----------------------------------------------------------------------------------------
5) CSE1701 Eve number (Id-3094)

A number ‘n’ is said to be an Eve number if the reverse of the square of the number ‘n’ is   not the square of the reverse of  ‘n’. For example, 15 is an Eve number.
Square of 15 = 225
Reverse of 15 = 51
Square of 51= 2601 which is not the reverse of square of 15
Write an Algorithm and the subsequent Python code to check whether the given number  is an Eve number or not.
Write a function to reverse a number
Input Format:
The first line will contain the number.
Output Format:
Print Eve number or Not an Eve number
*********************************************
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)
#Function to find the reverse of a number
def rev(n):
return(int(str(n)[::-1]))

n=int(input())
if(n<0):
print('Not an Eve number')
exit()
if(rev((n)**2)==(rev(n))**2):
print('Not an Eve number')
else:
print('Eve number')

Pseudo-Code:
def rev(n):
i=len(str(n))-1
s=0
while(n):
s+=(n%10)*(10)**i
n//=10
i-=1
return(s)

Processing:
1) Define the function to find the reverse of a number
2) Read the number 'n' as input
3) Find the square of the number and the square of the reverse of number
4) If square = square of reverse : print('Not an Eve number')
    else:
    print('Eve number')
___________________________________________________________
-----------------------------------------------------------------------------------------
6) CSE1701 Vowgram (Id-3080)
Vowgrams are words or sentences that has every vowel of  the English alphabet occurring  at least  once. Write an algorithm and  a subsequent Python code to check whether a string is a vowgram or not. Write a function to check if a given string is a vowgram. For example, "The quick brown fox jumps over the lazy dog" is a vowgram.
*********************************************
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)

def is_vogram(p):
 temp=0
 if(p.count('a')>=1 and p.count('e')>=1 and p.count('i')>=1 and p.count('o')>=1 and p.count('u')>=1):
  temp=1
 return temp

s=input().lower()
if(is_vogram(s)==1):
 print('Vowgram')
else:
 print('Not vowgram')
___________________________________________________________
-----------------------------------------------------------------------------------------
7) CSE1701 Automorphic Numbers (Id-3088)
Automorphic numbers are numbers having "n" digits such that the  last n digits of the square of the number will be the number itself. Write an algorithm and the subsequent Python code to check if the given number is automorphic. Write a function to find the square of a given number.. For example, 25 is a 2 digit automorphic number with a square of 625 and 376  with its  square  141376, is a 3 digit automorphic number.
*********************************************
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)
def sqr(n):
 return(n*n)

n=int(input())
c=sqr(n)
s=0
m=len(str(n))
L=len(str(n))
for i in range(L):
 s+=(c%10)*(10)**i
 m-=1
 c//=10
if(s==n):
 print('Automorphic')
else:
 print('Not automorphic')
___________________________________________________________
-------------------------------------------------------------------------------------
8) CSE1701 Heterosquare Numbers (Id-3089)
Heterosquare numbers are the numbers having "n" digits such that the  last n digits of the square of the number will not be the number itself. .Write an algorithm and the subsequent Python code to check if the given number is a Heterosquare number. Write a function to find the square of a given number. For example, 22 is a 2 digit heterosquare number with a square of 484 and 111 with its  square  12321, is a 3 digit heterosquare number.
*********************************************
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)

def sqr(n):
 return(n*n)

n=int(input())
c=sqr(n)
s=0
m=len(str(n))
L=len(str(n))
for i in range(L):
 s+=(c%10)*(10)**i
 m-=1
 c//=10
if(s==n):
 print('Not Heterosquare')
else:
 print('Heterosquare')
___________________________________________________________
-----------------------------------------------------------------------------------------
9) CSE1701 Vowelgram (Id-3081)
Vowelgrams are words or sentences that has every vowel (a,e,i,o,u)  of  the English alphabet occurring  at the most  once. Write an algorithm and  a subsequent Python code to check whether a string is a vowelgram or not. Write a function to check if a given string is a vowelgram. For example,”You black tiger" is a vowelgram.
Input format
First line contains the string to be checked
Output Format
Print Vowelgram or Not vowelgram
*********************************************
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)
def is_vowelgram(p):
temp=0
if(p.count('a')<=1 and p.count('e')<=1 and p.count('i')<=1 and p.count('o')<=1 and p.count('u')<=1):
temp=1
return temp

s=input().lower()
if(is_vowelgram(s)==1):
print('Vowelgram')
else:
print('Not vowelgram')

Pseudo-Code:
def is_vowelgram(p):
temp=0
if(p.count('a')<=1 and p.count('e')<=1 and p.count('i')<=1 and p.count('o')<=1 and p.count('u')<=1):
temp=1
return temp

Processing:
1) Define the function for a string to check whether it is vowelgram or not
2) Read the string
3) if(is_vowelgram(string)==1):
       print('Vowelgram')
     else:
       print('Not vowelgram')
___________________________________________________________
-----------------------------------------------------------------------------------------

10) CSE1701 Autocube Numbers (Id-3090)
Autocube numbers are numbers having "n" digits such that the  last n digits of the cube  of the number will be the number itself. Write an algorithm and the subsequent Python code to check if the given number is autocube. Write a function to find the cube of a given number.. For example, 25 is a 2 digit autocube number with a cube  of 15625 and 376  with its  cube  53157376, is a 3 digit autocube number.
Input Format
First line contains the number to be checked
Output Format
Print Autocube or Not autocube
*********************************************
CODE:(Verified👍)
(If you have problem understanding the indentation, click to download the code as text file.)
def cube(n):
return(n*n*n)

n=int(input())
c=cube(n)
s=0
m=len(str(n))
L=len(str(n))
for i in range(L):
s+=(c%10)*(10)**i
m-=1
c//=10
if(s==n):
print('Autocube')
else:
print('Not autocube')
___________________________________________________________
-----------------------------------------------------------------------------------------
11) CSE1701 Reverseadam number (Id-3097)
A number 'n' is said to be a Reversedam number if the number is divisible by its reverse.
CODE:(Verified👍)

#Function to find the reverse of a number
def rev(num):
new=0
while(num):
f=len(str(num))
new=new+(num%10)*10**(f-1)
f-=1
num=num//10
return new

n=int(input())
r=rev(n)
if(n%r==0):
print('Reverseadam number')
else:
print('Not a reverseadam number')
___________________________________________________________
---------------------------------------------------------------------------------------
12CSE1701 Consogram (Id-3082)
Consograms are words or sentences that has every consonant( letters other than a,e,i,o,u) of the English alphabet occurring at least once. Write an algorithm and a subsequent Python code to check whether a string is a consogram or not. Write a function to check if a given string is a consogram. For example,”"The quick brown fox jumps over the lazy dog"" is a consogram.

CODE:(Verified👍)

def cons(sen):
 sen=list(filter(lambda a: a != ' ', sen))
 q=['q','w','r','t','y','p','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
 flag=1
 for i in q:
  if(sen.count(i)<1):
   flag=0
 if(flag==1):
  print('Consogram')
 else:
  print('Not consogram')

sen=input().lower()
cons(sen)
___________________________________________________________
------------------------------------------------------------------------------------
13) CSE1701 Diffadam number (Id-3095)
⁠⁠[00:44, 9/17/2017] +91 93936 25566: ⁠⁠⁠A number ‘n’ is said to be a Diffadam number if the absolute value of the difference between the number ‘n’ and the reverse of ‘n’ is zero. For example, 121 is Diffadam number. Reverse of a number is the number got by writing the digits of the number in the reverse order (from right to left). Reverse of 132 is 231. Write an Algorithm and the subsequent Python code to check whether the given number is a Diffadam number or not. Write a function to reverse a number Input Format: The first line will contain the number. Output Format: Print Diffadam number or Not a Diffadam number
CODE:(Verified👍)

def rev(n):
 return(int(str(n)[::-1]))
 
def diffadam(num):
 if(num==rev(num)):
  print('Diffadam number')
 else:
  print('Not a Diffadam number')
  
n=int(input())
diffadam(n)
_________________________________________________________
-----------------------------------------------------------------------------------------
14) CSE1701 Adam number1 (Id-3093)
A number is said to be an Adam number if the reverse of the square of the number is equal to the square of the reverse of the number.  For example, 12 is an Adam number because the reverse of the square of 12 is the reverse of 144, which is 441, and the square of the reverse of 12 is the square of 21, which is also 441.
Write an Algorithm and the subsequent Python code to check whether the given number  is an Adam number or not.
Write a function to reverse a number
CODE:(Verified👍)
def rev(n):
 return(int(str(n)[::-1]))
 
def adam(num):
 if(rev(num)**2==rev(num**2)):
  print('Adam number')
 else:
  print('Not an Adam number')
  
n=int(input())
adam(n)
_________________________________________________________

Wednesday 13 September 2017

INLAB 6

******************************************************************************************

Q.)

Given ‘n’ integers, write an algorithm and the subsequent Python code to print all numbers that are sum-equivalent to the first number. Two numbers  ‘m’ and ‘n’ are said to be sum-equivalent if  ‘m’ and ‘n’ have the same number of digits and the sum of the digits in ‘m’ and ‘n’ are equal.  12381 is sum-equivalent to 10545. Here both the numbers are five digit numbers. Sum of the digits in 12381 is 1+2+3+8+1=15. Similarly the sum of the digits in 10545 is 15.
Write a function to check whether two numbers are sum-equivalent or not. If none of the numbers are sum-equivalent then print ‘No sum-equivalent’.
Input Format
First line contains the number of elements, n
Next ‘n’ line contains the numbers
Output Format
Print first number in the first line
Next few lines contain the numbers that are sum-equivalent to first number.
If the none of the numbers are sum-equivalent , then Print “No sum-equivalent”
******************************************
Code: 
(Click Here:)


Processing:
1) Define a function to find the sum of digits of a number
2) Define a function to check whether two numbers are sum equivalent or not
3) Read the numbers
4) For all numbers check if they are sum equivalent to the first number.
5) Print the sum equivalent numbers
6) If the none of the numbers are sum-equivalent , then Print “No sum-equivalent”

Pseudo-Code:
def sum_digits(n):
s=0
while(n>0):
s = remainder(n,10)
n//=10
return s

def sum_eq(m,n):
temp=0
if(sum of digits of m = sum of digits of n):
temp=1
return temp

for i in range(1,n):
if(sum_eq(numbers[0],numbers[i])==1):
temp=1
print(numbers[i])
if(temp==0):
print('No sum-equivalent')

****************************************************************************