/* -*- gp-script -*- */ \\% Find permutation between vectors of numerical data \\ Author: Joerg Arndt \\ License: GPL version 3 or later \\ online at http://www.jjj.de/pari/ \\ version: 2014-October-16 (18:31) get_perm(a, b)= { /* Let a[], b[] be vectors that contain identical (but permuted) elements. */ /* Return the permutation as a vector (with lowest element zero). */ /* Example: get_perm([1,2,3],[2,1,3]) ==> [1, 0, 2] */ /* Example: get_perm([1,2,3],[2,1,777]) ==> 0 */ my(n, p, ta, tb, t); n = length(a); p = vector(n, j, -1); t = vector(n, j, 0); \\ tag array for (k=1, n, ta = a[k]; for (j=1, n, if ( 0==t[j], tb = b[j]; \\ if ( abs(ta-tb)