Giter Site home page Giter Site logo

cp-2's People

Contributors

waghavi54321 avatar

Stargazers

 avatar

Watchers

 avatar

cp-2's Issues

Smith number problem

list1 = []
n = int(input("Enter the number :-"))
num = n
num1 = n

def prime(num):
    while num % 2 == 0:
        list1.append(2)
        num = num / 2

    for i in range(3, num + 1, 2):
        while num % i == 0:
            list1.append(i)
            num = num / i
    if num > 2:
        list1.append(num)

def sum_num(n):
    sum1 = 0
    while (n > 0):
        temp = n % 10
        n = n // 10
        sum1 += temp
    return (sum1)
sum3 = sum_num(n)
prime(num)
print(list1)
sum2 = 0
for i in list1:
    if i < 10:
        sum2 += i
    else:
        temp = sum_num(i)
        sum2 += temp
print(sum2)
if(sum3 == sum2):
    print(num1," is a smith num")
else:
    print(num1, " is not a smith num")
    
    
output********
Enter the number :-
22
22  is a smith num

** Process exited - Return Code: 0 **
Press Enter to exit terminal

Light more light

r = 6241
num_light  = 6241
bulb = "off"
for i in range(1,r+1):
    if(num_light%i == 0):
        if(bulb == "off"):
            bulb  = "on"
        elif(bulb == "on"):
            bulb = "off"
print(bulb)

Tower of hanoi

no_of_peg = int(input("Enter the number of Pegs: "))
no_of_balls = int(input("Enter the number of balls: "))
list_squares = []
output = []
for i in range(0, no_of_peg):
    temp = []
    output.append(temp)
for i in range(no_of_balls + 1):
    list_squares.append(i * i)
for j in range(1, no_of_balls + 1):
    for i in output:
        if len(i) == 0:
            i.append(j)
            break
        elif i[len(i)-1] + j in list_squares:
            i.append(j)
            break
print(output)

output***************************
C:\Users\HP\PycharmProjects\CompetetiveProgramming\venv\Scripts\python.exe "C:/Users/HP/PycharmProjects/CompetetiveProgramming/Infosys springboard/exercise 2 collections in python.py"
Enter the number of Pegs: 4
Enter the number of balls: 11
[[1, 3, 6, 10], [2, 7, 9], [4, 5, 11], [8]]

Process finished with exit code 0

4 prime number

num = int(input("Enter the number :- "))
list1 = []
def prime(num):
    if(num==2):
        return True
    for i in range(2,num):
        if num % i == 0:
            return False
        return True
for j in range(2,num):
    if(prime(j)):
        list1.append(j)
for i in list1:
    for j in list1:
        for k in list1:
            for l in list1:
                if(i+j+k+l == 18):
                    print("output :- ",i,j,k,l)
                    quit()
                    
     output*****
        
Enter the number :- 
18
output :-  2 2 3 11

CN CHECKSUM

n = "012FFA3BC09E45FA"
arr = []
temp = ""
count = 0
for i in n:
    temp = temp + i
    count = count + 1
    if(count%4==0):
        arr.append(temp)
        temp = ''
print(arr)
print("Question", arr)
output = bin(0)
for i in arr:
    res = "{0:04b}".format(int(i, 16))
    output = bin(int(output, 2) + int(res, 2))  # Passing the base value of 2 for binary to the int() function
    output = output[2:]
num = int(output, 2)
# convert int to hexadecimal
hex_num = format(num, 'x')
str1 = str(hex_num)
print("Answer = ", str1[-4:])
carry = str1[:len(str1) - 4]
print("carry = ", carry)
res1 = "{0:16b}".format(int(carry, 16))
res2 = "{0:16b}".format(int(str1[-4:], 16))
res3 = bin(int(res1, 2) + int(res2, 2))
res3 = res3[2:]
res4 = "{0:16b}".format(int(res3, 2))
str2 = ''
for i in res4:
    if i == '1':
        str2 += '0'
    else:
        str2 += '1'
num = int(str2, 2)
hex_num = format(num, 'x')
print("checksum required = ",str(hex_num))
########################################################output##########################################################
C:\Users\HP\PycharmProjects\CompetetiveProgramming\venv\Scripts\python.exe C:/Users/HP/PycharmProjects/CompetetiveProgramming/checksum.py
['012F', 'FA3B', 'C09E', '45FA']
Question ['012F', 'FA3B', 'C09E', '45FA']
Answer =  0202
carry =  2
checksum required =  fdfb

Process finished with exit code 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.