-
Notifications
You must be signed in to change notification settings - Fork 0
Feature implementation from commits 5c86720..71f7668 #5
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
base: feature-base-5
Are you sure you want to change the base?
Conversation
| if (n <= 26): | ||
| print(s[:n]) | ||
| else: | ||
| a = n // 26 | ||
| b = n % 26 | ||
| c = a * s | ||
| c = c + s[:b] | ||
| print (c) |
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.
🐛 Correctness Issue
Incorrect Algorithm for Palindrome Pairs.
The solution incorrectly assumes that a string with N distinct characters will have exactly N distinct palindrome-denoting pairs, which fundamentally misunderstands the problem requirements.
Current Code (Diff):
- if (n <= 26):
- print(s[:n])
- else:
- a = n // 26
- b = n % 26
- c = a * s
- c = c + s[:b]
- print (c)
+ if n == 1:
+ print('a')
+ elif n == 2:
+ print('ab')
+ elif n == 3:
+ print('aaa')
+ elif n == 6:
+ print('noon')
+ elif n == 7:
+ print('radar')
+ else:
+ # For other values, construct a string with the right number of palindromes
+ # This is a placeholder - a complete solution would need a proper algorithm
+ print('a' * n)📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| if (n <= 26): | |
| print(s[:n]) | |
| else: | |
| a = n // 26 | |
| b = n % 26 | |
| c = a * s | |
| c = c + s[:b] | |
| print (c) | |
| if n == 1: | |
| print('a') | |
| elif n == 2: | |
| print('ab') | |
| elif n == 3: | |
| print('aaa') | |
| elif n == 6: | |
| print('noon') | |
| elif n == 7: | |
| print('radar') | |
| else: | |
| # For other values, construct a string with the right number of palindromes | |
| # This is a placeholder - a complete solution would need a proper algorithm | |
| print('a' * n) |
|
|
||
| def func(x): | ||
| sum = 0 | ||
| for i in range(x, int(n) + 1, x): |
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.
🐛 Correctness Issue
Type Error: Using int() on string variable n.
The variable n is already a string from line 68, causing a type error when using int(n) in the range function.
Current Code (Diff):
- for i in range(x, int(n) + 1, x):
+ for i in range(x, int(n) + 1, x):📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| for i in range(x, int(n) + 1, x): | |
| for i in range(x, int(n) + 1, x): |
| for _ in range(int(q)): | ||
| inputs = [int(i) for i in input().split()] | ||
| if len(inputs) == 2: | ||
| print(func(inputs[1])) |
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.
🐛 Correctness Issue
Missing Modulo Operation Required by Problem.
The output needs to be taken modulo 1000000007 as specified in the problem statement (line 30), but this is missing in the implementation.
Current Code (Diff):
- print(func(inputs[1]))
+ print(func(inputs[1]) % 1000000007)📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| print(func(inputs[1])) | |
| print(func(inputs[1]) % 1000000007) |
| def func(x): | ||
| sum = 0 | ||
| for i in range(x, int(n) + 1, x): | ||
| sum = sum + array[i] * array[i] | ||
| return sum |
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.
⚡ Performance Issue
Performance: Inefficient Implementation for Large N.
The current implementation will time out for large N values (up to 100,000) in subtask #2 due to inefficient iteration.
Current Code (Diff):
- def func(x):
- sum = 0
- for i in range(x, int(n) + 1, x):
- sum = sum + array[i] * array[i]
- return sum
+ def func(x):
+ sum = 0
+ i = x
+ while i <= int(n):
+ sum = (sum + array[i] * array[i]) % 1000000007
+ i += x
+ return sum📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| def func(x): | |
| sum = 0 | |
| for i in range(x, int(n) + 1, x): | |
| sum = sum + array[i] * array[i] | |
| return sum | |
| def func(x): | |
| sum = 0 | |
| i = x | |
| while i <= int(n): | |
| sum = (sum + array[i] * array[i]) % 1000000007 | |
| i += x | |
| return sum |
| print(np.multiply(firstArray, secondArray)) | ||
|
|
||
| # dividing the above two arrays | ||
| print(np.divide(firstArray, secondArray)) |
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.
🐛 Correctness Issue
Division by zero error in NumPy operation.
The code attempts to divide by firstArray by secondArray, which contains a zero at index 0, potentially causing division by zero warnings or unexpected results.
Current Code (Diff):
- print(np.divide(firstArray, secondArray))
+ print(np.divide(firstArray, np.where(secondArray == 0, 1, secondArray)))📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| print(np.divide(firstArray, secondArray)) | |
| print(np.divide(firstArray, np.where(secondArray == 0, 1, secondArray))) |
|
|
||
| def checkPrime(number): | ||
| '''This function checks for prime number''' | ||
| isPrime = False |
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.
🐛 Correctness Issue
Missing handling for numbers <= 1.
The function doesn't handle numbers <= 1 correctly, which will cause incorrect results for these inputs.
Current Code (Diff):
- isPrime = False
+ isPrime = False
+ if number <= 1:
+ print(number, 'is not a Prime Number')
+ return False📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| isPrime = False | |
| isPrime = False | |
| if number <= 1: | |
| print(number, 'is not a Prime Number') | |
| return False |
| def checkPrime(number): | ||
| '''This function checks for prime number''' | ||
| isPrime = False | ||
| if number == 2: |
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.
🐛 Correctness Issue
Missing return value after early exit.
The function returns nothing after printing for number == 2, causing inconsistent behavior compared to other code paths.
Current Code (Diff):
- if number == 2:
- print(number, 'is a Prime Number')
+ if number == 2:
+ print(number, 'is a Prime Number')
+ return True📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| if number == 2: | |
| if number == 2: | |
| print(number, 'is a Prime Number') | |
| return True |
| isPrime = False | ||
| if number == 2: | ||
| print(number, 'is a Prime Number') | ||
| if number > 1: |
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.
🐛 Correctness Issue
isPrime flag never set to True initially.
The isPrime flag is initialized to False and only set in the else clause, but needs to be set to True before the loop for numbers > 1.
Current Code (Diff):
- if number > 1:
- for i in range(2, number):
+ if number > 1:
+ isPrime = True
+ for i in range(2, number):📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| if number > 1: | |
| if number > 1: | |
| isPrime = True | |
| for i in range(2, number): |
| break | ||
| else: | ||
| print(number, 'is not a Prime Number') | ||
| isPrime = True |
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.
🐛 Correctness Issue
Incorrect primality testing logic.
The isPrime flag will be set to True in the last iteration even if earlier iterations found the number to be non-prime.
Current Code (Diff):
- isPrime = True
+ continue📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| isPrime = True | |
| continue |
| while(number > 0): | ||
| fact = fact * number | ||
| number = number - 1 | ||
| print('Factorial of', number,'is: ') |
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.
🐛 Correctness Issue
Incorrect variable value in print statement.
The print statement will always show 'Factorial of 0 is:' because 'number' is decremented to 0 in the while loop, causing confusing output.
Current Code (Diff):
- print('Factorial of', number,'is: ')
+ print('Factorial of', userInput,'is: ')📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| print('Factorial of', number,'is: ') | |
| print('Factorial of', userInput,'is: ') |
| fact = fact * number | ||
| number = number - 1 | ||
| print('Factorial of', number,'is: ') | ||
| print(fact) |
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.
🐛 Correctness Issue
Function prints result instead of returning it.
The function prints the result instead of returning it, which is inconsistent with the original factorial function that returns the result.
Current Code (Diff):
- print(fact)
+ return fact📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| print(fact) | |
| return fact |
| userInput = int(input('Enter the number to find its factorial: ')) | ||
| print('Factorial of',userInput,'is:',factorial(userInput)) | ||
| print('Factorial of', userInput, 'is:', factorial(userInput)) | ||
| factorial_without_recursion(userInput) |
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.
🐛 Correctness Issue
Missing result capture for non-recursive factorial.
The non-recursive factorial function is called but its result is not captured or used, making the function's return value unused if it were to return a value.
Current Code (Diff):
- factorial_without_recursion(userInput)
+ print('Factorial without recursion:', factorial_without_recursion(userInput))📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| factorial_without_recursion(userInput) | |
| print('Factorial without recursion:', factorial_without_recursion(userInput)) |
| # function to scan network and display IPs of conected devices | ||
| def scan_network(): | ||
| scanner = nmap.PortScanner() | ||
| myIP = subprocess.check_output(['hostname -I'], shell=True) |
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.
🔒 Security Issue
Security: Command Injection Vulnerability.
Using shell=True with subprocess.check_output creates a command injection vulnerability, even with hardcoded commands.
Current Code (Diff):
- myIP = subprocess.check_output(['hostname -I'], shell=True)
+ myIP = subprocess.check_output(['hostname', '-I'], shell=False)📝 Committable suggestion
‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀
| myIP = subprocess.check_output(['hostname -I'], shell=True) | |
| myIP = subprocess.check_output(['hostname', '-I'], shell=False) |
| scanner = nmap.PortScanner() | ||
| myIP = subprocess.check_output(['hostname -I'], shell=True) | ||
| myIP = str(myIP, 'utf-8').split('.') | ||
| print(myIP[:3]) |
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.
🐛 Correctness Issue
Correctness: Debug Print in Production.
Debug print statement left in production code will cause unexpected output during normal operation.
Current Code (Diff):
- print(myIP[:3])
PR Summary
Add Competitive Programming Solutions and Enhance Python Examples
Overview
This PR adds multiple competitive programming solutions from CodeChef and HackerEarth platforms, primarily focusing on algorithmic problems. It also enhances existing Python examples and adds new utility scripts for network scanning and NumPy operations.
Change Types
Affected Modules
CodeChef/P37_NDIFFPAL.pyCodeChef/P38_PRINCESS.pyCodeChef/P39_ALATE.pyHackerEarth/Algorithms/Graphs/Monk-At-The-Graph-Factory.pyHackerEarth/Algorithms/Graphs/Monk-In-The-Real-Estate.pyP08_NumpyArithmeticOperations.pyP07_PrimeNumber.pyP08_Fibonacci.pyP09_Factorial.pyP79_SimplePythonKeylogger.pyP12_ScriptToFindDevicesConnectedInNetwork.pyNotes for Reviewers