User Tools

Site Tools


sym:mo:mma-tricks

Mathematica Tricks

Sorting the elements of a list using the triple underscore pattern.

from <Power Programming with Mathematica: The Kernel> by D.B. Wagner.
sorter[{a___, b_, c_, d___} /; b > c] := sorter[{a, c, b, d}]
sorter[x_] := x
(* Usage Example: *)
sorter[{5, 2, 7, 1, 4}]
(* {1, 2, 4, 5, 7) *)
sym/mo/mma-tricks.txt · Last modified: 2024/04/13 01:01 by killianz

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki