unity – Divide two quaternions evenly by a scalar to get a smooth rotation in-between

How do you divide two quaternions – say `A` and `B` – evenly by a scalar, to calculate the rotations between them to render a smoother rotation?

Effectively, say you want to smooth the rotations between `A` and `B`
evenly by `n`. How do you calculate each quaternion value between A and B?

I have found that resorting to `.eulerAngles` leads to some wild gimbal locking, so I think the math needs to stay in quaternion space…

python – Divide and Conquer Password Bruteforcer

My program brute-forces a password. The password is a string composed of a key and a four digit numeric code. The key is known so we are basically brute-forcing between 0000 through to 9999

An example password is:
`UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ 4143`

I updated that script I wrote to take advantage of multiprocessing in order to run faster.
The basic idea is to divide the task by the number of CPUs available.
There are two Events set up:

• `prnt_sig_found` is used by subprocesses to tell the parent if they succeed in guessing the right password.
• The parent process then uses `child_sig_term` to halt each subprocesses

My Python’s rusty and I think I made some bad choices. It would be useful to have my assumptions invalidated. 🙂

``````#!/usr/bin/env python
# coding: utf-8

import multiprocessing as mp
import socket
import time
import math
import sys
import os

class Connection:
def __init__(self, pin = 0, max_iter = 10000, sock = None):
print('initizializing socket instance ...')

self.pin = pin
self.max_iter = max_iter

self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

def p_name(self):
return mp.current_process().name

def connect(self, host='127.0.0.1', port=30002):
print(self.p_name(), 'connecting ...', host, port)
self.sock.connect((host, port))
print(self.p_name(), 'connection successful.')

def write(self, msg):
print(self.p_name(), 'sending', msg)
self.sock.sendall(msg)

print(self.p_name(), 'reading data ...')
data = self.sock.recv(4096)
return data

def close(self):
try:
self.sock.shutdown(0)
self.sock.close()
except:
pass

def execute(self, child_sig_term, prnt_sig_found):
start_time = time.time()
print(self.p_name(), 'executing ...')

self.connect()

self.write('greetings !')
print(welcome_str)

while self.pin < self.max_iter:
if child_sig_term.is_set():
break

pin_str = str(self.pin).zfill(4)
message = self.password + " " + pin_str + "n" # add newline char to flush message or it doesn't get sent

self.write(message.encode())

if 'Wrong' in received_msg:
print(self.p_name(), 'Wrong guess %s', pin_str)
else:
prnt_sig_found.set()
break

self.pin += 1
time.sleep(0.5)

end_time = time.time()
total_time = end_time - start_time
print(self.p_name(), "start: "+str(self.pin), ' end: '+str(self.max_iter), 'total_time: ', str((total_time)/60) + ' minutes')

def main():
print('main')

connections = ()
processes = ()

prnt_sig_found = mp.Event()
child_sig_term = mp.Event()

MAX_ITER_COUNT = 10000
processor_count = mp.cpu_count()

step_count = int(math.floor(MAX_ITER_COUNT / processor_count)) # math.floor returns a float in python 2
end = step_count
start = 0

print('Initial values ->', processor_count, step_count, start, end)

try:
for i in range(processor_count):
conn = Connection(pin = start, max_iter = end)
proc_name = 'BF( ' + str(start) + ' - ' + str(end) + ' )'

process = mp.Process(name=proc_name, target=conn.execute, args=(child_sig_term, prnt_sig_found))
process.daemon = True

connections.append(conn)
processes.append(process)

start = end + 1
end += start + step_count

# ensure start and end don't exceed max
if MAX_ITER_COUNT < end  : end = MAX_ITER_COUNT
if MAX_ITER_COUNT < start: start = MAX_ITER_COUNT

# start all processes
for process in processes:
process.start()

# wait for all processes to finish
# block the main program until these processes are finished
for process in processes:
process.join()

prnt_sig_found.wait()
child_sig_term.set()

except:
pass

finally:
for conn in connections:
conn.close()

for process in processes:
if process.is_alive():
process.terminate()

if __name__ == '__main__':
main()
``````

c++ – Divide and conquer solution for finding the majority element in the given input

I am using a divide and conquer strategy to solve the majority problem. An element in said to be in the majority if repeats more than n/2 times where n is the number of elements given in the input.
Return 1 if a majority element in present, return 0 otherwise.

This is the algorithm that I am using:-
->We will keep dividing the array into half until we reach an array of size two and we will compare the two elements of each array.
->If they are the same, they are the majority element of that array and we will return their value. ->If they are not the same, we will return a special character to signify that there is no majority element.
->Moving recursively up the arrays, we will check the values we get from the two child-arrays/halves. As with the base case above, if the elements are the same, we return them, otherwise we return the special character(special character is -1 in the code below).

``````//Function to count the number of occurences of an element in the input in linear time
ll simple_count(vector<ll>&v,ll p){
ll count = 0;
for(ll i=0;i<v.size();i++){
if(v(i)==p)
count++;
}
return count;
}
//Function to find the majority element using the above algorithm
ll majorityElement(vector<ll>&v,ll left, ll right){
if(left==right)
return v(left);
if(left+1==right){
if(v(left)==v(right))
return v(left);
return -1;
}
ll mid = left+(right-left)/2;
ll p = majorityElement(v,left,mid);
ll q = majorityElement(v,mid+1,right);
if(p!=-1&&q==-1)
{
if(simple_count(v,p)>((ll)v.size()/2))
return p;
return -1;
}
else if(p==-1&&q!=-1)
{
if(simple_count(v,q)>((ll)v.size()/2))
{
return q;
}
return -1;
}
else if(p!=-1&&q!=-1){
ll p_count = simple_count(v,p);
ll q_count = simple_count(v,q);
if(p_count>q_count&&p_count>v.size()/2)
return p;
else if(q_count>p_count&&q_count>v.size()/2)
return q;
return -1;
}
else if(p==q&&p!=-1)
{
if(simple_count(v,p)>(ll)v.size()/2)
return p;
return -1;
}
else if(p==q)
return -1;
}
int main(){
ll n;
cin>>n;
vector<ll>v(n);
for(ll i=0;i<n;i++)
cin>>v(i);
ll k = majorityElement(v,0,v.size()-1);
if(k==-1)
cout<<0;
else
cout<<1;
return 0;
}
``````

The problem I am facing is that this code is giving me Time Limit Exceeded(TLE) error for a few inputs(Coursera grader does not share the inputs for which we get an error) I believe the time complexity of my code is O(nlogn). Please help me optimize the code so that this program does not give me TLE.

algorithms – Divide first n square numbers 1^3, 2^3, … n^3 into two groups such that absolute difference of the sum of the two groups is minimum

Starboy, that one is actually obvious. You take my answer on your previous question, just using $$n^3$$ instead of $$n^2$$. You write a little program to find all the sums that you can produce using a subset of the first n cubes, until you find an n where these sums contain a consecutive sequence of $$(n+1)^3$$ numbers, and then you follow the same arguments.

I’m sure you can do that yourself without any further help.

sql server – What is the best way to divide data for random groups?

I would like to have persisted column which will randomly group data for 32 groups according to one of `varchar` key column in table. My idea was:

`SELECT ABS(CAST(HASHBYTES('MD5',(keyColumnFromTable)) AS bigint) % 31)`

Questions:

1. There is any better way to do this except `CHECKSUM` (different values on differents `COLLATE`) and own functions ?
2. There will be any difference If i will use `SELECT CAST(HASHBYTES('MD5',(keyColumnFromTable)) AS tinyint) % 31` ? I was reading that `CAST` to `tinyint` is taking into consideration last byte of data. Will be any affectt on randomness ?

algorithms – Divide first n square numbers 1^2, 2^2, ……. n^2 into two groups such that absolute difference of the sum of the two groups is minimum

lets say Given input is n = 6
My task is to divide {1, 4, 9, 16, 25, 36} into two groups and PRINT these two groups

Possible Solution 1: dividing groups as {1, 9, 36} and {4, 16, 25} which gives abs diff as abs(46 – 45) = 1. So the minimum difference is 1 and the two groups are {1, 9, 36} and {4, 16, 25}

Possible Solution 2: Another Possible Solution is dividing groups as {9, 36} and {1, 4, 16, 25} which gives abs diff as abs(45 – 46) = 1. So the minimum difference is 1 and the two groups are {9, 36} and {1, 4, 16, 25}.

If there are multiple solutions we can print any one.
Iam trying to solve it using https://www.geeksforgeeks.org/divide-1-n-two-groups-minimum-sum-difference/ but its not working.

permutation – How to divide a list into several single loops

Because of some problems, I need to divide the permutation represented by a list into several single loop lists.

For example, for list `{4, 3, 2, 1, 7, 6, 5}`, it can be divided into two single loops `{4, 3, 2, 1}` and `{ 7, 6, 5}`, where `{4, 3, 2, 1}` and `{ 7, 6, 5}` are continuous single loops (the single cycle in the positive direction and the single cycle in the opposite direction all meet the requirements).

``````PermutationCycles({4, 3, 2, 1, 7, 6, 5})
``````

But the results of the above code do not meet the requirements, what should I do to achieve this requirement delicately?

Other examples for testing:

``````{3, 2, 1, 7, 6, 4, 5}
(*{{3,2,1},{7,6},{4,5}}*)
``````

Divide a list of points into clusters based on the gap between them

This gets you four clusters with points grouped together in `ccmp`. The two large islands are depicted in orange and blue, the small long island in green, and a tiny island in red.

``````nng = NearestNeighborGraph(data, 8);
ccmp = ConnectedComponents(nng);
ListPointPlot3D(ccmp)

(* Length@ccmp == 4 *)
``````

Writing a program that divide numbers until I hit a one digit number

Well, I have the following question:

How can I write a program such that an input number $$n$$ is divided by the number $$k$$ as long as the resulting number does not have one digit, if the resulting number is not an integer we need to take the floor-function of the fraction. Then I need to count how many divisions it took to do that.

Example:

When I have the number $$n=100$$ and $$k=2$$. Now divide the number by $$2$$ to get $$n/k=50$$, that is not a one digit number so we divide by $$2$$ again and get $$n/(2k)=25$$, still not a one digit number so divide by $$2$$ again $$n/(3k)=12.5$$ which is not an integer so we need to take the floor function $$lfloor12.5rfloor=12$$ now divide by $$2$$ again and get $$6$$ which is a one digit number so we stop. The number of divisions is: $$4$$.

microsoft word – How can I divide a matrix into several parts using the eqarray command?

Good morning, I am trying to incorporate the following expression using the equation tools in Word.

Thanks to the valuable answer I received in this space I was able to use the command eqarray and raise it using the Word equation tools following the code

eqarray(Δu_t=&I_t “(” -0.070&+&0.381Δu_(t-1)&+&0.345Δu_(t-2)&+&0.126Δu_(t-3)&+&0.084Δu_(t-4)&-&0.148Δu_(t-12) “)” &+(1-I_t )&”(” -0.004&-&0.039Δu_(t-1)&+&0.122Δu_(t-2)&+&0.179Δu_(t-3)&+&0.159Δu_(t-4)&-&0.126Δu_(t-12) “)” @&(-3.28)&&(3.84)&&(5.22)&&(1.90)&&(1.25)&&(-2.08)&&(-0.47)&&(-0.57)&&(2.48)&&(3.73)&&(3.35)&&(-3.09))here

Whose result, in the form of an equation is

The problem is that, since it is a matrix of equations, the expression is long and is outside the margins of the document. I wanted to know if there is any way to divide it into several parts, adjust it into more lines or express it in such a way that it remains as it is recorded in the text from which the image was obtained. I appreciate the information!