39 votes
Accepted

3D tree in Mathematica?

First, an idomatic, but slow version. ...
Henrik Schumacher's user avatar
20 votes
Accepted

How to fill a grid make its total be largest

Below is given a solution derived with ILP combinatorial optimization: The total of the assigned values to the $5 \times 5$ table is $61$. I called in the comments this approach to be "brute force" ...
Anton Antonov's user avatar
19 votes
Accepted

Solving "Resistance between two nodes on a grid" problem in Mathematica

In addition to Carl Woll's post: Computing the pseudoinverse of a the graph Laplacian matrix (a.k.a. the KirchhoffMatrix) is very expensive and in general leads to ...
Henrik Schumacher's user avatar
18 votes
Accepted

Image segmentation by pixel value

Update: If you want 4-neighborhood, you can use MorphologicalComponents to do most of the work, which is fast and easy to implement (that was my original attempt, ...
Niki Estner's user avatar
  • 36.1k
18 votes
Accepted

Quick QuickSort implementation

I also got angry about those randomly picked and ill-implemented benchmarks by the Julia team. I appreciate their efforts (jit compilers are useful), but the Fibonacci example was straight away ...
Henrik Schumacher's user avatar
16 votes

Solving "Resistance between two nodes on a grid" problem in Mathematica

Based on rcampion2012's answer to Efficient Implementation of Resistance Distance for graphs?, you could use: ...
Carl Woll's user avatar
  • 130k
16 votes
Accepted

The most efficient algorithm to find all possible integer pairs which sum to a given integer

I think IntegerPartitions[m, {2}, listOfIntegers] does exactly what you want, and seems pretty efficient.
Roman's user avatar
  • 46.9k
15 votes
Accepted

Visibility Polygon

Edit Test non-convex case. ...
cvgmt's user avatar
  • 69.7k
14 votes
Accepted

Why is SVM unable to separate linearly separable data?

It's not explicitly documented, but I think Mathematica is using the C-SVM variant, where a regularization parameter C basically says how "expensive" mislabeled training samples are, compared to the ...
Niki Estner's user avatar
  • 36.1k
14 votes

How can I get samples of f(x) that are roughly evenly spaced?

f[x_] := 1 - 8 x^2 + 8 x^4; You can use the option MeshFunctions -> {ArcLength} and ... 1. Specify the number of equal-arc-...
kglr's user avatar
  • 392k
13 votes
Accepted

Factor a polynomial Root into Roots of smallest possible degree

A constructive approach The problem can be solved if the form of the solution is given. Define the two factors using a hint (that these should be cubic equations) in the original post ...
yarchik's user avatar
  • 18k
13 votes

How can I get samples of f(x) that are roughly evenly spaced?

If we want to the ArcLength approximately equal to the dist = 0.15;, we can define an arclength function ...
cvgmt's user avatar
  • 69.7k
12 votes

How to implement QLearning?

Right now you can use MDPtoolbox via RLink. Reinforcement learning is expected in the next version of Mathematica. You can see this presentation from the Wolfram Conference 2015. A lot of interesting ...
Alexey Golyshev's user avatar
11 votes

Given a large binary matrix, find the largest submatrix containing non-zero elements

Because you want to minimize the number of elements removed, a natural way to do this is with constrained optimization functions like Minimize and ...
unlikely's user avatar
  • 7,103
11 votes

Creating unique keys from list

Clear[f] f[_] = 0; (f[#] = f[#] + 1; {f[#], #}) & /@ list ...
C. E.'s user avatar
  • 70.4k
11 votes

Algorithm too slow

You could use FrobeniusSolve for this: Table[ Length @ FrobeniusSolve[{1,2,5,10}, i], {i,10} ] {1, 2, 2, 3, 4, 5, 6,...
Carl Woll's user avatar
  • 130k
11 votes
Accepted

Algorithm too slow

Looks like you are describing the classic problem of counting the number of ways to make change, given coins of value 1, 2, 5, and 10. Generating functions can count the ways. ...
KennyColnago's user avatar
  • 15.2k
11 votes

How to calculate the "center" point

The median is known to be more robust against outliers than the mean: ...
Henrik Schumacher's user avatar
11 votes
Accepted

Fast method to calculating signature of a matrix

SeedRandom[1]; H = RandomReal[{-1, 1}, {100, 100}] // (# + #\[ConjugateTranspose]) &; Short[H, 3] ...
SnzFor16Min's user avatar
  • 2,190
11 votes
Accepted

Accumulate up and down

accumulateUpDown := Module[{ud = {0, 0}}, Map[ud[[1 + Boole[# >= 0]]] += # &]] accumulateUpDown @ dt == res True <...
kglr's user avatar
  • 392k
10 votes

Finding all elements within a certain range in a sorted list

Assuming that you are interested in multiple different windows for the same list, then the following approach will be much faster than the other answers. Basically, compute a ...
Carl Woll's user avatar
  • 130k
10 votes

Image segmentation by pixel value

Almost,for your example three: ...
yode's user avatar
  • 26.5k
10 votes
Accepted

From a list of lists of integer, choose a minimal length list of integers that intersects each sublist

LinearProgramming By enumerating your lists and associating each element of Union @@ data with set of indices of lists that contain this element, you can translate ...
jkuczm's user avatar
  • 15.1k
10 votes

3D tree in Mathematica?

Slow version ...
chyanog's user avatar
  • 15.4k
10 votes
Accepted

Which algorithm does Mathematica use for "RandomSearch"?

According to section "Random Search" in this guide, NMinimize with method RandomSearch scatters points randomly over the search ...
Henrik Schumacher's user avatar
10 votes

Is there a cyclic list manipulate function?

Square brackets are only used for functions ...
Bob Hanlon's user avatar
  • 155k
10 votes

What's wrong with this FFT-based Von Kármán vortex street simulation?

I found the index should start from 0 instead of 1. This affects the (squared) wave number k....
rnotlnglgq's user avatar
  • 3,740
10 votes

Smooth a list of integer values

The following can be shortened: ...
JimB's user avatar
  • 41.2k
9 votes

How to implement the sample-point process like the built-ins of Mathematica?

Being highly astonished about all the very interesting answers, I only want to add an approach using NMinimize. Not very fast, but straightforward. The idea behind ...
Ulrich Neumann's user avatar
9 votes

Factor a polynomial Root into Roots of smallest possible degree

I'll show the resultant formulation for the degree 15 example. The polynomial in question: ...
Daniel Lichtblau's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible