Questions tagged [Algorithms] (2080)

1
answer

How to find all local minima in the matrix?

Hello! There is a matrix of real nonnegative numbers about the size of 1000*1000. Essentially it is the value of some more or less smooth function of two variables. The task is to find all local minima of this function. Lows can be located on the borders of the matrix.
elbert asked April 4th 20 at 14:18
1
answer

How to solve a quadratic equation by the linear algorithm?

So, the crux of the issue: recently had a test in computer science, where my teacher said that it is impossible to solve a quadratic equation using a linear algorithm (i.e. without cycles and conditions). I was thinking, is it really all hopeless? About two days trying to think of something, but all attempts in vain.. maybe...
Lenna.Borer asked April 4th 20 at 14:13
3
answers

How to know whether password protected rar file?

Anyone has the experience of reading the header of rar files? Need to know, superimposed on the archive the password or not programmatically using Java.
Van.Kuhlman43 asked April 4th 20 at 14:02
3
answers

The task of the Olympics?

Peter decided to make mom a gift at a birthday celebration Breakfast. He decided to make a delicious tea and to bake pancakes. Unfortunately, although not outstanding culinary abilities, Peter could not keep up with the pancakes. Each of them turned out burnt on one side and undercooked on the other. As a result, Peti turne...
napoleon_Hessel52 asked April 4th 20 at 13:35
4
answers

How to count number of duplicate e-s in the array?

let arr = [1,3,3,4,5,5,5]; function count(arr){ let cnt = 1; let map = new Map(); for(let i = 0; i< arr.length; i++){ for(let j = 0; j< arr.length; j++){ if(arr[i] == arr[j]){ map.set(arr[i],cnt++); } } } return map; } console.log(count(arr)); // map should be {1 => 1, 3 => 2, 4 => 1, 5 => 3} , // bu...
brennan.Wilkins asked April 4th 20 at 13:30
2
answers

Why recursion persists?

Task Butterscotch weighs X grams, tangerine – Y gram, the carrot – Z grams. Need to write a program that determines how many different options of gifts weight exactly W grams can make Santa Claus. Input The only line of the input file INPUT.TXT contains four integers X, Y, Z and W (1 ≤ X, Y, Z ≤ 100, 1 ≤ W ≤ 1000). Output T...
westley_Rice asked April 4th 20 at 12:45
1
answer

Which algorithm to fetch data from a Python list?

Colleagues, tell me beginner about a possible algorithm to select(retrieve) data from a Python list, which can contain as dictionaries, tuples, lists,...) using a loop. I have a misunderstanding with reference to the attached structures, can not understand the principle of.... For example, there is such a list: s_list = [ ...
rahul.Harb asked April 4th 20 at 12:45
1
answer

How to optimize memory usage when working with class instances in Python?

I'm writing a game in which there are units. There is a Unit class, which is a repository of information about each individual unit. The class Unit now this structure:class Unit: def __init__(self, color, health): self.color = color self.health = health When you create a unit every time I create an instance of the Unit c...
shaylee.Hintz asked April 4th 20 at 12:45
1
answer

If a sorting option?

# sort the smallest element of the array #Define Nakanishi element of the array #and return its index array_example = [100,25,89,63] def find_small(arr): small = arr[0] # put in a variable the value of null array element count = 0 # variable which will store the smallest element of the array size = len(arr) # find ou...
Madyson.Aufderhar asked April 4th 20 at 12:37
1
answer

Is this binary search?

# Binary search def binary_search(list, item): low = 0 # the starting position of the list in which the search high = len(list) - 1 # position of the last element of the list while low <= high:# while the range is not narrowed that they will be equal mid = (low + high) # check the middle element guess = list[mid] ...
Florian40 asked April 4th 20 at 12:34