Click here to Skip to main content
15,914,642 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionProving an algorithm wrong Pin
Member 1377958614-Apr-18 6:39
Member 1377958614-Apr-18 6:39 
AnswerRe: Proving an algorithm wrong Pin
Richard Andrew x6415-Apr-18 6:04
professionalRichard Andrew x6415-Apr-18 6:04 
GeneralRe: Proving an algorithm wrong Pin
Gerry Schmitz15-Apr-18 8:05
mveGerry Schmitz15-Apr-18 8:05 
GeneralRe: Proving an algorithm wrong Pin
Richard Andrew x6415-Apr-18 8:26
professionalRichard Andrew x6415-Apr-18 8:26 
GeneralRe: Proving an algorithm wrong Pin
Richard MacCutchan15-Apr-18 21:30
mveRichard MacCutchan15-Apr-18 21:30 
AnswerRe: Proving an algorithm wrong Pin
Jochen Arndt15-Apr-18 21:45
professionalJochen Arndt15-Apr-18 21:45 
GeneralRe: Proving an algorithm wrong Pin
Richard MacCutchan15-Apr-18 22:27
mveRichard MacCutchan15-Apr-18 22:27 
QuestionCan someone please help me optimize(decrease time complexity) this algorithm.. Pin
Member 137677177-Apr-18 10:37
Member 137677177-Apr-18 10:37 
C++
<pre>import timeit
start = timeit.default_timer()
import math



def fequals(a, b):
	return abs(a-b) < 0.0000001




def matmult(a,b):
    
	zip_b = list(zip(*b))
	return [[sum(ele_a*ele_b for ele_a, ele_b in zip(row_a, col_b)) 
	 for col_b in zip_b] for row_a in a]






def area(theta):
	r = [[math.cos(theta), -math.sin(theta), 0.0],
	[math.sin(theta), math.cos(theta), 0.0],
	[0.0, 0.0, 1.0]]
	
	v = [[1], [-1], [1]]
	
	point = matmult(r, v)
	return abs(point[0][0]*point[2][0])







def position(theta):
	r = [[math.cos(theta), -math.sin(theta), 0.0],
	[math.sin(theta), math.cos(theta), 0.0],
	[0.0, 0.0, 1.0]]
	
	c_o= [[0.5, 0.0, 0.0],
	[0.0, 0.5, 0.0],
	[0.0, 0.0, 0.5]]
	
	result = matmult(r, c_o)

	return(result)



def OptimizeTheta(A):
	if fequals(A, 1.0):
		return position(0.0)
	elif fequals(A, 1.414213):
		return position(math.pi / 4.0)
	l = 0.0
	m = math.pi / 4.0
	while True:
		mid = (l + m)/2.0
		a = area(mid)
		if fequals(A, a):
			return position(mid)
		if a < A:
			l = mid
		else:
			m = mid
	



t =int(input())
for i in range(t):
	A = float(input())
	cube = OptimizeTheta(A)
	print("Case #{}:".format(i+1))
	print(cube[0][0], cube[1][0], cube[2][0])

	print(cube[0][1], cube[1][1], cube[2][1])

	print(cube[0][2], cube[1][2], cube[2][2])


                                                                                                                                                                            #GHOST999



stop = timeit.default_timer()
execution_time = stop - start



Beyond value 1.41...
it becomes extremely inefficient..
appreciate any help..
AnswerRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
Patrice T7-Apr-18 20:15
mvePatrice T7-Apr-18 20:15 
QuestionRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
claymorehack18-May-18 3:38
claymorehack18-May-18 3:38 
AnswerRe: Can someone please help me optimize(decrease time complexity) this algorithm.. Pin
Richard MacCutchan18-May-18 5:59
mveRichard MacCutchan18-May-18 5:59 
QuestionAlgorithm for golf putting. Slope 1-4 degrees Pin
Member 1375000827-Mar-18 11:06
Member 1375000827-Mar-18 11:06 
AnswerRe: Algorithm for golf putting. Slope 1-4 degrees Pin
Gerry Schmitz2-Apr-18 6:01
mveGerry Schmitz2-Apr-18 6:01 
Questionrecursive algorithm Pin
Member 1374335523-Mar-18 7:00
Member 1374335523-Mar-18 7:00 
AnswerRe: recursive algorithm Pin
Gerry Schmitz23-Mar-18 12:00
mveGerry Schmitz23-Mar-18 12:00 
AnswerRe: recursive algorithm Pin
Peter_in_278023-Mar-18 14:53
professionalPeter_in_278023-Mar-18 14:53 
QuestionSquare root of positive integer using binary search. Pin
lnikon25-Feb-18 9:40
lnikon25-Feb-18 9:40 
GeneralRe: Square root of positive integer using binary search. Pin
harold aptroot25-Feb-18 10:29
harold aptroot25-Feb-18 10:29 
GeneralRe: Square root of positive integer using binary search. Pin
lnikon25-Feb-18 10:54
lnikon25-Feb-18 10:54 
AnswerRe: Square root of positive integer using binary search. Pin
Richard Deeming26-Feb-18 1:21
mveRichard Deeming26-Feb-18 1:21 
AnswerRe: Square root of positive integer using binary search. Pin
Patrice T7-Apr-18 21:01
mvePatrice T7-Apr-18 21:01 
Question3D Points to 2D Points Pin
Member 1368222216-Feb-18 15:34
Member 1368222216-Feb-18 15:34 
AnswerRe: 3D Points to 2D Points Pin
Ralf Meier17-Feb-18 0:35
mveRalf Meier17-Feb-18 0:35 
GeneralRe: 3D Points to 2D Points Pin
jschell17-Feb-18 11:41
jschell17-Feb-18 11:41 
GeneralRe: 3D Points to 2D Points Pin
Ralf Meier17-Feb-18 23:02
mveRalf Meier17-Feb-18 23:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.