Tutorial 6-Competitive Programming-New Problem & Visualization Tool To Visualize Python Programming

preview_player
Показать описание
In this Video We will discuss a new problem statement and a visualization

Starter In Data Science

1 Complete Machine Learning Playlist:(Top 24 videos)

2 Statistics in Machine Learning:(Understand some Concepts With Respect To Data)- Complete Playlist

3. Feature Engineering(Complete Playlist)

4. Continue The Complete Machine Learning Playlist(24-all the videos)

5. Live Stream Playlist:(Top 10 videos)

6. Machine Learning Pipelines

7. Complete Deep Learning Playlist:

8. Live Projects Playlist:
Рекомендации по теме
Комментарии
Автор

def append(a, l):
return [a+i for i in l]

def generate(n):
if n==0: return []

if n==1: return ['0', '1']

else:
return (append("0", generate(n-1)) + append("1", generate(n-1)))

def gen_bitsize(binary_output, n, bit_size):
if n < bit_size:
x=bit_size-n
a=''
for i in range(x):
a+="0"
result=[a+i for i in binary_output]
print(result)
else:
print("error")


n=int(input("Enter the Number to generate the bits"))
bit_size=int(input("select the size of each bit"))
binary_output=generate(n)
gen_bitsize(binary_output, n, bit_size)

suhassasetty
Автор

Again, I am sorry to ignore all the concepts behind the problem that Krish will explain later. But here is how I will done. Remember we were told to solve this problem, so I am using what i think will be easy for me.

But it works :D

def problem2(num, bits):
answer = str(bin(num).replace("0b", "").rjust(bits, '0'))
if(len(answer)==size):
return answer
else:
return "Error"

Great content Krish, I will be following your content for a long time thats for sure. Keep up the good work.

ravisoni
Автор

This really handy those who preparing for competive exams..Thanks Krish for sharing

rajathrshettigar
Автор

def gen_binary(num, bits):
binary, out = bin(num)[2:], ""
if bits < len(binary): return -1

out += ('0' * (bits - len(binary)) + binary)

return out

NOTE : For binary conversion you may write your own function. I just used this inbuilt bin() function.

abhishekdobliyal
Автор

This is a hidden gem, totally amazing for recursion or DP problems.

hemanthsavasere
Автор

def bitRecur(n):
if n==1:
return "1"
if n==0:
return "0"
return bitRecur(n//2)+str(n%2)

def bitGen(n, size):
bits=bitRecur(n)
if size<len(bits):
raise Exception('specified bit length is too short')
else:
return ('0'*size+bits)[-size:]

bitGen(4, 6)

pankajkumarchoudhary
Автор

its very helpful to see how code really work in background. Thanks a lot.

ramdeoyadav
Автор

I have been using this tool for past two years ..Great to see it on your channel

deveshkumar
Автор

This visualisation in debugging is reducing bit complexity anna ..👌👌

lavanyabellamkonda
Автор

Hi Krish - Thanks for sharing knowledge.

karthikrams
Автор

Thanks so much for the amazing python visualization interface . It is of great use to test line by line execution . I tried not using any in-built command .

def binary(digits, bits):
if digits<0:
print("error)
else:
temp=digits
b=[]
while(temp>=1):
a=temp%2
temp=temp//2
b.append(a)
if(bits>=len(b)):
k=b[::-1]
to_add_zeros=bits-len(k)
if(to_add_zeros!=0):

print(modified_binary)
else:
modified_binary=k
print(modified_binary)
else:
print("It would require atleast "+str(len(b))+" bits to represent the number "+str(digits))

binary(8, 4)

My code can be optimally bad as I am new to programming but really great to think about each step and solve!.
It worked for all test cases .

harshavardhanasrinivasan
Автор

def binary(number, bits):
string = ''
while number > 0:
rem = number %2
string = str(rem) + string
number = number//2
length_str = len(string)
if bits >= length_str:
extra = bits - length_str
for i in range(extra):
string = '0' + string
return string
else:
return "Error message"


binary(7, 3)

srikanthsuroju
Автор

def gen_bin(number, bits):
if number < 2**bits:
print(gen_recursively(number, bits, bits, ''))
else:
print("number cant be expressed in "+str(bits)+" bits")


def gen_recursively(number, bits, level, strin):
if level==0:
return strin
return gen_recursively(number/2, bits, level-1, str(number%2)+strin)
gen_bin(5, 3)

handled the exception in gen_bin function and actual binary string is generated recursively

zuccerbot
Автор

This will work perfectly using recursion:



def bin(num, bit, ans, c):
if c==num:
if len(ans)>bit:
print('Not Possible')
else:
if len(ans)==bit:
print(ans)
else:
l=bit-len(ans)
print('0'*l+ans)
return
if c>num:
return
bin(num, bit, ans+'1', c*2+1)
bin(num, bit, ans+'0', c*2)



bin(13, 14, '1', 1) [pass number, bit number and rest will be same]

sujitkumar-prrr
Автор

You do great! Thanks for videos. Thats all helpful

random-yuhv
Автор

Sirji really so happy listing about this series ❤️ so much o want build my competative coding ❤️❤️❤️❤️❤️

nikhiljadhav
Автор

This video I had released near by 1year ago on my channel. And using this tool from a long time. 😎

AlokMishra_tech
Автор

here's the solution very similar to the last one.

def conv(num, bits):

if bits < len(bin(num).replace('0b', '')):
raise Exception("Sorry, the number of bits is less than the length of the binary output")
else:
s = '0'*(bits-len(bin(num).replace('0b', '')))

return (s + bin(num).replace('0b', ''))

theoutlet
Автор

def getFormattedBinary(number, position):
b = f"{number:b}"
if len(b)>position:
return -1
else:
return b.zfill(position)

cedriclebocq
Автор

Did he just gave me a shoutout??😂 Thanks man

souhardya