Maybe statements should show more numbers for sample generation. That helps with overflow bugs check.
Iām getting the same values, 44, 25 then 42, 14 and so on. Maybe Iām missing something basic but could you explain how 44 is occupied?
Hello all,
Iām trying to make this challenge but my mines donāt get same position that example and i donāt know why.
First mines get is number 7 and last is 1, x is for the start of player :
. 7 . . 1 .
. . . . 2 .
. . . . . .
. . . x . 5
. 6 . . . .
. . 4 . 3 .
To generate mines, I reroll this until I have a valid position.
while (minesRemaining > 0) {
int x1 = nextValue(width);
int y1 = nextValue(height); }
My problem is here but how to generate position if itās not thatā¦
Thank you for helping me in advance
@Lycast I think I had this result first as well, before I noticed that my calculation of the next 32bit value of the RNG was not correct. I had an intermediate value that went beyond the 32bit range. Maybe that helps?
Hello @MarcoT,
Thank you and yes I think that was it.
I am looking in JAVA how to respect this calculation.
Have a good day
unsigned int PRNG(unsigned int s){
return (214013 * s+ 2531011 / 65536);
}
does not give the correct numbers
PRNG(31) = 642077
Something is wrong, anyone has an idea ?
Maybe an overflow, try with unsigned long long.
@Razovsky The right parenthesis is misplaced, it should be (214013*s + 2531011) / 65536
(or equivalently >> 16
).
Right, iām dumb, thanks, i fixed itā¦ Iām ashamed, blocked 2 hours by this, lol
I canāt have the same mine positions as in the testcases. The first mines are correct, but then theyāre completely different, except for testcases ācorner selectionā and ābeginner levelā.
I generate numbers with this python code : RD = ((214013*RD+2531011)%2**32)//65536
Iām currently successful for all test cases except the expert level.
When placing mine # 77 it tries to place it at (x: 15, y: 7).
Which is wrong according to the example.
Even though Iāve magiced up the PRNG for uint32s (and it seems to work for all but the biggest test case), something still failsā¦
Iām using TypeScript. (Yes, not ideal for floatsā¦ I could choose a different language, but whereās the fun in thatā¦)
function prng(seed: number): number {
return Math.floor(((214013 * seed + 2531011) % 2**32) / 65536);
}
For every time I try to place a mine, the PRNG is called twice (with obviously the āpreviousā result as seed).
If the result (x, y) is out of bounds, or it falls on a mine and/or starting 3x3, I just continue, ignoring BOTH previous results.
Someone has any ideas where to continue looking?
Hi,
(x: 15, y: 7) are the good values the PRNG should get you when you try to place the #77, it canāt be placed there because the coordinates of the first selected cell is (x: 15, y: 8).
First thought was āno that canāt be, that code worksā¦ Itās tested in the other test casesā¦ā
Well, of course there is 4 directions this could āfailā inā¦
Thanks for pointing me in the right direction!
y >= yStart  1 &&
y <= yStart + 1 &&
x >= xStart  1 &&
x <= yStart + 1 // <
Hello,
I made a code that work for the 5 first case but not the expert case.
I canāt seem to find the issue.
I get the error : free(): invalid pointer
Thanks
For the First test : mines = 7
i >= 0
row = R(2 * i + 1) mod Height
col = R(2 * i + 2) mod Width

for i = 0 : row: 0, col : 1

for i = 1 : row: 4, col : 1

for i = 2 : row: 3, col : 5

for i = 3 : row: 4, col : 2
Rejected (The 3x3 cells square centered on the cell (y,x) is always set free of mines.) 
for i = 4 : row: 0, col : 4

for i = 5 : row: 2, col : 2
Rejected (The 3x3 cells square centered on the cell (y,x) is always set free of mines.) 
for i = 6 : row: 4, col : 3
Rejected (The 3x3 cells square centered on the cell (y,x) is always set free of mines.) 
for i = 7 : row: 4, col : 4
Rejected (The 3x3 cells square centered on the cell (y,x) is always set free of mines.) 
for i = 8 : row: 4, col : 1
Rejected (This sell have already a mine ) 
for i = 9 : row: 2, col : 2
Rejected (The 3x3 cells square centered on the cell (y,x) is always set free of mines.) 
for i = 10 : row: 2, col : 0

for i = 11 : row: 0, col : 3

for i = 12 : row: 4, col : 0
after collecting 7 Mines we stop generating them
Iām working in C#, and have been struggling with this all day, trying to create a list of random numbers.
Can someone give me a hint, or point me to a good YouTube video that will help me understand.
public static void PopulateRandos(int seed)
{
Randos.Add(seed);
for (int i = 1 ; i < 100; i++)
{
int prev = Randos[i1];
double temp = 214013 * prev + 2531011;
temp = temp % Math.Pow(2,32);
temp = temp / 65536;
temp = Math.Abs(temp);
Randos.Add((int)temp);
}
}
I think itās the part about āAll calculations must be in 32bit unsigned numbersā that is confusing me.
An unsigned integer has a limited range which does not allow big numbers.
I tried your proposition vs an unsigned int working solution. Through the calcul, using the seed from test 1, i see that when my unsigned int seed gets reduced, your double continues to grow.
For example, using R(n) = (214013 * R(n1) + 2531011) / 65536, R(57855) should be 57896 with R(n1) and R(n) being unsigned int.
What i suppose is that the variable size limitation can occur at different steps of the calculation:
 when you multiply the seed by 214013
 when you add 2531011
I suppose that in most cases, variable type unsigned int limits at the first step of the calcul, which is the multiplication, and not the addition as you seem to consider in your code. However, you canāt be sure of that. Which makes your way of doing more complicated.
And as unsigned int is, well, unsigned, the āabs()ā function of a double (signed variable) canāt give you a right answer (supposing you got the right ātempā value until there).
I would suggest you two things:
 either you use unsigned int variables, which would simplify your problem because you just have to write R(n) = (214013 * R(n1) + 2531011) / 65536 without adding anything
 or you keep it your way, however i would suggest some changes :
First use an unsigned variable type and remove this abs() step, which will not give anything right anyway
Then try to use the modulus operator % pow(2,32) after the multiplication, then add 2531011 and reuse the modulus, to be sure. But i canāt tell you if this will work.
Hope i helped you, donāt hesitate to ask more questions.
Note: I work in C++ so i donāt know if what i say is similar in C#, specially variable types definition.
I guess C# is similar to Java that it has no unsigned int types.
(1)
You can use int or long, but never float or double when you have to deal with integers.
I would use long.
(2)
value of Math.Pow(2,32) can be defined as a constant
Why recalculate it 100 times in a tight loop?
(3) abs()
unsigned type does not have negative values anyway. Meaningless to abs it
Razovsky and java_coffee_cup āThanks for the replys.
Leaving some notes for future players:
It turns out I needed to learn more about āunsigned integersā, and that that type is āuintā in C#. (I have some gaps in my knowledge, it seems)
All the suggestions in the forum about āmod 2**32ā donāt seem to apply at all to C#, as far as I can tell.
Finally, it works. Great educational puzzle; Minesweeper is complete