There's a problem on this line: m--; for(i = 0; i < n; i++) { m[i]--; } You're decrementing m, but then go ahead and index it from 0 ... I guess you may end up messing up the heap structures. I managed to have your code valgrind error-free like...

python,python-3.x,syntax,operator-keyword,algebra

You can do as follows: if 0 <= number1 <= 9: print("x") else: print("y") ...

mysql,logging,grouping,algebra

You can use a SUM() function and CASE statement to count each message_type and do the math. SELECT DAY(date) as day, HOUR(date) as hour, SUM(CASE WHEN message_type = 1 THEN 1 ELSE 0 END) - SUM(CASE WHEN message_type = 2 THEN 1 ELSE 0 END) - SUM(CASE WHEN message_type =...

python,algorithm,primes,algebra

If we find an intermediate result that is congruent to 1 (modulo n) and such that the previous result x was not congruent to 1 or -1 (i.e. n-1) modulo n, then this number x is a nontrivial square root of 1 modulo n (i.e. a number x such that...

Like this: SQLFIDDLE set @curr_user = 1; set @maxid = (select max(u1.id) maxid from users u1); set @minid = (select min(u2.id) minid from users u2); set @next_user = (if(@curr_user = @maxid ,@minid ,@curr_user +1)); set @prev_user = (if(@curr_user = @minid ,@maxid ,@curr_user - 1)); SELECT t1.name as prevuser, t2.name as...

sql,group-by,sql-order-by,relational-database,algebra

Neither is possible in relational algebra but people have been creating some "extensions" for these operations (Note: in the original text, part of the text is written as subscript). GROUP BY, According to the book Fundamentals of Database Systems (Elmasri, Navathe 2011 6th ed): Another type of request that cannot...

c,cryptography,modulus,algebra

You can utilize the fact, that (N-1) % N == -1. Thus, (65536 * a) % 65537 == -a % 65537. Also, -a % 65537 == -a + 1 (mod 65536), when 0 is interpreted as 65536 uint16_t fastmod65537(uint16_t a, uint16_t b) { uint32_t c; uint16_t hi, lo; if (a...

java,math,complexity-theory,mathematical-optimization,algebra

Mathematically, this corresponds to finding all linear combinations of the kernel vectors using all possible sets of coefficients that are n-tuples mod p. It amounts to a matrix multiplication mod p between a p^n x n coefficient matrix and a n x m kernel matrix. The p^n x n matrix...

vb.net,visual-studio,variables,calculator,algebra

From what I understand, you want to solve for m. This means given a value for b and t, you want to find m. Algebraically: m = b/ (1-t) The above equation is what you need to put in your program. Be aware that t=1 will cause an error, so...

I could not find any math library that could do this in iOS Objective C. But I realized that coming up with the formula with the answer is easy with coding. Whenever there are many constants you can you create a new variable that includes all constants, and go on...

javascript,parsing,variables,algebra

Seems to be a complex problem... This is a solution for a simple relaxed version of your problem. Hope you can use some components of this. Constraints: answer for x should be integers between 0 and 1000 the left hand side of the expression should be proper javascript syntax var...

You are not using proper syntax for the repmat function In your example ,You need to create a matrix of size 4 x 3 using repmat Now a call to repmat(A,k,j) repeats matrix A k times along the first dimension (i.e vertically) and j times along the second dimension (i.e,...

Have a look if this one helps you: https://code.google.com/p/sympy/ SymPy is an open source Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in...

sql,database,algebra,relational

Your first query finds pizzas that does not cost more that $10 anywhere, or is not eaten by any people aged 24 or above, while your last query fins pizzas that is sold for less than $10 somewhere, or is eaten by some people below 24. These queries will give...

Difficult to answer at the rate you are editing but: m_angle = math.degrees(math.atan(float(thing.position()[1]-stuff.position()[1]) / float(thing.position()[0]-stuff.position()[0]))) the bit inside the atan is equivalent to something/(a-b) m_angle = math.degrees(math.atan(float(thing.position()[1]-stuff.position()[1]) / thing.position()[0]-stuff.position()[0])) the bit inside the atan is equivalent to (something/a)-b...

math,algebra,differential-equations

global halvingInterval = 43200 global startingInventory = 512 def boxInventory(boxNumber): currentInventory = startingInventory while(boxNumber > halvingInterval): currentInventory = currentInventory/2 boxNumber -= halvingInterval return currentInventory This code will take the box number. It will keep subtracting the halving interval until you get to the right inventory area, and then return the...

sql,database,algebra,relational,calculus

This is the translation to SQL for your formula that starts with {S|∃ D ∈ Doctor (∃ C ∈ Duty (D.Doc_id = C.Doc_id ^ (etc..) ) ) } SELECT * FROM S WHERE EXISTS (SELECT * FROM Doctor D WHERE EXISTS (SELECT * FROM Duty C WHERE (D.Doc_id = C.Doc_id)...

You can do this with the power of bitwise arithmetic: def switches(n, num=4): return [n & (2**i) > 0 for i in range(num)] This will return a list where each item is a boolean indicating whether that switch is pressed: >>> switches(10) [False, True, False, True] # a b c...

This is a double nested NOT EXISTS query (no really, that's what I've usually seen it called), and it is used specificially to answer this type of quesion, i.e., "Are there any x true for all y?" Here's MySQL's page on EXISTS and NOT EXISTS, which mentions this technique specifically....

If p is supposed to be the name of an equation, try adding eq. prefix before p. If p is a variable that the expression on the right should be equal to, then replace p with eq.equation1 and put -p on the right side.

c#,unity3d,linear-algebra,algebra

There is no built in way to solve equations in .NET. Symbolic equation parsing/solving is something for advanced math libraries (heck, it wasn't even in TI calculators until the TI-89). The following libraries may be of use: http://smartmathlibrary.codeplex.com/ http://mathnetnumerics.codeplex.com/...

for loop can be simplifed to x= (pow(3,n)-1)/2 I have double checked this here: http://www.wolframalpha.com/input/?i=sum+pow%283%2Ci%29+for+i+from+0+to+%28n-1%29...