-
-
Notifications
You must be signed in to change notification settings - Fork 46.5k
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
Added largest_pow_of_two_le_num #9374
Added largest_pow_of_two_le_num #9374
Conversation
6925fa1
to
768e506
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def find(a):
if a<=0:
return 0;
for i in range(a+1):
if (2**i <= a):
c=i;
else :
return c;
b=int(input())
print(find(b))
this would be a simple and effective code i guess
16 0b10000 (Exit) | ||
""" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think we need so long one instead we can use
def find(a):
if a<=0:
return 0;
for i in range(a+1):
if (2**i <= a):
c=i;
else :
return c;
b=int(input())
print(find(b))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rahbdd thanks but there are a couple of issues with your suggestion
- It's actually not about the size of the code but how verbose yet briefly it explains the algo. The actual code I have written is in fact only 5 lines, rest is explanation.
- The syntax of your logic ??
- Your code is remarkably slow compared to the proposed solution. Check out this performance analysis.
I would suggest you to look at all the other algo's in the repository. The goal of the TheAlgorithms as described by their authors is to document model beautiful, helpful and interesting algorithms using code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you , I will try to modify it
DIRECTORY.md
Outdated
@@ -51,6 +51,7 @@ | |||
* [Index Of Rightmost Set Bit](bit_manipulation/index_of_rightmost_set_bit.py) | |||
* [Is Even](bit_manipulation/is_even.py) | |||
* [Is Power Of Two](bit_manipulation/is_power_of_two.py) | |||
* [Is Power Of Two](bit_manipulation/largest_pow_of_two_less_than_or_equal_to_a_number.py) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please DO NOT edit DIRECTORY.md
. We have a workflow to do this for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, I'll revert this change.
90e0c82
to
3bf61e7
Compare
3bf61e7
to
582ee5f
Compare
Describe your change:
Fixes #9347
Checklist: