-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseNToIntegerArray.cs
More file actions
78 lines (64 loc) · 1.95 KB
/
BaseNToIntegerArray.cs
File metadata and controls
78 lines (64 loc) · 1.95 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
namespace NP_CompleteOrder
{
public class BaseNIntegerArray
{
public static int[] CreateArray(decimal[] inputArray, decimal total)
{
List<int> output = new List<int>();
foreach (var item in inputArray)
{
decimal x = total/item;
output.Add((int)x.RoundUp());
}
return output.ToArray();
}
public static long GetLimit(int[] inputArray)
{
long output = 1;
foreach (var value in inputArray)
{
output *= value;
}
return output;
}
public static int[] GetPosition(int[] inputArray, long index)
{
List<int> output = new List<int>();
for(int pointer = 0; pointer < inputArray.Length; pointer++)
{
if (index < 1)
{
output.Add(0);
}
else
{
output.Add((int)index % inputArray[pointer]);
}
index = (long)Math.Floor((double)index / inputArray[pointer]);
}
/*
foreach (var item in inputArray)
{
output.Add((int)index % item);
index = (long)Math.Floor((double)index / item);
if(index<1)
{
break;
}
}*/
return output.ToArray();
}
public static int[] Convert(long counter, int numberBase)
{
List<int> output = new List<int>();
while (counter > 0)
{
output.Add((int)counter % numberBase);
counter = (long)Math.Floor((double)counter / numberBase);
}
return output.ToArray();
}
}
}