1. algorythm

This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C2FF5A.A5720DD0
	charset="iso-8859-1"

hi anyone,

is there an algorythm to determine sequences of 5 numbers in a given =
range (ex. 1 - 20) where each couple of numbers is used only once ?
jos hermans 
------=_NextPart_000_0005_01C2FF5A.A5720DD0
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>hi anyone,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>is there an algorythm to determine =
sequences of 5=20
numbers in </FONT><FONT face=3DArial size=3D2>a given range (ex. 1 - =
20)&nbsp;where=20
each couple of numbers is used only once ?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>jos =

------=_NextPart_000_0005_01C2FF5A.A5720DD0--

new topic     » topic index » view message » categorize

2. Re: algorythm

This should do the trick:

function unique_sequence(integer num_entries,sequence range)
	sequence s
	integer n

	s = {}

	for i=1 to num_entries do
		while 1 do
			n = rand(range[2]+1-range[1])+range[1]-1
			if not find(n,s) then
				s &= n
				exit
			end if
		end while
	end for
	return s
end function


? unique_sequence(5,{1,20})

-- END OF CODE

Note that it *does* have the possibility of ending up in an eternal loop, 
but the odds of that ever happening is close to zip (unless to do something 
stupid like unique_sequence(2,{1,1}) )


>hi anyone,
>
>is there an algorythm to determine sequences of 5 numbers in a given range 
>(ex. 1 - 20) where each couple of numbers is used only once ?
>jos hermans

new topic     » goto parent     » topic index » view message » categorize

3. Re: algorythm

sorry, but this prog is not quite what i'm looking for.
what I need is "all" sequences, with every couple of numbers just used once.
This one produces only 1 sequence, and isn't calculated, but just picked
randomly.


Jos


----- Original Message -----
From: <stabmaster_ at hotmail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, April 10, 2003 1:15 PM
Subject: Re: algorythm


>
> This should do the trick:
>
> function unique_sequence(integer num_entries,sequence range)
> sequence s
> integer n
>
> s = {}
>
> for i=1 to num_entries do
> while 1 do
> n = rand(range[2]+1-range[1])+range[1]-1
> if not find(n,s) then
> s &= n
> exit
> end if
> end while
> end for
> return s
> end function
>
>
> ? unique_sequence(5,{1,20})
>
> -- END OF CODE
>
> Note that it *does* have the possibility of ending up in an eternal loop,
> but the odds of that ever happening is close to zip (unless to do
something
> stupid like unique_sequence(2,{1,1}) )
>
>
> >hi anyone,
> >
> >is there an algorythm to determine sequences of 5 numbers in a given
range
> >(ex. 1 - 20) where each couple of numbers is used only once ?
> >jos hermans
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu