Stack Overflow » Algorithm
94 FOLLOWERS
Read the most recent 30 Algorithm posts from Stack Overflow. The world's largest online community for developers, helping write the script of the future by serving developers and all technologists.
Stack Overflow » Algorithm
3h ago
I work for an airport, and my task is to calculate the taxiing routes for airplanes on taxiways, ensuring they follow the prescribed road sequence. Here, I'll give an example and would like to ask if there are any high-performance algorithms for calculating the shortest path while adhering to the specified route sequence, using Python.
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge("A1", "A2", weight=1, name="A")
G.add_edge("A2", "A3", weight=1, name="A")
G.add_edge("A3", "A4", weight=1, name="A")
G.add_edge("A4", "A5", weight=1, name="A")
G.add_edge("A5", "A ..read more
Stack Overflow » Algorithm
3h ago
How to solve this problem using 1 loop, charCodes, and 1 result array?
Emoji pattern :apple: (colon, no case-insensitive letters colon), with no spaces or other characters.
Usernames pattern <@username /> and are no case-insensitive
MAIN PROBLEM: I can store previous name, but if its a long chain of names??
If one user is immediately followed by another user, they form a group, and any subsequent emojis are shared among all users in that group. This means:
If a user (e.g., Max) does not have any valid emojis and is followed by another user (Kate) who does, then Max should inherit the emo ..read more
Stack Overflow » Algorithm
3h ago
i know the code for this is bad and not close to working but i dont know what to do at all im supposed to get the lowest value in the array and then swap it to the first spot and then get the second lowest and swap it to the next slot etc so just a sorting algorithm when i run it it just doesnt do what it should be and goes to an infinite or a very long loop inside of findloop
org 0x100
jmp start
array db 8, 3, 11, 19, 2, 6, 3
size db 7
start:
lea ax,array
xor cx,cx
mov cl, size
push cx
push ax
call SortArray
push cx
p ..read more
Stack Overflow » Algorithm
3h ago
here are they:
#define majority(a, b, c) _mm256_xor_si256(_mm256_xor_si256(_mm256_and_si256(a, b), _mm256_and_si256(b, c)), _mm256_and_si256(a, c))
#define choose(e, f, g) _mm256_xor_si256(_mm256_and_si256(e, f), _mm256_and_si256(_mm256_xor_si256(e, allones) , g))
#define ROR32_AVX(x, n) _mm256_or_si256(_mm256_srli_epi32((x), (n)), _mm256_slli_epi32((x), 32 - (n)))
#define sigma0(x) _mm256_xor_si256(_mm256_xor_si256(ROR32_AVX((x), 2), ROR32_AVX((x), 13)), ROR32_AVX((x), 22))
#define sigma1(x) _mm256_xor_si256(_mm256_xor_si256(ROR32_AVX((x), 6), ROR32_AVX((x), 11)), ROR32_AVX((x), 25))
#def ..read more
Stack Overflow » Algorithm
1d ago
I will need to obtain the coordinate based on the divide coefficient(or point number) e.g., 3 -> [0, 0.5, 1], 5 -> [0, 0.25, 0.5, 0.75, 1]...assume the result is single float the true situation might be like 10,000+.
My very naive solution is to generate the typical value into a data structure, and mostly we do the searching instead of calculate ..read more
Stack Overflow » Algorithm
1d ago
Link this is code project I was working on. I was making chart area to run sorting for each tab but it didn't work.
I wonder if this function is error or somethin
def run_sorting_algorithm(selected_algo, data, chart_area, thread_id):
global pause_event, stop_event
print(f"Running {selected_algo} on Tab {thread_id}")
# start_time = time.time()
sort_algorithms = {
"Merge Sort": lambda: merge_sort(data, 0, len(data) - 1, chart_area),
"Quick Sort": lambda: quick_sort(data, 0, len(data) - 1, chart_area),
"Selection Sort": lambda: selection_sort(data, chart_ ..read more
Stack Overflow » Algorithm
1d ago
Given a python list of lists containing numbers i.e lists = [ [1, 2], [2, 1], [3, 4] ], the problem is to return a list of all unique lists from the input list. A list is considered a duplicate if it can be generated from another list by reordering the items in the list. i.e [2, 1] is a duplicate of [1, 2]. Given the input [ [1, 2], [2, 1], [3, 4] ], the output should be [ [1, 2], [3, 4]] . Any reordering of [ [1, 2], [3, 4]] is also correct i.e [1, 2], [4, 3]],
My approach is to first sort all lists in the input list, convert the lists to tuples, use a set data structure to filter out duplica ..read more
Stack Overflow » Algorithm
1d ago
So, I have a subdivided icosahedron sphere (icosphere), and I am looping through its vertices and creating a logical tile-map of hexagons at the location of every vertex in the array. Basically, now I need to start detecting input on the tile-map, and looping through 10k tiles and doing a bounds check every time the user hovers a mouse over or clicks the sphere is way too computationally expensive.
I need a way to quickly and efficiently get the tile the user clicks/hovers over.
My current idea would be to create a 2D array of tiles (lat/lon), convert the tile's position to lat/lon values, and ..read more
Stack Overflow » Algorithm
1d ago
No compilation error, no logical error (I believe). But the thing is, there is no output at all! If you see my code, I set up test print statements at places, including one at the extreme beginning of main(), even that is not getting printed. I am clueless.
I would be glad if someone could help me figure out what's going on.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct process
{
int PID;
int AT; // arrival time
int BT; // burst time
int ST; // start time
int CT; // completion time
int TAT; // tur ..read more
Stack Overflow » Algorithm
1d ago
I want to solve the following problem:
Given an undirected graph G with positive integer weights, find maximum number of walks (each with different starting vertices) that ends at some specified vertex v, and the total number of times one travels through an edge in all these walks can't exceed the edge's weight. The time bound is O(m^2), where m is number of edges of G.
For example, if an edge has weight 2, then at most 2 different walks can use it as part of the walk. If a walk use this edge twice, then no other walks can use it. We can view it as decreasing the edge's weight by 1 every time ..read more