Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A program to work out the number of open cells?

Status
Not open for further replies.

karisma

Vendor
Nov 17, 2002
2
0
0
US
Hi,

I have been going through your site, it is really good. I was wondering if you could help me. I would be really grateful if you could spend a few moments going through this and just showing me how to write the program for it to run in Fortran 90.

This is the scenario: One night a number of prison wardens got drunk and decided to play a game. The first one runs up a row of cells and unlocks each cell. Then, the second warden relocks every second cell. The third warden runs up and switches the lock of every 3rd cell; if it was locked its now open and vice versa. The fourth warden does them same thing, but only on every fourth cell. The 5th warden will only switch the lock on every 5th cell and so on. The wardens carry on until all of them has had a go. Basically at the end of the program it should print how many cells are open after the last warden has run and a list of all the open and closed cells should be saved to a file. The program should allow the user to input any number of wardens and cells.

Please, please, please anyone who understands this help me, i'm really very stuck :(
 
This sounds like a homework assignment, so I wont just write the program for you. But what you need to do is delcare an array of integers for the cells, set them all to zero to represent a locked cell, then create an outer do loop to represent each warden running down the cell block and an inner do loop to set the appropriate array elements to 1 or zero. Post your best attempt and I'm sure someone will critique it for you. BTW, how many cells and how many wardens? CaKiwi
 
I hate to say this but it does look like a very simple question, overly verbose to attempt to complicate things.

If this was a homework assignment then it is probably aiming to see that you can weed the info out of the chaff.
As the above asnwer states:
1 array of integers set to 1 (initially)
2 ints No wardens, No cells
+ some useful control variables

loop warden
loop cell (in steps of warden)
cell = cell * -1
end loop
end loop

multiplying by -1 swaps between -1 & +1 ie locked / unlocked.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top