I have a list of hashes and I need to find the length and offset of the subsets in the list.
Here is an example:
There is an array of values, like the following array:
[A][B][C][D][E]
We have a Maximum Length
and ainput string similar to Minimum LengthABCDEFGHIJK
from which a loop generates 1 hash per a subsetseries of the original array, moving the offset from 1 until the point which the subset still fits in the original array.
Assuming the Maximum Length
as 3
and the Minimum Length
as 1
, the output will be:
1) [A][B][C]
2) [B][C][D]
3) [C][D][E]
4) [A][B]
5) [B][C]
6) [C][D]
7) [D][E]
8) [A]
9) [B]
10)[C]
11)[D]
12)[E]
For each subset, a hash will besequences has been generated which seats in the same index as the hash list like this:
1) Hash#1 ([A][B][C])
2) Hash#2 ([B][C][D])
3) Hash#3 ([C][D][E])
4) Hash#4 ([A][B])
5) Hash#5 ([B][C])
6) Hash#6 ([C][D])
7) Hash#7 ([D][E])
8) Hash#8 ([A])
9) Hash#9 ([B])
10)Hash#10 ([C])
11)Hash#11 ([D])
12)Hash#12 ([E])
Is it possible to get the subset length and offset using an offset from the hash list, maximum length, minimum length and original array's length?
Update:
Following I have provided a sample code in Javascript to be easily tested.
Assuming the code below:
var sourceData = "ABCDEFGHIJK";
var subs = [];
var dataLength = sourceData.length;
var maxLength = 8;
var minLength = 1;
var length = maxLength;
while (length >= minLength) {
var index = 0;
while (index + length <= dataLength) {
var sub = sourceData.substring(index, index + length);
subs.push(sub);
index++;
}
length--;
}
If you run the code provided above,into an array will be generated this looks like thisas following:
0: 'ABCDEFGH'
1: 'BCDEFGHI'
2: 'CDEFGHIJ'
3: 'DEFGHIJK'
4: 'ABCDEFG'
5: 'BCDEFGH'
6: 'CDEFGHI'
7: 'DEFGHIJ'
8: 'EFGHIJK'
9: 'ABCDEF'
10: 'BCDEFG'
11: 'CDEFGH'
12: 'DEFGHI'
13: 'EFGHIJ'
14: 'FGHIJK'
15: 'ABCDE'
16: 'BCDEF'
17: 'CDEFG'
18: 'DEFGH'
19: 'EFGHI'
20: 'FGHIJ'
21: 'GHIJK'
2200: 'ABCD'
2301: 'BCDE'
2402: 'CDEF'
2503: 'DEFG'
2604: 'EFGH'
2705: 'FGHI'
2806: 'GHIJ'
2907: 'HIJK'
3008: 'ABC'
3109: 'BCD'
3210: 'CDE'
3311: 'DEF'
3412: 'EFG'
3513: 'FGH'
3614: 'GHI'
3715: 'HIJ'
3816: 'IJK'
3917: 'AB'
4018: 'BC'
4119: 'CD'
4220: 'DE'
4321: 'EF'
4422: 'FG'
4523: 'GH'
4624: 'HI'
4725: 'IJ'
4826: 'JK'
4927: 'A'
5028: 'B'
5129: 'C'
5230: 'D'
5331: 'E'
5432: 'F'
5533: 'G'
5634: 'H'
5735: 'I'
5836: 'J'
5937: 'K'
ConsideringThe sequences in the out array, if we take above has been generated by following these steps:
- Set
length
to4
- Set
offset
to0
- Pick a
sequence
oflength
long characters from"ABCDEFGHIJK" (Input string)
- Put the
sequence
at the bottom ofoutput array
- Increase
offset
by1
- If
offset + length <= 11 (Input string's length)
thengoto 3
- Decrease
length
by1
- If
length >= 1
thengoto 2
- Exit
By looking at the index number 17output array, sequences in the item length isarray have a length
which starts at 4 and it has started ongradually goes down to 1, and also an offset
which is where in the index 2 ofinput string
the initial input data (which I call offset of 2)sequence
has begun.
What I'm trying to findachieve is a formula or algorithm which allows me to figure"predict" both the lengthlength
and offsetthe offset
of any itema sequence
at a given index
in the output arrayoutput array
, only by having its indexthe input string's length
and index in the output array
.
I'm preferably looking for a formula, without having access tohowever an algorithm which doesn't involve simulating the actual output array will work as well.