in reply to Re^4: keep track of array indexes
in thread keep track of array indexes

Nobody seemed to care, but words are not necessarily unique.

So instead of hashing one index we need to store an array of indices per word.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^6: keep track of array indexes
by choroba (Cardinal) on Jan 03, 2016 at 17:58 UTC
    Only a slight modification needed.
    #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use List::Util qw{ shuffle }; my @words = qw( this is a string with a word ); my @order = 0 .. $#words; my %ord; push @{ $ord{ $words[$_] } }, $_ for 0 .. $#words; # <-- Here... @words = shuffle(@words); @order = @ord{@words}; print do { local $" = "\t"; "@words\n" }; say join "\t", map "[@$_]", @order; @order = map shift @$_, @order; # <-- and here. say join ' ', map $words[$_], sort { $order[$a] <=> $order[$b] } @order;
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Of course, I had no doubt you know how to do it! ;)

      Just wanted to point out that the inverse of a function isn't necessarily a function again. :)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!