-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjosephusPermutationOrder.cs
More file actions
57 lines (46 loc) · 1.31 KB
/
Copy pathjosephusPermutationOrder.cs
File metadata and controls
57 lines (46 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace josephusPermutationOrder
{
class Program
{
static void Main(string[] args)
{
List<object> items = new List<object> { 1, 2, 3, 4, 5, 6, 7 };
int k = 3;
List<object> turns = Josephus.JosephusPermutation(items, k);
foreach (var item in turns)
{
Console.WriteLine(item);
}
}
}
public class Josephus
{
public static List<object> JosephusPermutation(List<object> items, int k)
{
List<object> turns = new List<object>();
int point = k - 1;
while (items.Count != 0)
{
while (point >= items.Count)
{
point -= items.Count;
}
Console.WriteLine("Pointer position: " + point + " looking at: " + items[point]);
foreach (var item in items)
{
Console.Write(item);
}
Console.WriteLine();
turns.Add(items[point]);
items.RemoveAt(point);
point += k - 1;
}
return turns;
}
}
}