@Lembik True, but if two sets of code magically end up with the same set of numbers, you can be more sure that they are accurate. You can never be sure that they are actually accurate
@NathanMerrill If you want statistically relevant results then you need to run each matchup dozens of times, not twice. And there are a few typos which need fixing. Other than that, I think it's almost ready. What's missing is the strongly recommended link to the test framework.
@lembik thanks for reminding me about pypy. I'll run it to get some higher values of N when I'm back at a computer. Can I use pypy for the score too? I hadn't thought of that before.
Convert a Finite State Machine to a Regular Expression
Anyone can make a finite state machine for matching a regular expression. But what about a regular expression that emulates a finite state machine? This inverse operation is much more confusing.
Input
A positive integer N, denoting the nu...
public class RandomOutOfBoundsException extends Exception {}
public class MyRandom extends Random {
private final long seed;
private int count;
public MyRandom(long seed) {
this.seed = seed;
this.setSeed(seed);
count = 0;
}
public int nextInt() {
count++;
return super.nextInt();
}
public int previousInt() throws RandomOutOfBoundsException {
if (count < 1)
throw new RandomOutOfBoundsException();
count--;
@NathanMerrill Works like a charm ^
It's pretty ugly. If you called nextInt() a million times in a row and then called previousInt(), then it would have to loop a million minus one times to give you what you want.
How about this? Use the seed as the position on the number line. nextInt() adds 1 to the seed and grabs the first number from the RNG, prevInt() decrements the seed, etc.
public class MyRandom extends Random{
long seed;
public MyRandom(long seed){
this.seed = seed;
}
public int nextInt(){
super.setSeed(++seed);
return super.nextInt();
}
public int prevInt(){
super.setSeed(--seed);
return super.nextInt();
}
}
@Lembik good news - I've added an extra test case that has start and finish arrangements non-intersecting but involves a single step that intersects during the move, and it's correctly rejecting it.
It's a length 10 snake but the two states are interchangeable just not in one step, so it's still possible the sequence may overlap with the no-intersections sequence you found, for the first few n
@Geobits That class seems to return numbers that are very close together run: ---Going forwards--- -1190881475 -1191266224 -1190111977 -1190496726 -1106236717 -1106621466 ---Going backwards--- -1106236717 -1190496726 -1190111977 -1191266224 -1190881475 -1188957731 BUILD SUCCESSFUL (total time: 0 seconds)
It looks like seeds that are very close together produce numbers that are also very close together
I had a feeling that would be the case (or at least not very well distributed). That's why I added that note to self ;)
I don't know if it only applies to the upper bits, though,. If the lower bits are evenly distributed, you might still be able to use a variation for small numbers.
Random.previousInt()
Consider a number line where each spot has a random integer. You will implement this line with 3 functions: setSeed(), nextInt(), and previousInt(). Your goal is to implement the line such that:
The randomness is deterministic. Calling setSeed(x) then nextInt() should al...
Random.previousInt()
Consider a number line where each spot has a random integer. You will implement this line with 3 functions: setSeed(), nextInt(), and previousInt(). Your goal is to implement the line such that:
The randomness is deterministic. Calling setSeed(x) then nextInt() should al...
I don't think I ever wanted to print"" (in those cases I usually want to print literally nothing)... but some people do give you a hard time for printing arrays like "" instead of []
well. there are very less questions asking to print [] and then there are ever lesser people giving hard time when you print "", so I think it might reach the same number as questions requiring you to print ""
but you want to add new features which work similarly (like the vector operations), so I'm afraid if you do it this way round they'll probably have the same issue ;)
@Doorknob two things... a) I take it you haven't heard any news regarding MathJax after the negative feedback Jon Ericson got? (just checking) b) When will tips be un-CW-ed? ;)