Sponsored Content
Top Forums Shell Programming and Scripting Python: generateeuro-millions combinations Post 302512728 by sk1418 on Monday 11th of April 2011 11:44:34 AM
Old 04-11-2011
i didn't read your codes through. I wrote a py script, to do the combination calculation (5 from 50). you can change the two numbers. of course some validation was not implemented, e.g m(5) should be smaller than n(50) etc.

I saved the results in a list (result), didn't print it out or save into a file. the output of my codes was just the total possibilities. (2118760). it took 2min and 50 secs to calculate C 50 5.


Code:
kent$ time python pySolution.py
2118760
python pySolution.py  167.13s user 0.64s system 98% cpu 2:50.08 total

here are the python script:

PHP Code:
#!/usr/bin/python
def getCombinations(n,m):
    
allNum range(1,n+1)
    
idx = [0]*n
    
# index matrix
    
idxMatrix = []
    
result = []

    for 
i in range(m):
        
idx[i]=1
    idxMatrix
.append(idx)    
    while(
getIdxMatrix(idxMatrix,m)):
        
pass
    
for l in idxMatrix:
        
#print l
        
result.append([for x in allNum if l[allNum.index(x)]])
    print 
len(result)

def getIdxMatrix(idxMatrix,m):
    
last idxMatrix[-1]
    
newline = list(last)
    for 
i in range(len(newline)):
        if 
i!=len(newline)-and newline[i]==and newline[i+1]==0:
            
su sum(last[:i])
            
newline[i],newline[i+1] = 0,1
            
for j in range(i):
                
newline[j]=if j<su else 0
            idxMatrix
.append(newline)
            return 
True
    
return False

getCombinations
(50,5
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

dump/restore of a fs with 100 of millions hardlinks

Hi :-) i have a dump of a backupdisk (~540GB / ext3). The Backups have some 100 millions of hardlinks (backups are created with storeBackup). The OS is linux. A restore of a directory ended after some days with the errormessage "no memory to extend symbol table" The restore of the complete... (0 Replies)
Discussion started by: turricum
0 Replies

2. Shell Programming and Scripting

Generating millions of record using shell script

Hi All, My requirement is like this. I want to generate records of 1 million lines. If I say lines it means one line will contain some string or numbers like AA,3,4,45,+223424234,Tets,Ghdj,+33434,345453434,........................ upto length lets say 41. ( 41 comma sepearted aplha numneric... (2 Replies)
Discussion started by: Rahil2k9
2 Replies

3. UNIX for Advanced & Expert Users

How to zip/tar millions of files?

Hi guys, I have an issue processing a large amount of files. I have around 5 million files (some of them are actually directories) in a server. I am unable to find out the exact number of files since it's taking "forever" to finish (See this thread for more on the issue). Anyway, now I... (6 Replies)
Discussion started by: verdepollo
6 Replies

4. Shell Programming and Scripting

Need script to remove millions of tmp files in /html/cache/ directory

Hello, I just saw that on my vps (centOS) my oscommerce with a seo script has created millions of tmp files inside the /html/cache/ directory. I would need to remove all those files (millions), I tried via shell but the vps loads goes to very high and it hangs, is there some way to do a... (7 Replies)
Discussion started by: andymc1
7 Replies

5. Shell Programming and Scripting

Need an efficient way to search for a tag in an xml file having millions of rows

Hi, I have an XML file with around 1 billion rows in it and i am trying to find the number of times a particular tag occurs in it. The solution i am using works but takes a lot of time (~1 hr) .Please help me with an efficient way to do this. Lets say the input file is <Root> ... (13 Replies)
Discussion started by: Sheel
13 Replies

6. Shell Programming and Scripting

Millions of record using shell script

I wanna create a millions of record using shell scripts.. the scenario is somehow like this,,,i want to create the record for these fields in my database..id,name,addrs,sales. So can you please give a overall idea for how to achieve it? (9 Replies)
Discussion started by: shankarpanda003
9 Replies

7. Shell Programming and Scripting

How to create a file contains millions of lines and each line has different datas?

I want to create a file contains millions of lines. The line format like this: acnum$$123456$$+$$Tom$$111$$ fields separated by $$, field 1 and field 3 have only two options:acnum or crenum; + or -. field 4 can be any name or any letters. Other fields can be any fixed length digits. So, I want to... (9 Replies)
Discussion started by: hhdzhu
9 Replies

8. UNIX for Beginners Questions & Answers

Print a python script down a list in a text file without printing a lot combinations

In a python script I have 2 files printing side by side on the same line. I want to have 1 of the files to be already displayed at once while the other file print down the list in the file and it still will produce new lines. I want to do it like that to reduce printing a lot of lines and... (0 Replies)
Discussion started by: bigvito19
0 Replies
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy