Skip to main content

New answers tagged

1 vote

Position and string patterns

...
E. Chan-López's user avatar
2 votes

Delete all strings that are prefixes of another string

...
E. Chan-López's user avatar
2 votes

Delete all strings that are prefixes of another string

...
eldo's user avatar
  • 81.2k
1 vote

Position and string patterns

...
eldo's user avatar
  • 81.2k
1 vote

How to compare and remove x-coordinates (and the associated y-coordinates) that are less than previous x-coordinates?

...
eldo's user avatar
  • 81.2k
0 votes

MatchQ returns False for a match for e1 ** e2 while matching both e1 and e2

Using RealValuedNumberQ (new in 13.3) MatchQ[(2 e1) ** (-2 e2), (k1_?RealValuedNumberQ x_) ** (k2_?RealValuedNumberQ y_)] True ...
eldo's user avatar
  • 81.2k
2 votes

Replace a column/row of a matrix under a condition by a random number

m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Using Cases ...
eldo's user avatar
  • 81.2k
1 vote

What is the correct pattern to DeleteCases from a list?

DeleteCases require a pattern to remove elements removes all elements of expr that match pattern. in your examples, ...
AsukaMinato's user avatar
  • 10.1k
1 vote

What is the correct pattern to DeleteCases from a list?

...
E. Chan-López's user avatar
1 vote

Replace elements that do not match a pattern

mat = {{0, a, b}, {c, 0, d}, {0, 0, e}}; A hash-free variant of E. Chan-López answer using SameAs (new in 13.1) ...
eldo's user avatar
  • 81.2k
1 vote

What is the correct pattern to DeleteCases from a list?

...
eldo's user avatar
  • 81.2k
1 vote

Replace elements that do not match a pattern

mat = {{0, a, b}, {c, 0, d}, {0, 0, e}}; Using ReplaceList: ...
E. Chan-López's user avatar
2 votes

Replace elements that do not match a pattern

mat = {{0, a, b}, {c, 0, d}, {0, 0, e}}; Using MapCases by Richard Hennigan (Wolfram Research) ...
eldo's user avatar
  • 81.2k
2 votes

Removing lists with zero at any position

Create and select tuples in one step with SelectTuples by Sander Huisman: ...
eldo's user avatar
  • 81.2k
4 votes

Create sublists whose totals exceed a certain threshold and that are as short as possible

split[lst_, th_] := Module[{t = 0}, Split[lst, Or[(t += #) <= th, t = 0] &]]; Examples: ...
kglr's user avatar
  • 399k
1 vote

Create sublists whose totals exceed a certain threshold and that are as short as possible

Other way with AppendTo : list = {2, 1, 8, 10, 1, 4, 4, 5, 3, 4, 4, 11, 12}; th = 10; t=s={};(AppendTo[t,#]; If[Total[t]>th,AppendTo[s,t]; t={}])&/@list;s ...
Reda.Kebbaj's user avatar
2 votes

Removing lists with zero at any position

list = Tuples[Range[-2, 2], 2]; Another way using GroupBy: ...
E. Chan-López's user avatar
1 vote

Is there a better way to " Select non self mapping elements from a list of rules"?

abc = {a -> a, b -> c, d -> d, e -> f}; Another way using GroupBy: ...
E. Chan-López's user avatar
1 vote

Find subsequences of consecutive integers inside a list

list = {3, 4, 5, 6, 7, 10, 11, 12, 15, 16, 17, 19, 20, 21, 22, 23, 24,42, 43, 44, 45, 46}; Using SequenceSplit and ...
E. Chan-López's user avatar
2 votes

Find subsequences of consecutive integers inside a list

list = {3, 4, 5, 6, 7, 10, 11, 12, 15, 16, 17, 19, 20, 21, 22, 23, 24, 42, 43, 44, 45, 46}; Using FindRanges by Jan Pöschko (Wolfram Research) ...
eldo's user avatar
  • 81.2k
1 vote

Create sublists whose totals exceed a certain threshold and that are as short as possible

list = {2, 1, 8, 10, 1, 4, 4, 5, 3, 4, 4, 11, 12}; th = 10; A more programmatic way to do it is the following: ...
E. Chan-López's user avatar
4 votes

Create sublists whose totals exceed a certain threshold and that are as short as possible

list = {2, 1, 8, 10, 1, 4, 4, 5, 3, 4, 4, 11, 12}; th = 10; f = SequenceCases[#, {a___, e_} /; ! Max@Accumulate@{a} > th :> {a, e}] &; f@list ...
vindobona's user avatar
  • 5,021
4 votes

Create sublists whose totals exceed a certain threshold and that are as short as possible

I may have misunderstood but this finds shortest subset satisfying constraint: ...
ubpdqn's user avatar
  • 62.8k
9 votes
Accepted

Create sublists whose totals exceed a certain threshold and that are as short as possible

Why not just use Most: ...
ydd's user avatar
  • 4,587
3 votes

Create sublists whose totals exceed a certain threshold and that are as short as possible

Assume what you want is just one instance of shortest consecutive sequence of the elements in the list. Then following pattern matching will help you: ...
A. Kato's user avatar
  • 1,460
3 votes

Is there a better way to " Select non self mapping elements from a list of rules"?

DeleteCases[abc, Rule[x_, x_]] {b -> c, e -> f}
A. Kato's user avatar
  • 1,460
3 votes

Is there a better way to " Select non self mapping elements from a list of rules"?

abc = {a -> a, b -> c, d -> d, e -> f}; Using Pick and UnsameQ ...
eldo's user avatar
  • 81.2k
3 votes

StringContainsQ, but anywhere in order

A variant of NewStringContainsQFunction using StringPosition: ...
E. Chan-López's user avatar
2 votes

StringContainsQ, but anywhere in order

c = Characters["aabbckkdf"]; s = Characters["acd"]; Using DeleteElements (new in 13.1) ...
eldo's user avatar
  • 81.2k

Top 50 recent answers are included