Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Create 'n' number random pairwise combination of words Post 303039576 by sammy777888 on Wednesday 9th of October 2019 10:16:23 PM
Old 10-09-2019
Create 'n' number random pairwise combination of words

File 1 contains the list of words that needed to be randomly paired:

Code:
Tiger
Cat 
Fish
Frog
Dog
Mouse
Elephant
Monkey

File 2 contains the pairs that should not be used (in any solution) during random pairing.

Code:
Elephant-Dog
Cat-Fish
Monkey-Frog

Dog-Elephant, Fish-Cat, Frog-Monkey should also be deleted as their pair appeared in File2 (irrespective to direction)
I need total 6 solutions and in every solution, there should be maximum of 5 pairs.
Tiger-Cat and Cat-Tiger should be treated as same and if they appear together in any solution one should be deleted.
Same pair such as Frog-Dog can be appear in many solutions.

The output looks like (here one one solution is given).

Code:
Tiger-Cat
Cat-Dog
Monkey-Cat
Frog-Dog
Elephant-Cat

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

create a Random passwd

Hello Everyone, I am wondering how to create a Random Password of 8 characters for a user. It has to be run in a script. Also, The user have to be asked to change his/her password the first time they login. I tried using genPass but seems like my system doesn't support that command. For... (1 Reply)
Discussion started by: bashirpopal
1 Replies

2. Programming

how to create random no between 10 to 40 in C

can any one tell me how to create integer random no between 10 to 40 in C language.When i m using random() or rand() functions they r creting some long int which is not required (5 Replies)
Discussion started by: useless79
5 Replies

3. UNIX for Dummies Questions & Answers

How to create all possible combination of lines?

Hi, I have a file where all the lines are sorted and uniq. A part of it looks like AAL AAR ABC ABE ABJ ABQ ABV ABZ ACC ACE ADA ADB ADD ADL AES (3 Replies)
Discussion started by: sickboy
3 Replies

4. Shell Programming and Scripting

search and replace combination of two words...with a constraint

Hi I have 100 files in my directory. Please help me how to do in Unix or any other scriptin lanuages. I want to replace all occurances of "goutham" to goutham_ind ONLY if the file contains the word "goutham" with the word "engineer"; for eg----test1 is a file contains the following inf; goutham... (6 Replies)
Discussion started by: nandugo1
6 Replies

5. Shell Programming and Scripting

Random pieces of number

Hello folks, i have number for example 10 and i want to divide into 4 random pieces that may be (6+2+1+1). How can i do this via script i have random number 234951 and i want to divide into 31 pieces. (6 Replies)
Discussion started by: learnbash
6 Replies

6. UNIX for Dummies Questions & Answers

random words

Hi there folks, for an exercise for my pupils (you know i am always thinking of them!) i need to randomly re-arrange the words (blank space separated) in a sentence (a line in a textfile). Any inspiration?? Txk so much. (9 Replies)
Discussion started by: eldeingles
9 Replies

7. Shell Programming and Scripting

Create random number

Hi, I'm trying to create a script that will print random numbers with length of three. Below is the expected out. 928-377-899 942-458-310 951-948-511 962-681-415 995-161-708 997-997-209 thanks (4 Replies)
Discussion started by: reignangel2003
4 Replies

8. Programming

random number

How can I choose randomly the row numbers of my file in awk? (4 Replies)
Discussion started by: Homa
4 Replies

9. Shell Programming and Scripting

How count the number of two words associated with the two words occurring in the file?

Hi , I need to count the number of errors associated with the two words occurring in the file. It's about counting the occurrences of the word "error" for where is the word "index.js". As such the command should look like. Please kindly help. I was trying: grep "error" log.txt | wc -l (1 Reply)
Discussion started by: jmarx
1 Replies

10. Shell Programming and Scripting

Split files by pairwise combination

I have 2 files $ cat tmp A1 File1a B1 File1b A2 File2a B2 File2b A1 File1a B3 File3b and $ cat tmp1 A1/B1 File3 A1/B1 File4 A1/B1 File5 A1/B1 File6 A1/B1 File7 A2/B2 File8 A2/B2 File9 A2/B2 File10 (1 Reply)
Discussion started by: senhia83
1 Replies
Monkey::Patch(3pm)					User Contributed Perl Documentation					Monkey::Patch(3pm)

NAME
Monkey::Patch - Scoped monkeypatching (you can at least play nice) VERSION
version 0.03 SYNOPSIS
use Monkey::Patch qw(:all); sub some_subroutine { my $pkg = patch_class 'Some::Class' => 'something' => sub { my $original = shift; say "Whee!"; $original->(@_); }; Some::Class->something(); # says Whee! and does whatever undef $pkg; Some::Class->something(); # no longer says Whee! my $obj = Some::Class->new; my $obj2 = Some::Class->new; my $whoah = patch_object $obj, 'twiddle' => sub { my $original = shift; my $self = shift; say "Whoah!"; $self->$original(@_); }; $obj->twiddle(); # says Whoah! $obj2->twiddle(); # doesn't $obj->twiddle() # still does undef $whoah; $obj->twiddle(); # but not any more SUBROUTINES
The following subroutines are available (either individually or via :all) patch_package (package, subname, code) Wraps "package"'s subroutine named <subname> with your <code>. Your code recieves the original subroutine as its first argument, followed by any arguments the subroutine would have normally gotten. You can always call the subroutine ref your received; if there was no subroutine by that name, the coderef will simply do nothing. patch_class (class, methodname, code) Just like "patch_package", except that the @ISA chain is walked when you try to call the original subroutine if there wasn't any subroutine by that name in the package. patch_object (object, methodname, code) Just like "patch_class", except that your code will only get called on the object you pass, not the entire class. HANDLES
All the "patch" functions return a handle object. As soon as you lose the value of the handle (by calling in void context, assigning over the variable, undeffing the variable, letting it go out of scope, etc), the monkey patch is unwrapped. You can stack monkeypatches and let go of the handles in any order; they obey a stack discipline, and the most recent valid monkeypatch will always be called. Calling the "original" argument to your wrapper routine will always call the next-most-recent monkeypatched version (or, the original subroutine, of course). BUGS
This magic is only faintly black, but mucking around with the symbol table is not for the faint of heart. Help make this module better by reporting any strange behavior that you see! perl v5.10.1 2010-07-16 Monkey::Patch(3pm)
All times are GMT -4. The time now is 02:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy