using System;
using System.Linq;
class Program
{
static void Main()
{
Console.WriteLine(GetLastStanding(11, 4));
}
static int GetLastStanding(int n, int step)
{
var items = Enumerable.Range(0, n)
.Select(position => new Item { Position = position }).ToArray();
var i = 0;
var stepCounter = 0;
var nCounter = n;
while (nCounter > 1)
{
if (!items[i].Marked && ++stepCounter == step)
{
stepCounter = 0;
items[i].Marked = true;
--nCounter;
Console.WriteLine(string.Join(", ",
items.Select(item => item.Marked ?
"_" : (item.Position + 1).ToString())));
}
i = (i + 1) % n;
}
return items.Single(item => !item.Marked).Position;
}
struct Item
{
public int Position;
public bool Marked;
}
}
public class MyNumeric<T> where T : struct, IComparable<T>, IEquatable<T>, IConvertible
{
public static readonly T MaxValue = ReadStaticField("MaxValue");
public static readonly T MinValue = ReadStaticField("MinValue");
private static T ReadStaticField(string name)
{
FieldInfo field = typeof(T).GetField(name, BindingFlags.Public | BindingFlags.Static);
if (field == null)
{
throw new InvalidOperationException("Нечисловой тип: " + typeof(T).Name);
}
return (T)field.GetValue(null);
}
}
Console.WriteLine(MyNumeric<int>.MaxValue);
Console.WriteLine(MyNumeric<float>.MinValue);