LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2009, 08:05 AM   #1
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Rep: Reputation: 30
JavaScript: Working out permutations


I'm looking to create a JavaScript script that can work out permutations, no duplicates or singles, so an array of numbers with 0, 1, 2 and 3 should return:

Code:
01, 02, 03, 12, 13, 23
012, 013, 023, 123
0123
The actual script will do something once it reaches a permutation, so 23 would actually be used to access two items in an array at positions 2 and 3 and return a value based on these values.

Now recursion is a topic I have never got my head around and I think it's probably going to be the answer to this post so any help would be appreciated.
 
Old 02-17-2009, 11:17 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
What you are asking is more like power sets.

Looking at the order in which you wrote the numbers it looks like you already have the algorithm in your head: it's just a simple loop starting with 01 you add 1 to the last digit each time until it reaches the max, then you carry over to next digit.
 
Old 02-17-2009, 11:56 AM   #3
Andy@DP
Member
 
Registered: Aug 2003
Posts: 208

Original Poster
Rep: Reputation: 30
No way - I didn't even see the pattern in the numbers that I wrote until you mentioned it.
That will give me something to work off, it should be simple enough to code that.

Cheers!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Combinations Vs. Permutations on Linux and Unix LXer Syndicated Linux News 0 09-19-2008 02:50 AM
Permutations & recursive Function cdog Programming 3 01-23-2006 08:05 AM
Javascript from AdSense not working properly linux-rulz General 2 03-29-2005 11:25 PM
fast algorithm - permutations kev82 Programming 3 08-10-2004 07:09 AM
Javascript not working in mozilla 1.6 ..Plz Help Me its_m3 Linux - Software 0 07-29-2004 04:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration