Jump to content
IGNORED

Programming puzzle, advice wanted


CPFace

Recommended Posts

I'm looking for advice for a routine I want to write. I have an idea how it could work, but I was wondering if anyone had any more efficient ideas. All I'm looking for is a general strategy -- code is appreciated, but not necessary, and if you do decide to code it, assembly is just as good as BASIC.

 

Here's the behavior I'm looking for:

 

The variables a, b, c, d, and e must all be set to random numbers from 0 to 7. Every value must be unique; there can be no duplicates.

 

The variables a and b are already determined when the routine begins. They may change between calls to the routine, but they are not randomly selected. (It can be assumed that a and b are not equal.)

 

The routine has to finish in a predictable amount of time and, of course, operate as quickly as possible. The program can't sit and reselect random numbers until the conditions are met because how long it takes can't be predicted.

 

The routine doesn't have to be statistically perfect -- it's okay if one number or another has a slightly higher chance of being picked as long as the outcome can't be predicted.

 

Here's the basic strategy I've come up with so far:

 

Use temp1-6 to hold the numbers 0-7 that aren't equal to a or b.

 

Maybe shuffle their values around a bit. (Pick two of them at random and switch the values around, repeat a certain number of times.)

 

Select one of them at random, put the value into c.

 

Select one of the remaining values at random, put it into d, repeat for e.

 

Anyone else have any suggestions?

Link to comment
Share on other sites

It's not a puzzle game -- the problem of assigning random values to the variables was the puzzle. ;) The game I'm working on may yet be a fairly generic dungeon-crawler. The routine was intended to randomize contents in the maze.

 

Problem is, if I go the route I've chosen, it's going to take half a kilobyte of my ROM space just to store the random scenarios! O_o Depending on how things go, I may just have to resort to non-randomized maze contents.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...