# algorithm

## Degenerate root finding problem: get the first value for which f(x)>0

Degenerate root finding problem: get the first value for which f(x)>0 Question: Given a function f(x) that is zero for all values x less than a critical value c, and non-zero for values x>c. I want to approximate the critical value c using an optimization method. Because the function f(x) is expensive, I want to …

## Mapping four string values to all different possibilities of two number ranges in a nested dictionary in python

Mapping four string values to all different possibilities of two number ranges in a nested dictionary in python Question: I have the following lists. In reality these lists are a lot bigger but I simplified for the example. d = ["a", "b", "c", "d"] p = [1,2,3,4] a = [1,2,3,4] I need to map the …

## A* algorithm in python having trouble with making the final path

A* algorithm in python having trouble with making the final path Question: Full now working Code: https://docs.google.com/document/d/1j1BLe4L735nmXWR0Vnj3TeHumzI5x7Ea5yWJSc5j-8w/edit I tried to code the A* pathfinding algorithm and I got it to expand in the right way using the g and h costs. It looked really cool, however when I tried finding the final path by using …

## Finding all possible sums of three integers within a list

Finding all possible sums of three integers within a list Question: I need to use a list of perfect cubes to find all possible sums of three different numbers within that list. The sum must also be a perfect cube. My original solution was to nest 3 for loops to cover each number, but this …

## Graph DFS – Confused about the return value of recursion

Graph DFS – Confused about the return value of recursion Question: I have a graph where a path from top-left cell – (0,0) to the bottom-right cell – (m-1,n-1) is valid if the difference between consecutive cells are less than or equal to "val". For instance, this example should return true for a val=2 because …

## Why do i get a list index out of range error with entries with a length of four digits?

Why do i get a list index out of range error with entries with a length of four digits? Question: I wrote this algorithm that returns the shortest sequence using operations to sort a list of numbers. is sorted by always reversing the order of the first n elements of the list and removing the …

## Searching for sequence of bits in an integer in Python

Searching for sequence of bits in an integer in Python Question: I have two integers, lets call them haystack and needle. I need to check that, if the binary representation of needle occurred in haystack [and OPTIONALLY find the position of the first occurrence] Example haystack = 0b10101111010110010101010101110 needle = 0b1011001 # occurred in position …

## ATM cash withdraw algorithm to distribute notes using \$20 and \$50 notes only

ATM cash withdraw algorithm to distribute notes using \$20 and \$50 notes only Question: I want to begin by acknowledging that I know there are a ton of similar questions in SO and other websites, but all proposed solutions seem to have the same problem for my specific example. Only using \$20 and \$50 notes, …