Arbitrary permutation and combination script


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 06-18-2012
MySQL Arbitrary permutation and combination script

Code:
#!/bin/bash
# permutation_combination.sh

# Version: 2.0
# Author : YongYe <complex.invoke@gmail.com>

arg0=-1
argv=${3}
number=${2}
eval ary=({1..${1}})
length=${#ary[@]}
percom(){ nsloop i ${1} number${2} ${3} ${4} ${5}; }
invoke(){ echo $(percom ${argu} nsloop -1) prtcom $(percom ${argu}); }
permut(){ echo -n "${1} arg${i} ${2} "; (( ${#} != 0 )) && echo -n " length "; }
combin(){ (( ${#} != 0 )) && echo -n "${1} arg$((i+1)) arg${i} length " || echo -n "arg$((i+1)) "; }
prtcom(){ num=0; for i in ${@}; do echo -n ${ary[${!i}]}; (( ++num != number )) && echo -n .; done; echo; }

nsloop()
{ 
    local arc arg
    arg=${1//arg}
    for((${1}=${2}+1; ${1}<${3}; ++${1})); do 
         if [[ ${1//[0-9]} == arg ]]; then
               for((arc=1; arc!=arg; ++arc)); do
                    (( ${1} == arg${arc} )) && continue 2
               done
         fi
         eval eval \\\$\{{4..${#}}\}
    done
}

case ${3} in
     p) argu="-0 +1 permut" ;;
     c) argu="-1 +0 combin" ;; 
esac

$(invoke)

Invoke the script:
C 4 3
Code:
[root@node2 ~]# bash permutation_combination.sh 4 3 c
1.2.3
1.2.4
1.3.4
2.3.4

P 4 3
Code:
[root@node2 ~]# bash permutation_combination.sh 4 3 p | xargs -n 6
1.2.3 1.2.4 1.3.2 1.3.4 1.4.2 1.4.3
2.1.3 2.1.4 2.3.1 2.3.4 2.4.1 2.4.3
3.1.2 3.1.4 3.2.1 3.2.4 3.4.1 3.4.2
4.1.2 4.1.3 4.2.1 4.2.3 4.3.1 4.3.2

C 8 5
Code:
[root@node2 ~]# bash permutation_combination.sh 8 5 c | xargs -n 8
1.2.3.4.5 1.2.3.4.6 1.2.3.4.7 1.2.3.4.8 1.2.3.5.6 1.2.3.5.7 1.2.3.5.8 1.2.3.6.7
1.2.3.6.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2.5 3.1.4.5.2 3.1.5.2.4 3.1.5.4.2 3.2.1.4.5 3.2.1.5.4
3.2.4.1.5 3.2.4.5.1 3.2.5.1.4 3.2.5.4.1 3.4.1.2.5 3.4.1.5.2 3.4.2.1.5 3.4.2.5.1
3.4.5.1.2 3.4.5.2.1 3.5.1.2.4 3.5.1.4.2 3.5.2.1.4 3.5.2.4.1 3.5.4.1.2 3.5.4.2.1
4.1.2.3.5 4.1.2.5.3 4.1.3.2.5 4.1.3.5.2 4.1.5.2.3 4.1.5.3.2 4.2.1.3.5 4.2.1.5.3
4.2.3.1.5 4.2.3.5.1 4.2.5.1.3 4.2.5.3.1 4.3.1.2.5 4.3.1.5.2 4.3.2.1.5 4.3.2.5.1
4.3.5.1.2 4.3.5.2.1 4.5.1.2.3 4.5.1.3.2 4.5.2.1.3 4.5.2.3.1 4.5.3.1.2 4.5.3.2.1
5.1.2.3.4 5.1.2.4.3 5.1.3.2.4 5.1.3.4.2 5.1.4.2.3 5.1.4.3.2 5.2.1.3.4 5.2.1.4.3
5.2.3.1.4 5.2.3.4.1 5.2.4.1.3 5.2.4.3.1 5.3.1.2.4 5.3.1.4.2 5.3.2.1.4 5.3.2.4.1
5.3.4.1.2 5.3.4.2.1 5.4.1.2.3 5.4.1.3.2 5.4.2.1.3 5.4.2.3.1 5.4.3.1.2 5.4.3.2.1


Last edited by complex.invoke; 08-26-2012 at 03:52 AM..
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
PHP parametric + bash script combination baris35 Shell Programming and Scripting 6 07-06-2017 11:45 AM
Basic Combination Shell Script vespasian Shell Programming and Scripting 4 09-28-2016 02:43 AM
Permutation Words in awk watcherpro Shell Programming and Scripting 1 04-17-2016 10:22 PM
Combination of 6 nos gsiva Shell Programming and Scripting 3 02-25-2016 12:21 PM
Help with bash script to open arbitrary # of independent xterms smth333 Shell Programming and Scripting 3 09-05-2014 05:35 AM
6 digits combination Tzeronone Programming 6 05-15-2014 06:54 AM
[Solved] Permutation johnkim0806 Shell Programming and Scripting 2 01-18-2013 10:10 AM
Select combination unique using shell script osmanux Shell Programming and Scripting 4 01-09-2012 10:09 PM
Combination of numbers csierra Shell Programming and Scripting 7 02-14-2011 01:39 PM
Escape and combination Dedalus Shell Programming and Scripting 3 06-04-2010 11:44 AM
Combination of case and If else in shell script Pauline mugisha Shell Programming and Scripting 2 12-01-2009 01:06 AM
How To Analyze This (Cryptography Random?) Permutation...? lucky7 What is on Your Mind? 3 05-26-2009 12:46 PM
Combination backup/VI script cbo0485 Shell Programming and Scripting 3 01-22-2009 04:09 PM
Combination Of commands rahulrathod UNIX for Dummies Questions & Answers 2 12-14-2004 06:32 AM
Partition combination gardarm Filesystems, Disks and Memory 3 03-14-2002 06:35 PM