Help with a logic problem
Posted
by Stradigos
on Stack Overflow
See other posts from Stack Overflow
or by Stradigos
Published on 2010-03-18T00:38:04Z
Indexed on
2010/03/18
0:41 UTC
Read the original article
Hit count: 392
I'm having a great deal of difficulty trying to figure out the logic behind this problem. I have developed everything else, but I really could use some help, any sort of help, on the part I'm stuck on.
Back story:
*A group of actors waits in a circle. They "count off" by various amounts. The last few to audition are thought to have the best chance of getting the parts and becoming stars.
Instead of actors having names, they are identified by numbers. The "Audition Order" in the table tells, reading left-to-right, the "names" of the actors who will be auditioned in the order they will perform.*
Sample output:
etc, all the way up to 10.
What I have so far:
using System;
using System.Collections;
using System.Text;
namespace The_Last_Survivor
{
class Program
{
static void Main(string[] args)
{
//Declare Variables
int NumOfActors = 0;
System.DateTime dt = System.DateTime.Now;
int interval = 3;
ArrayList Ring = new ArrayList(10);
//Header
Console.Out.WriteLine("Actors\tNumber\tOrder");
//Add Actors
for (int x = 1; x < 11; x++)
{
NumOfActors++;
Ring.Insert((x - 1), new Actor(x));
foreach (Actor i in Ring)
{
Console.Out.WriteLine("{0}\t{1}\t{2}", NumOfActors, i, i.Order(interval, x));
}
Console.Out.WriteLine("\n");
}
Console.In.Read();
}
public class Actor
{
//Variables
protected int Number;
//Constructor
public Actor(int num)
{
Number = num;
}
//Order in circle
public string Order(int inter, int num)
{
//Variable
string result = "";
ArrayList myArray = new ArrayList(num);
//Filling Array
for (int i = 0; i < num; i++)
myArray.Add(i + 1);
//Formula
foreach (int element in myArray)
{
if (element == inter)
{
result += String.Format(" {0}", element);
myArray.RemoveAt(element);
}
}
return result;
}
//String override
public override string ToString()
{
return String.Format("{0}", Number);
}
}
}
}
The part I'm stuck on is getting some math going that does this:
Can anyone offer some guidance and/or sample code?
© Stack Overflow or respective owner