forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jérôme Krell <[email protected]>
- Loading branch information
Showing
185 changed files
with
128,830 additions
and
86,755 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
def pascal_triangle( lineNumber ) : | ||
def pascal_triangle(lineNumber): | ||
list1 = list() | ||
list1.append([1]) | ||
i=1 | ||
while(i<=lineNumber): | ||
j=1 | ||
l=[] | ||
i = 1 | ||
while (i <= lineNumber): | ||
j = 1 | ||
l = [] | ||
l.append(1) | ||
while(j<i): | ||
|
||
l.append(list1[i-1][j]+list1[i-1][j-1]) | ||
j=j+1 | ||
while (j < i): | ||
l.append(list1[i - 1][j] + list1[i - 1][j - 1]) | ||
j = j + 1 | ||
l.append(1) | ||
list1.append(l) | ||
i=i+1 | ||
i = i + 1 | ||
return list1 | ||
|
||
def binomial_coef(n,k): | ||
pascalTriangle=pascal_triangle(n) | ||
return(pascalTriangle[n][k-1]) | ||
|
||
def binomial_coef(n, k): | ||
pascalTriangle = pascal_triangle(n) | ||
return (pascalTriangle[n][k - 1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
# It returns location of x in given array arr | ||
# if present, else returns -1 | ||
def binarySearch(arr, l, r, x): | ||
|
||
while l <= r: | ||
|
||
mid = l + (r - l)/2; | ||
|
||
def binarySearch(arr, l, r, x): | ||
while l <= r: | ||
|
||
mid = l + (r - l) / 2; | ||
|
||
# Check if x is present at mid | ||
if arr[mid] == x: | ||
return mid | ||
# If x is greater, ignore left half | ||
elif arr[mid] < x: | ||
if arr[mid] == x: | ||
return mid | ||
|
||
# If x is greater, ignore left half | ||
elif arr[mid] < x: | ||
l = mid + 1 | ||
|
||
# If x is smaller, ignore right half | ||
else: | ||
else: | ||
r = mid - 1 | ||
|
||
# If we reach here, then the element was not present | ||
return -1 | ||
|
||
|
||
|
||
# Main Function | ||
if __name__ == "__main__": | ||
# User input array | ||
print("Enter the array with comma separated in which element will be searched") | ||
arr = map(int,input().split(",")) | ||
x = int(input("Enter the element you want to search in given array")) | ||
|
||
# Function call | ||
result = binarySearch(arr, 0, len(arr)-1, x) | ||
|
||
if result != -1: | ||
print("Element is present at index {}".format(result)) | ||
else: | ||
print("Element is not present in array") | ||
# User input array | ||
print("Enter the array with comma separated in which element will be searched") | ||
arr = map(int, input().split(",")) | ||
x = int(input("Enter the element you want to search in given array")) | ||
|
||
# Function call | ||
result = binarySearch(arr, 0, len(arr) - 1, x) | ||
|
||
if result != -1: | ||
print("Element is present at index {}".format(result)) | ||
else: | ||
print("Element is not present in array") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.