40
votes
Accepted
How to implement the sample-point process like the built-ins of Mathematica?
Plot uses two different algorithms depending on whether PerformanceGoal is set to Quality or ...
38
votes
Accepted
37
votes
How to implement the sample-point process like the built-ins of Mathematica?
Wanna listen to a story? :)
It was around 2002 when I finally became fed up with ParametricPlot3D[] and its inability to adaptively plot space curves. Recall that ...
22
votes
Accepted
How to generate a blank crossword sheet?
One can use CellularAutomaton and apply only one rule: do not allow 4 white cells together!
...
21
votes
Accepted
Machine learning. SVM algorithm
As of Version 10 , Mathematica has a built in function Classify, which implements support vector machines and some other common machine learning algorithms.
...
21
votes
21
votes
Accepted
Faster position list construction from a "take instructions" list
My answer is based on a modification of a binary heap. Basically the construction looks something like this. We start with a binary tree:
Notice that if we label the nodes breadth-first, the labels ...
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" ...
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 ...
18
votes
Accepted
Efficient way to build a certain square matrix
Here's my take using NestList
cm[n_] := NestList[# + 1 &, Join[Range[n/2 + 1], Reverse@Range[n/2]], n - 1]
Then
...
18
votes
Accepted
Implement the Bisection algorithm elegantly and easily
1. Bisection algorithm
The algorithm itself is fairly straightforward and "fast" in some sense: the number of iterations is roughly Log2 of the ratio of the ...
18
votes
How to implement the sample-point process like the built-ins of Mathematica?
Earlier in the summer I had written the following for How to obtain adaptive sampling as in Plot function?. It is something like J. M.'s technique. But instead of a new version of Mathematica coming ...
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, ...
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 ...
17
votes
How to deal with recursion formula in Mathematica?
If you can rewrite the recursion to be tail recursive, you will not run into recursion limits.
Here is an example of a tail-recursive implementation of factorial.
...
17
votes
Faster position list construction from a "take instructions" list
Preface
Below, you will find two different solutions. For understanding the problem itself, the first, iterative solution is better suited since it gives insight in how the solution can be found ...
16
votes
Accepted
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:
...
15
votes
Accepted
Detecting patterns of black and white stones on a 2D board
One function comes to mind that already implements matching of multidimensonal rules: CellularAutomaton. Allow me to represent your board data like this:
...
15
votes
Accepted
Splitting strings into letter keys and integers
You asked for shortened, improved, so here it is using RegularExpressions:
...
15
votes
15
votes
Upper bound "Vicious nearest neighbour" algorithm suggestions
(Notebook: https://github.com/arnoudbuzing/rifleproblem)
OK, this is not a full blown solution (I can delete it when there is a real answer), but perhaps a useful tool to help others get a feel for ...
15
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.
14
votes
Accepted
Replace interior of matrix with zeros
Just another alternative.
x - ArrayPad[ArrayPad[x, -1], 1] // MatrixForm
14
votes
Accepted
How to deal with recursion formula in Mathematica?
A number of points:
First, if you need to compute several values of your sequence, your intial memo-ized implementation will NOT run into recursion limit problems.
Second, if you need to compute ...
14
votes
Match opening and closing parentheses?
This one returns the pairs in the order they get closed:
...
13
votes
Implementing an algorithm for finding the largest circle that contains a single point in a set (and no other point)
Here's a direct implementation of Rahul Narain's algorithm using Version 10 functions (no attempt has been made to optimize):
...
13
votes
Faster position list construction from a "take instructions" list
I have a tree-based method that has the right asymptotics but a very high coefficient. The upshot being, it will not compete with other methods until we get past 10^6 or so in list size. With ...
12
votes
Alternative ways to implement a triangular recursion
In this answer, I will use the Functional Paradigm to deal with triangular recursive formula in a uniform manner.
For the triangular recursive formula
$$T_k^{(n)}=f(T_{k-1}^{(n)},T_{k-1}^{(n+1)})$$
...
12
votes
Efficient way to build a certain square matrix
Edit: See end of post for latest performance enhancement.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
algorithm × 342graphs-and-networks × 45
list-manipulation × 39
performance-tuning × 35
matrix × 31
programming × 30
mathematical-optimization × 17
linear-algebra × 16
random × 16
graphics × 15
combinatorics × 15
image-processing × 12
geometry × 11
equation-solving × 10
computational-geometry × 10
recursion × 10
calculus-and-analysis × 9
functions × 9
number-theory × 9
plotting × 8
numerical-integration × 8
function-construction × 8
polynomials × 7
machine-learning × 6
code-request × 6