in reply to sequence of positions to binary sequence
Update: This assumes that the largest index in @pos is the length of your @bin array, which would work if you only needed to test for true/false on the array, indeed if you only need to test true/false then the second loop is unneeded as undef and 0 are both false ;)perl -e' @pos=qw(2 4 6 9); $max=0; for (0..(@pos -1)){ $bin[$pos[$_]]=1; $max=$pos[$_] if $max<$pos[$_]; } for (0..$max){ $bin[$_]=0 unless $bin[$_]; } print "@bin\n";'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sequence of positions to binary sequence
by ELISHEVA (Prior) on Apr 16, 2009 at 09:16 UTC | |
by Utilitarian (Vicar) on Apr 16, 2009 at 10:42 UTC |