dbTalk Databases Forums  

Algorithm

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss Algorithm in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
andre_magalhaes@sapo.pt
 
Posts: n/a

Default Algorithm - 04-22-2006 , 08:20 AM






I am looking for a possible algorithm that can generate all sequences
of numbers formed by the 10 basic numeric figures: 0, 1, 2, 3, 4, 5, 6,
7, 8 and 9.

It is essential that, in all formed combinations, no digit is repeated
and that all of them are used.

Please help in any way you can.

Thank you.


Reply With Quote
  #2  
Old   
Josh Assing
 
Posts: n/a

Default Re: Algorithm - 04-22-2006 , 06:38 PM







Brute force function...


FUNCTION randnum
LPARAMETERS tcDigits, tnLen
IF PARAMETERS()=0
tcDigits = "0123456789"
ENDIF
IF PARAMETERS() <2
tnLen = LEN(tcdigits)
ENDIF

LOCAL lcNumber AS STRING,lnNumber AS INTEGER , x AS INTEGER, lcDigit
lcNumber = ""

FOR x = 1 TO tnLen
lcDigit = SUBSTR(tcDigits,INT(RAND()*LEN(tcDigits))+1,1)
tcDigits = STRTRAN(tcDigits,lcDigit,"")
lcNumber = lcNumber + lcDigit
ENDFOR
RETURN eval(lcNumber)
ENDFUNC


On 22 Apr 2006 06:20:14 -0700, andre_magalhaes (AT) sapo (DOT) pt wrote:

Quote:
I am looking for a possible algorithm that can generate all sequences
of numbers formed by the 10 basic numeric figures: 0, 1, 2, 3, 4, 5, 6,
7, 8 and 9.

It is essential that, in all formed combinations, no digit is repeated
and that all of them are used.

Please help in any way you can.

Thank you.

--- AntiSpam/harvest ---
Remove X's to send email to me.


Reply With Quote
  #3  
Old   
Michael J Davis
 
Posts: n/a

Default Re: Algorithm - 04-24-2006 , 05:15 AM



Josh Assing <XjoshX (AT) jAssing (DOT) com> opined
Quote:
Brute force function...


FUNCTION randnum
LPARAMETERS tcDigits, tnLen
IF PARAMETERS()=0
tcDigits = "0123456789"
ENDIF
IF PARAMETERS() <2
tnLen = LEN(tcdigits)
ENDIF

LOCAL lcNumber AS STRING,lnNumber AS INTEGER , x AS INTEGER, lcDigit
lcNumber = ""

FOR x = 1 TO tnLen
lcDigit = SUBSTR(tcDigits,INT(RAND()*LEN(tcDigits))+1,1)
tcDigits = STRTRAN(tcDigits,lcDigit,"")
lcNumber = lcNumber + lcDigit
ENDFOR
RETURN eval(lcNumber)
ENDFUNC
Not sure which version of VFP you are using. In the early version I use
RAND() always starts at the same sequence, and so needs some
'randomisation seed'.

I use rand(seconds()) in place of rand() above.

Mike

--
Michael J Davis

<>{
Free advice is often worth
less than you paid for it.
<>{


Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.