Skip to main content
14 votes

Position and string patterns

For large lists, this should be snappy: Pick[Range@Length@dat, StringTake[dat, UpTo@4], "star"] and actually, taking advantage of listability, ...
ciao's user avatar
  • 25.9k
13 votes
Accepted

Searching a phrase in all *.nb files

Here is a way to search from within mathematica: ...
george2079's user avatar
13 votes
Accepted

Position and string patterns

Position[dat, _String?(StringMatchQ[#, "star" ~~ ___] &)] or Position[dat, _String?(StringMatchQ[#, "star*"] &)] or ...
kglr's user avatar
  • 397k
12 votes

Implementing a Better Grep Command

Mathematica allows text searching using regular expressions (based on the PCRE library). It would take some work to re-implement the whole grep functionality within ...
Alexey Popkov's user avatar
11 votes
Accepted

Searching for an unordered triple in a list of triples

This seems to be a case for OrderlessPatternSequence tT = {{7, 1, 2}, {7, 2, 3}, {7, 3, 8}, {7, 1, 6}}; MemberQ[tT, {OrderlessPatternSequence[1, 2, 7]}] True ...
kglr's user avatar
  • 397k
10 votes

How can I implement my own documentation search function?

Update This code is no longer the most up-to-date. The properly up-to-date code is in the package on GitHub. For a run-down of the changes between this and that see the discussion between b3m2a1 and ...
b3m2a1's user avatar
  • 46.9k
10 votes
Accepted

Find elements of array with largest absolute value

You could use SparseArray to do this: ...
Carl Woll's user avatar
  • 131k
10 votes

How to find the position of the smaller element in the list?

Flatten @ Position[Less @@@ Transpose[{x, y}], True]
corey979's user avatar
  • 24k
10 votes
Accepted

How to find the position of the smaller element in the list?

Flatten@Position[Negative[x - y], True] Also possible: Flatten@Position[x - y, _?(# < 0 &)] or, as suggested by J.M.,...
anderstood's user avatar
  • 14.3k
9 votes

Basic Search Functionality

...
Conor's user avatar
  • 7,449
9 votes
Accepted

Basic Search Functionality

As of Mathematica 11: ...
C. E.'s user avatar
  • 70.8k
9 votes
Accepted

Working with deep lists

If there is no particular reason for using Outer, then this is simple and straightforward: ...
corey979's user avatar
  • 24k
9 votes
Accepted

How to cache results of WebImageSearch?

So it looks like the only real way to do this is by hacking the mainframe package that underlies this. Everything seems to be clumsy and hard coded, so I had to dig a little. The following works for ...
b3m2a1's user avatar
  • 46.9k
9 votes

How to find the position of the smaller element in the list?

PositionIndex[Sign[x - y]] @ -1 {2, 3, 6} Also PositionIndex[UnitStep[x - y]] @ 0 (* thanks: J.M. *) {2, 3, 6} ...
kglr's user avatar
  • 397k
8 votes

Find sublists in a list by contents, then union them

Flatten /@ Gather[groups, MemberQ[#1, b | g] && MemberQ[#2, b | g] &]
march's user avatar
  • 23.9k
8 votes
Accepted

Find sublists in a list by contents, then union them

Using rules: groups //. {a___, x : {___, b | g, ___}, b___, y : {___, b | g, ___}, c___} :> {a, Union[x, y], b, c} This behaves differently compared to your ...
C. E.'s user avatar
  • 70.8k
8 votes

Searching a phrase in all *.nb files

A couple of additional solutions. The first, with FindList, is probably the simplest and quickest. Using FindList ...
Anton Antonov's user avatar
8 votes
Accepted

Solving a rotating combination lock puzzle

I'd implement backtracking like this: ...
C. E.'s user avatar
  • 70.8k
7 votes

Searching a phrase in all *.nb files

Note: the following method isn't robust. See this answer of mine for a robust solution. Here is an approach which does not rely on the NBImport.exe (which actually performs importing of the NB files ...
Alexey Popkov's user avatar
7 votes

Working with deep lists

corey979's answer is simple and elegant for small numbers of values of x, a, and b. But if ...
Michael Seifert's user avatar
7 votes
Accepted

Obtaining the position in a list where the i^th element is bigger than the (i+1)^th element

A couple of these methods were incorrect, one terribly so. I believe they are now corrected. Here are some different ideas: ...
Mr.Wizard's user avatar
  • 272k
7 votes
Accepted

Find permutation index

I think you'll find this considerably more efficient than the accepted answer: ...
ciao's user avatar
  • 25.9k
7 votes

Implementing a Better Grep Command

Update As recommended in the comments by @b3m2a1, you can also use RunProcess as a simpler way to execute grep. You need to ...
Tim Laska's user avatar
  • 16.4k
7 votes
Accepted

How to test if $ⅈ$ is in an expression?

Look at the FullForm. This is what Mathematica actually sees. ...
b3m2a1's user avatar
  • 46.9k
7 votes
Accepted

Faster searching for subsets with pairwise conditions

Might be faster to cull as you go. I compile the selection function (possibly it can be made faster). Also I set the history length to zero although that does not help too much because the ...
Daniel Lichtblau's user avatar
7 votes
Accepted

Documentation Search : google-like (pokygon -> polygon)

The following is roughly what the documentation search appears to use: We first create an index: index = CreateSearchIndex["ExampleData/Text"] If we now ...
Lukas Lang's user avatar
  • 34.1k
6 votes

Working with deep lists

I think I would use Reap, Sow and Do for this problem. With these functions you can get the ...
m_goldberg's user avatar
  • 108k
6 votes

Is there a built-in function to do binary search?

It seems that since 2021 there is a ResourceFunction that does this. Example: ResourceFunction["BinarySearch"][{1, 2, 5, 5, 7, 12}, 6] I looked at the ...
userrandrand's user avatar
  • 5,937
6 votes

How can one efficiently find the (x,y) values of the rectangles that enclose a chosen % of nonrandom data points in mathematica?

...
george2079's user avatar
6 votes

Find elements of array with largest absolute value

Let h be the OP's H, to avoid single capital letters: ...
Michael E2's user avatar
  • 237k

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