Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to combine and/or permute the words from a list up to 3 times. For example:

If I have one list with:

apple
orange
cafe

and another list with:

11
22
33

it should produce combinations like:

11appleorange22
33orange11cafe2211
orangecafe3333apple1133

The logic is the word from any list can be repeated up to 3 times, no more. But in any order and any permutation. How can I achieve this?

share|improve this question
    
Following your logic 112233112233112233appleorangecafeappleorangecafeappleorangecafe would be your longest combination from your example, right? –  nixda Jul 13 '13 at 13:50
    
right, exactly. –  FernandoSBS Jul 13 '13 at 13:53
    
@nixda where are you? –  FernandoSBS Jul 13 '13 at 14:15
    
Do you need a piece of software or could it be code? –  Andy Jul 13 '13 at 16:44
    
Need a piece of software. You know, I've tried googling for it for like 1 hour straight and can't believe that I couldn't find a program that do this that I want. there is a website which do almost it all (but only combine, no permute) but it limits the word count. So I believe it must be a local software. –  FernandoSBS Jul 13 '13 at 18:36

2 Answers 2

up vote 1 down vote accepted

command line, eq cat test test test|shuf|head -n 18|grep -v ^$|paste -s -d"\0":

powershell $r=New-Object Random;1..3^|%{gc test}^|select -f 18^|%{[array]$A+=$_};1..$A.Count^|%{$A[$r.Next(0,$A.Count-1)]}^|?{$_.Length -ne 0}^|%{$S+=$_};$S

cat test test test approximate correspondence `1..3^|%{gc test}

shuf approximate correspondence (powershell shuffle strings in pipe):

$r=New-Object Random; ... %{[array]$A+=$_};1..$A.Count^|%{$A[$r.Next(0,$A.Count-1)]}

head -n 18 approximate correspondence select -f 18

grep -v ^$ approximate correspondence ?{$_.Length -ne 0}

paste -s -d"\0" approximate correspondence %{$S+=$_};$S

when see command line:

cat test test test|shuf|head -n 18|grep -v ^$|paste -s -d"\0"

imagined the file type - test:

1
2
3
5

7
8

use file test:

apple
orange
cafe
11
22
33

shuffle1.ps1:

$r=New-Object Random;1..3|%{gc test}|select -f 18|%{[array]$A+=$_};1..$A.Count|%{$A[$r.Next(0,$A.Count-1)]}|?{$_.Length -ne 0}|%{$S+=$_};$S

For the purpose of generating text from templates are more suitable in another language.

It needs a specialist in Common Lisp and C. May be an expert Haskell.

If necessary mathematical symbolic computation then it is likely Maxima.

But you can always do whatever tools that are not designed for specific tasks ))).

It will be very nice if you describe your problem completely. Architecturally.

share|improve this answer
    
this all should be put in a powershell script? Does it output all the combinations? –  FernandoSBS Jul 14 '13 at 20:24
    
sorry but I don't understand your post, could you please explain each step better? –  FernandoSBS Jul 14 '13 at 21:53
    
i've forgot a password for a rar file and i'm trying to figure it out with the common words I use. –  FernandoSBS Jul 15 '13 at 2:25
1  
@FernandoSBS use Passware Kit Professional ... –  STTR Jul 15 '13 at 2:47
    
great program. Only drawback is that I can't make it use ONLY the words in a wordlist, since I must set the number of characters. –  FernandoSBS Jul 29 '13 at 11:44

If you have a Linux computer handy (or Mac OS X might do), create a file called test with this content:

apple
orange
cafe
11
22
33

followed by six empty lines. Then run this:

cat test test test|shuf|head -n 18|grep -v ^$|paste -s -d"\0"

cat concatenates the files, shuf shuffles the lines, head retrieves the first 18 lines (so you can have your maximum string), grep excludes empty lines and paste glues the line together.

EDIT: Sorry, only noticed the windows tag after posting. You can install Cygwin for this, but you might as well just take the principle and implement in something else.

share|improve this answer
    
any way to do it with powershell? also, what about the empty lines, if I have a 30 word list then I must put 30 empty lines in the end? –  FernandoSBS Jul 13 '13 at 23:33
    
Probably, but I wouldn't know how. You may be able to do it with Excel too (shuffle rows, transpose, merge). –  Paulo Almeida Jul 13 '13 at 23:39
    
Yes, with this method you would have to put as many empty lines at the end as you have words, but if you implement it in a different way you can have just the words and retrieve a random number of them. I just didn't know of any immediate way to do it on the command line. –  Paulo Almeida Jul 13 '13 at 23:43
    
ok so how to output it to a text file? –  FernandoSBS Jul 14 '13 at 0:09
    
On linux, redirect the output by appending "> filename" to the command. –  Paulo Almeida Jul 14 '13 at 0:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.