Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bb038c

Browse files
author
Amogh Singhal
authored
Merge pull request devAmoghS#11 from SyeedHasan/master
Adjacent Element Product
2 parents 2336082 + 144ab33 commit 6bb038c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

‎adjacentElementProduct.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#Given an array of integers,
2+
#find the pair of adjacent elements
3+
#that has the largest product and
4+
#return that product.
5+
6+
def adjacentElementsProduct(inputArray):
7+
8+
length = int(len(inputArray))
9+
10+
maxm = inputArray[0]*inputArray[1]
11+
product = 1
12+
for i in range(1, length-1):
13+
product = inputArray[i]*inputArray[i+1]
14+
15+
if product>maxm:
16+
maxm = product
17+
18+
return maxm
19+
20+
21+
# print(adjacentElementsProduct([3,6,7,5]))
22+
23+
print(adjacentElementsProduct([3, 6, -2, -5, 7, 3]))
24+
25+
#Alternate solution
26+
#return max([inputArray[i]*inputArray[i+1] for i in range(0, int(len(inputArray)-1))])
27+
28+
29+
30+
31+
32+
33+
34+

‎bresenham_line_algorithm.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
def lineGenerator(x1, y1, x2, y2):
2+
dx = x2 - x1
3+
dy = y2 - y1
4+
5+
slope = 2*dy - dx
6+
7+
x = x1
8+
y = y1
9+
while x < x2:
10+
11+
#Print current coordinates
12+
print(x, y)
13+
14+
#X increases any ways
15+
x+= 1
16+
17+
# 2dy is always added in the slope. Do it.
18+
slope += 2*dy
19+
#Check for the current slope
20+
if slope >= 0:
21+
y += 1
22+
slope -= 2 * (x2-x1)
23+
24+
elif slope <=0:
25+
#No changes are made.
26+
slope = slope
27+
28+
29+
lineGenerator(3, 2, 15, 5)
30+
31+
# if P1[0]==P2[0] and P1[1]==P2[1]:
32+
# return 0
33+
# #P1 is the point given. Initial point
34+
# #P2 is the point to reach. Final point
35+
# print(P1)
36+
# #Check if the point is above or below the line.
37+
# dx = P2[0]-P1[0]
38+
# dy = P2[1]-P1[0]
39+
40+
# di = 2*dy - dx
41+
42+
# currX = P1[0]
43+
# currY = P1[1]
44+
45+
# if di > 0:
46+
# P1 = (currX+1, currY+1)
47+
# else:
48+
# P1 = (currX+1, currY)
49+
50+
# return lineGenerator(P1, P2)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /