Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Scrambling a list
If this is Off Topic for the group, I appologize. I need some help
from xBASE programmers more experienced than I. The scenario..

I have a .dbf which is a list of members by family and a facility
that each member is assigned to. It might look like this..

first          last           fam   fac

Michael        Davis          2896  102
Mitch          McGlynn        3706  74
Theresa        McGlynn        3706  210
Mitchell       McGlynn        3706  210
Megan          McGlynn        3706  210
Patricia       Doyle          3715  210
Sandra         Ratliff        3712  342
Edgell         Ratliff        3712  342
Lori           Hayes          3713  74
David          Hayes          3713  74
Mary           Stoner         4777  40
Mary           Harrison       22486 102
Thomas         McGlynn        22751 391
Patricia       Griffin        22751 391
Thomas         McGlynn        22751 391
Connor         McGlynn        22751 391
Kesley         McGlynn        22751 391
Michaela       McGlynn        22751 391

The task is to rearrange the rows such that neither fam or fac are
adjacent. Theresa McGlynn cannot follow Mitch for example because
their families are the same. Patricia Doyle cannot follow Megan
McGlynn because their facilities are the same.

I'm not sure it can be done at all. Until now, I can't. TIA.
--
Joe Wright                            mailto:joewwright@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Wright
08-21-04 01:55 PM


Re: Scrambling a list
On Sun, 15 Aug 2004 16:10:51 -0400, Joe Wright
<joewwright@comcast.net> wrote:

>If this is Off Topic for the group, I appologize. I need some help
>from xBASE programmers more experienced than I. The scenario..
>
>I have a .dbf which is a list of members by family and a facility
>that each member is assigned to. It might look like this..
>
>first          last           fam   fac
>
>Michael        Davis          2896  102
>Mitch          McGlynn        3706  74
>Theresa        McGlynn        3706  210
>Mitchell       McGlynn        3706  210
>Megan          McGlynn        3706  210
>Patricia       Doyle          3715  210
>Sandra         Ratliff        3712  342
>Edgell         Ratliff        3712  342
>Lori           Hayes          3713  74
>David          Hayes          3713  74
>Mary           Stoner         4777  40
>Mary           Harrison       22486 102
>Thomas         McGlynn        22751 391
>Patricia       Griffin        22751 391
>Thomas         McGlynn        22751 391
>Connor         McGlynn        22751 391
>Kesley         McGlynn        22751 391
>Michaela       McGlynn        22751 391
>
>The task is to rearrange the rows such that neither fam or fac are
>adjacent. Theresa McGlynn cannot follow Mitch for example because
>their families are the same. Patricia Doyle cannot follow Megan
>McGlynn because their facilities are the same.

Sounds like a homework assignment to me. It is against my religion
to answer your problem. Hopefully everyone has good scruples.

>I'm not sure it can be done at all. Until now, I can't. TIA.


Report this thread to moderator Post Follow-up to this message
Old Post
techno
08-21-04 01:55 PM


Re: Scrambling a list
* techno <out.there@somewhere.com>:

> Sounds like a homework assignment to me. It is against my religion to
> answer your problem. Hopefully everyone has good scruples.

Given that "homework problems" tend to be posted by hit-and-run posters (and
they're hardly ever posted to <URL:news:comp.lang.clipper> anyway) don't you
think that "good scruples" would run at least as far as you checking if the
OP was a regular of this group or not first? Here, let me do your homework
for you:

<URL:http://groups.google.com/groups?q=g...t%40comcast.net>

Good job I don't share your religion isn't it?

--
"Religion, whatever its consolations, makes for hideous governance."
John Lloyd, New Statesman

Report this thread to moderator Post Follow-up to this message
Old Post
Dave Pearson
08-21-04 08:55 PM


Re: Scrambling a list
* Joe Wright <joewwright@comcast.net>:

> I'm not sure it can be done at all. Until now, I can't. TIA.

It's a bit brute force and won't really scale very well but, in the absence
of a more elegant solution, how about generating lists of every possible
permutation and then searching for the first permutation that satisfies the
stated rules? Or is the volume of data too great for this to stand a chance
of working?

--
Dave Pearson                        |  OSLib - Timeslice release functions.
http://www.davep.org/               |     eg - Norton Guide reader for Linux
.
http://www.davep.org/clipper/       |    weg - Norton Guide reader for Windo
ws.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.

Report this thread to moderator Post Follow-up to this message
Old Post
Dave Pearson
08-22-04 08:55 PM


Re: Scrambling a list
Joe

How many different familiy numbers??
How many different facility numbers??
How big a list??

You might not be enough family members for you to achieve it.
What I mean is if you have a family with 5 members you'll have to have at le
ast
5 others from different families that don't have the same facility numbers.
Eg
> Thomas         McGlynn        22751 391
> Michael        Davis          2896  102
> Connor         McGlynn        22751 391
> Mitch          McGlynn        3706  74
> Kesley         McGlynn        22751 391
> Theresa        McGlynn        3706  210
> Michaela       McGlynn        22751 391

Given the info you've supplied you'd probably have to use a brute force meth
od.

--
HTH
Steve



Report this thread to moderator Post Follow-up to this message
Old Post
Stephen Quinn
08-22-04 08:55 PM


Re: Scrambling a list
techno wrote:
> On Sun, 15 Aug 2004 16:10:51 -0400, Joe Wright
> <joewwright@comcast.net> wrote:
>
[ my post is immediately up-thread ]

> Sounds like a homework assignment to me. It is against my religion
> to answer your problem. Hopefully everyone has good scruples.
>

It's not homework. It's hard stuff. No wonder you can't answer it.
--
Joe Wright                            mailto:joewwright@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Wright
08-22-04 08:55 PM


Re: Scrambling a list
On Sun, 15 Aug 2004 20:02:42 -0500, "E.Fridman" <pm771@netscape.net>
wrote:

>Joe,
>
>Yes, it can be done. I mean such algorithms exist.

>http://www.staff.vu.edu.au/

Small world. The "vu" is Victoria University and is about 30 minutes
from me. I attended a single semester subject on the motorola 6809
microprocessor there back in ...cough, cough 1980 <g>.

Regards,

Ross McKenzie
ValuSoft
Melbourne Australia

valusoft AT optushome DOT com DOT au

Report this thread to moderator Post Follow-up to this message
Old Post
Ross McKenzie
08-22-04 08:55 PM


Re: Scrambling a list
On 15 Aug 2004 21:09:31 GMT, Dave Pearson <davep.news@davep.org>
wrote:

>* Joe Wright <joewwright@comcast.net>:
> 
>
>It's a bit brute force and won't really scale very well but, in the absence
>of a more elegant solution, how about generating lists of every possible
>permutation and then searching for the first permutation that satisfies the
>stated rules? Or is the volume of data too great for this to stand a chance
>of working?

Ever heard of factorials?

F! of 18 is a bigger number than you'd want to make a list of? It's
like billions of billions of billions of billions. A big number.

Report this thread to moderator Post Follow-up to this message
Old Post
techno
08-23-04 01:55 AM


Re: Scrambling a list
* techno <out.there@somewhere.com>:

> On 15 Aug 2004 21:09:31 GMT, Dave Pearson <davep.news@davep.org>
> wrote:
> 
>
> Ever heard of factorials?

Yes; why do you think I included a disclaimer to that affect *twice* in the
above paragraph?

> F! of 18 is a bigger number than you'd want to make a list of? It's like
> billions of billions of billions of billions. A big number.

Unless I'm mistaken it's six quadrillion, four hundred and two trillion,
three hundred and seventy-three billion, seven hundred and five million,
seven hundred and twenty-eight thousand.

--
Dave Pearson                        |  OSLib - Timeslice release functions.
http://www.davep.org/               |     eg - Norton Guide reader for Linux
.
http://www.davep.org/clipper/       |    weg - Norton Guide reader for Windo
ws.
http://www.davep.org/norton-guides/ | dgscan - DGROUP scanner for Clipper.

Report this thread to moderator Post Follow-up to this message
Old Post
Dave Pearson
08-23-04 01:55 AM


Re: Scrambling a list
/*
See below.
The wanted data is at the end of the mail
Sorry for the long post
Alejandro

** NOTE **
THIS CODE works, but is not optimized code !
*/

* I got your data inside OLD.DBF with
* APPEND FROM pepe.txt TYPE SDF
* I add a NUMERIC field of 4 position named ID to OLD.DBF

COPY FILE OLD.DBF TO WORK.DBF  // backup because work will be destroyed

SELE 1
USE WORK

* Create empty dbf
COPY STRUCTURE TO LIST

SELE 2
USE LIST

SELE 1

*--- only for 1st Time --------
* We need the first rec for comparision purposes
nCurRec := 1
GOTO nCurRec

* Get needed fields
nOldFam  := FAM
nOldFac  := FAC

* copy current record to LIST.DBF
COPYFIELDS( nCurRec )

DELETE   // current record
PACK
*--- only for 1st Time --------


DO WHILE LASTREC() > 0     // in WORK.DBF

? "record left: ", LASTREC()

nCurRec := INT( FT_RAND1( LASTREC() )) +1

GOTO nCurRec

IF FAM <> nOldFam   // match family ?
IF FAC <> nOldFac   // match facility ?
* lSuccess := .T.

* 2) Get New needed fields before deletion
nOldFam  := FAM
nOldFac  := FAC

* copy current record to LIST.DBF
COPYFIELDS( nCurRec )

DELETE   // current record
pack

ENDIF
ENDIF

ENDDO


? "record left: ", LASTREC()
SELE 2
LIST ID, FIRST, LAST, FAM, FAC TO FILE output.txt


* After that if you want the original data, just index:
* SELE 2
* INDEX ON ID TO LIST1
QUIT



*------------------------------
FUNCTION COPYFIELDS( nCurRec )
*------------------------------
LOCAL nID, cFirst, cLast, nFam, nFac

// assumes you are stand, over the right record
nID = ID
cFirst = FIRST
cLast = LAST
nFam  = FAM
nFac  = FAC

SELE 2
APPEND BLANK
REPLACE  ID    WITH nID
REPLACE  FIRST WITH cFirst
REPLACE  LAST  WITH cLast
REPLACE  FAM   WITH nFam
REPLACE  FAC   WITH nFac
COMMIT

SELE 1
GOTO nCurRec
RETURN 0

/*
This is one of the many output you can get

1    1 Michael         Davis             2896 102
2   13 Thomas          McGlynn          22751 391
3    8 Edgell          Ratliff           3712 342
4    9 Lori            Hayes             3713  74
5   18 Michaela        McGlynn          22751 391
6   12 Mary            Harrison         22486 102
7    3 Theresa         McGlynn           3706 210
8   11 Mary            Stoner            4777  40
9    4 Mitchell        McGlynn           3706 210
10   14 Patricia        Griffin          22751 391
11    2 Mitch           McGlynn           3706  74
12   17 Kesley          McGlynn          22751 391
13   10 David           Hayes             3713  74
14   16 Connor          McGlynn          22751 391
15    7 Sandra          Ratliff           3712 342
16    6 Patricia        Doyle             3715 210
17   15 Thomas          McGlynn          22751 391
18    5 Megan           McGlynn           3706 210
*/


--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

Report this thread to moderator Post Follow-up to this message
Old Post
Alejandro
08-23-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Clipper archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:45 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.