The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
October 01, 2020, 03:10:20 PM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  permutations
« previous next »
Pages: [1] Print
Author Topic: permutations  (Read 3063 times)
0x58
New Member
*
Posts: 22


permutations
« on: January 30, 2012, 03:13:09 PM »

hi all :) i did a lot of googling but didn't find any good answers Roll Eyes so i'm wondering if there is a way to get all the possible lexicographic permutations of a given object either a number or a word. for exemple we have 0, 1 and 2, it's possible lexicographic permutations are: 012, 021, 102, 120, 201,210

thank's for your help :)
Logged
z941998
Member
****
Gender: Male
Posts: 96


Re: permutations
« Reply #1 on: January 30, 2012, 04:28:49 PM »

Google for Combinatorial Algorithms - For computers and calculators.

You will find a few for Computer Science and Applied Mathmatics - Editor: Werner Rheinboldt from University of Maryland.

Look for the pdfs and you will have all you need.  He also has a book (the pdf).

Welcome on board.
Logged
bozo
Member
*****
Posts: 242



Re: permutations
« Reply #2 on: January 30, 2012, 04:43:05 PM »

Here's a rough idea.

Code:
comment ~

      000
      001
      002
      010
      011
      012
      020
      021
      022
      100
      101
      102
      110
      111
      112
      120
      121
      122
      200
      201
      202
      210
      211
      212
      220
      221
      222

~

.686
.model flat,stdcall

extern printf :proc
extern exit   :proc

WORD_LEN equ 3

.data

format db 10,"%s",0

elements db "012"
elements_len equ $-str

index db WORD_LEN dup (0)
buf db WORD_LEN+1 dup (0)

.code

start:
      lea esi, [index]
      lea ebx, [elements]
      lea edi, [buf]
load_string:
      mov ecx, WORD_LEN
      pushad
load_index:
      lodsb               ; idx = index[0]
      xlatb               ; c = str[ idx ]
      stosb               ; buf[i] = c
      loop load_index     ; --i

      push offset buf
      push offset format
      call printf
      pop eax
      pop eax
      popad

inc_index:
      inc byte ptr [esi+ecx-1]   ; increment last index
      cmp byte ptr [esi+ecx-1], WORD_LEN   ; exceeded word len?
      jne load_string

      mov byte ptr [esi+ecx-1], 0                 ; reset
      loop inc_index

      push 0
      call exit

      end start
Logged
dedndave
Member
*****
Posts: 12523


Re: permutations
« Reply #3 on: January 30, 2012, 06:09:26 PM »

long ago, i wrote a permutation routine in 16-bit code
it was recursive, and would handle various group widths

maybe this link will help...
http://www-edlab.cs.umass.edu/cs123/Projects/Permutation/project6.htm
Logged
FORTRANS
Member
*****
Gender: Male
Posts: 1147


Imagine


Re: permutations
« Reply #4 on: January 30, 2012, 10:57:59 PM »

Hi,

   You can use a set of nested loops.  In a pseudo-BASIC
style..

Cheers,

Steve N.

Code:
FOR I = 0 to 2
  FOR J = 0 TO 2
  IF ( I = J ) GOTO 20
    FOR K = 0, 2
    IF ( I = K ) GOTO 10
    IF ( J = K ) GOTO 10
    PRINT I, J, K
10 NEXT K
20 NEXT J
NEXT I
END
Logged
0x58
New Member
*
Posts: 22


Re: permutations
« Reply #5 on: January 31, 2012, 01:29:56 AM »

thank you all for your help  ThumbsUp
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!