A cleaned example of the code at present:
Code: Select all
[h: status = input(
"input|10|User input"
)]
[h: abort(status)]
[h: input= max(min(input, 25), 0)]
[h: shortList = ""]
[h: elem1 = ""]
[h: elem2 = ""]
[h: elements = ""]
[h: index = 0]
[h, count(input), code:
{
[h: index = index + 1]
[h, if(1d100 <= 50): elem1 = "AAA"; elem1 = ""]
[h, if(1d100 <= 50): elem2 = "BBB"; elem2 = ""]
[h, if(elem1 != ""): shortList = listAppend(shortList, elem1)]
[h, if(elem2 != ""): shortList = listAppend(shortList, elem2)]
[h, if(shortList == ""): shortList = "Null"]
[h: elements = elements + "<font color='red'>Res " + string(index) + ": <font color='black'>" + shortList + if(index < input, "; ", "")]
[h: shortList = ""]
}]
[r: elements]
I mean, if the iterations are 25, it should produce 5 rows with 5 cells each (5 x 5 = 25); if the iterations are 9, it should produce 3 rows with 3 cells each (3 x 3 = 9), and so on. In case of a number of iterations that doesn't have an integer square root, it would use the closest higher number of cells and the closest lower number of rows, with the last cells being empty (for example, 18 iterations would produce a 5 cells x 4 rows table, where the last two cells of the last row are empty; or 6 iterations would produce a 3 x 2 table... always the closest possible to a square, but not with unnecessary rows that would be fully empty).
The problem is my mind gets very messy, when I try it out... any more mathematical mind than mine who can help?