Printing Character and same number for 8 iterations approach

I’m trying to print something like this:
Letters : A - H for 24 times
Number pattern I wanted to print is as shown below. Basically, 1 will be printed next to A & H for first 8 iterations, then 2 will be used, then 3 so on and so forth.

"A1"
"B1"
"C1"
"D1"
"E1"
"F1"
"G1"
"H1"
"A2"
"B2"
"C2"
"D2"
"E2"
"F2"
"G2"
"H2"
"A3"
"B3"
"C3"
"D3"
"E3"
"F3"
"G3"
"H3"

Question #1:
Is the logic I’ve used in this JSFiddle good enough to handle this? Currently this is only handling loop values till 24 but I’m going to expand the same pattern up to 96 numbers and plan to follow same pattern.

for( i = 0 ; i < 24 ; i++){


for (j = i ; j < 8 ; j++){
var k = 1;
}
for (j = 8 ; j < 16 ; j++){
var p = 2;
}
for (j = 16 ; j < 24 ; j++){
var q = 3;
}

var number = 65 + (i%8)
var characterVal = String.fromCharCode(number) 
if(i < 8){
console.log(characterVal+k);
} else if( i >= 8 && i < 16){
console.log(characterVal+p);
}
else if( i >= 16 && i < 24){
console.log(characterVal+q);
}

}

Question #2:

Just like I have a simple sequence of alphabets in above scenario from A-H which I was able to generate using the logic var number = 65 + (i%8). Is there a logic I could use to generate the following pattern of alphabets for first 24 values?

A1
G1
B1
H1
C1
A2
D1
B2
E1
C2
F1
D2
E2
C3
F2
D3
G2
E3
H2
F3
A3
G3
B3
H3

This loop does nothing.

If you can tell me what the pattern is, sure. Cause i dont see an obvious pattern to those values.

I see. Only following one is enough it looks like:

for (j = 16 ; j < 24 ; j++){
var q = 3;
}

The pattern related to Question #1 is the following (where A-H have 1 number next to it first, then 2 and then 3):


We are considering the starting value as A1 from top left to bottom (D2) and then E2 to H3 in a sequential manner that I printed above.

I believe there isn’t any pattern. The above table changes to the following:

I guess I may just need to hard code the above values of the table in an array and use it as needed.

For A1-H1, this loop is used, right?

for( i = 0 ; i < 24 ; i++){


for (j = i ; j < 8 ; j++){
var k = 1;
}
for (j = 8 ; j < 16 ; j++){
var p = 2;
}
for (j = 16 ; j < 24 ; j++){
var q = 3;
}

var number = 65 + (i%8)
var characterVal = String.fromCharCode(number) 
if(i < 8){
console.log("Inside i<8");
console.log(characterVal+k);
} else if( i >= 8 && i < 16){
console.log("Inside ( i >= 8 && i < 16)");
console.log(characterVal+p);
}
else if( i >= 16 && i < 24){
console.log("Inside else if( i >= 16 && i < 24)");

console.log(characterVal+q);
}

I would counter it that:

can be replaced by:

let k = 1;
let p = 2;
let q = 3;

Consider: In this loop:

1: What happens the first time the loop executes?
2: What happens the second time the loop executes?
3: What’s the net outcome of the loop?

===

Ironically, showing it to me in this form has shown me exactly what the pattern is. It’s an Interlaced Mod 6.

Perhaps it would become more clear if I turned the table back into numbers (so A1 = 1, B1 = 2, etc)

Desired pattern:

1
7
2
8
3
9
4
10
5
11
6
12
(Here we hit 12, so the pattern "restarts")
13
19
14
20
15
21
16
22
17
23
18
24

This is… doable, but would require your dataset to contain a multiple of 12 elements (or if failing that, some logic to handle “what about the missing numbers at the end”)

This my take to the first question (Play with the variables):

let starChar = "A".charCodeAt(0)
let endChar = "I".charCodeAt(0)
let counterEnd = 4

for(let counter = 1; counter < counterEnd; counter++) {
	for(let i = starChar; i < endChar; ++i) {
		console.log('"' + (String.fromCharCode(i) + counter) + '"')
	}
}

The second question, I don’t see a pattern either, seem random to me

I fell into the weeds a bit on question 2.

Given a string Alphabet and a Modulo;

//Input
const alphabet = "ABCDEFGH"
const modulo = 6

//Output
let output = []

//Calculated Values
const alphalen = alphabet.length;
const lcm = LCM(alphalen,modulo);
const cycles = lcm / (modulo*2);

//Loop
for(cycle = 0; cycle < cycles; cycle++) {
  for(modpos = 0; modpos < modulo; modpos++) {
     output.push(getCharacterForNum((cycle*modulo*2) + modpos));
     output.push(getCharacterForNum((cycle*modulo*2) + modpos + modulo));
   }
}

//Do something with output.
document.getElementById("output").innerHTML = output;

//For a given index, find the correct Letter/Number combination.
function getCharacterForNum(num) {
  let letter = alphabet[num % alphalen];
  let number = Math.floor(num / alphalen)+1;
  return letter + number;
}

//Function to find the Least Common Multiple of A and B and 2.
function LCM(a,b) {
    let large = Math.max(a, b);
    let small = Math.min(a, b);
    for (check = large; ; check += large) {
        if (check % small == 0 && check % 2 == 0)
            return check;
    }
}

The original pattern works because the alphabet is of length 8, the modulo is 6; their LCM is 24 (8*3 and 6*4), so for an alphabet of length 8 and a target output of 24, you perform 3 cycles of the alphabet, running the Interlaced Modulo pattern.

Note: This code has no safeguard for ensuring that LCM is respectably small. If you give it stupid values for the alphabet and modulo, you will blow up your javascript. Not my fault you tried to multiply a massive prime number with another.

I should clarify a bit because i realized i reused a term there.

For the original example, the LCM is 24, the alphabet length is 8, and the modulo is 6.

The pattern length of an interlaced modulo is 2 times the modulo.
The number of times you will cycle through the pattern is LCM / Pattern Length.
During those cycles, you will cycle through the alphabet LCM / Alphabet Length times.

So for the original problem, there will be 2 (24 / (6*2)) pattern cycles.
There will be 3 (24 / 8) alphabet cycles. So you would expect the pattern to end with H3.