Last active
September 13, 2015 13:53
-
-
Save mizdra/c700bbf2d4379adf16d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* OS: Windows 7 | |
* CPU: i7-2670QM 2.20GHz 4コア 8スレッド | |
* RAM: 8GB | |
* 計算時間: 10分59秒 | |
*/ | |
#include <algorithm> | |
#include <iostream> | |
typedef uint32_t u32; | |
using namespace std; | |
u32 count_skip(u32 s_2, u32 nature); | |
u32 next_seed(u32 seed); | |
u32 calc_nature(u32 s_lid, u32 s_hid); | |
/* | |
* | |
*/ | |
int main() { | |
u32 s_2 = 0; | |
u32 max_skip = 0; // S[n+2] | |
// S[n+2]の総当り計算 | |
do { | |
u32 nature = (s_2 >> 16) % 25; // r[n+2] % 25 | |
max_skip = max(max_skip, count_skip(s_2, nature)); | |
s_2++; | |
} while (s_2 != 0); // 0x100000000が桁あふれして0になる | |
cout << max_skip << endl; | |
return 0; | |
} | |
u32 count_skip(u32 s_2, u32 nature) { | |
u32 s_lid = next_seed(s_2); | |
u32 s_hid = next_seed(s_lid); | |
u32 skip = 0; | |
while (calc_nature(s_lid, s_hid) != nature) { | |
s_lid = next_seed(s_hid); | |
s_hid = next_seed(s_lid); | |
skip++; | |
} | |
return skip; | |
} | |
u32 next_seed(u32 seed) { | |
return seed * 0x41c64e6d + 0x6073; | |
} | |
u32 calc_nature(u32 s_lid, u32 s_hid) { | |
u32 pid = (s_hid & 0xFFFF0000) | (s_lid >> 16); | |
return pid % 25; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* OS: Windows 7 CPU: i7-2670QM 2.20GHz 4コア 8スレッド RAM: 8GB 計算時間: 12分6秒 | |
*/ | |
public class PIDSkipCounter { | |
private static final int METHOD = 3; // 1, 3に対応 | |
private static final boolean SYNCHRONIZE = false; // trueでシンクロ適用 | |
private static final int SYNCHRONIZE_NATURE = 0; // シンクロポケモンの性格 | |
public static void main(String[] args) { | |
System.out.println("Method: " + METHOD); | |
System.out.println("SYNCHRONIZE: " + SYNCHRONIZE); | |
System.out.println("SYNCHRONIZE_NATURE: " + SYNCHRONIZE_NATURE); | |
int max = 0; | |
int s_2 = 0; // S[n+2] | |
int nature; | |
// S[n+2]の総当り計算 | |
do { | |
if (SYNCHRONIZE) { // シンクロ有り | |
if ((s_2 >>> 16) % 1 == 0) { // 成功 | |
nature = SYNCHRONIZE_NATURE; | |
} else { // 失敗 | |
s_2 = nextSeed(s_2); | |
nature = (s_2 >>> 16) % 25; | |
} | |
} else { // シンクロ無し | |
nature = (s_2 >>> 16) % 25; // r[n+2] % 25 | |
} | |
max = Math.max(max, countSkip(s_2, nature)); | |
s_2++; | |
} while (s_2 != 0); // 0x100000000が桁あふれして0になる | |
System.out.println("Max: " + max); | |
} | |
private static int countSkip(int s_2, int nature) { | |
int s_lid = nextSeed(s_2); | |
int s_hid = nextSeed(s_lid); | |
int skip = 0; | |
while (calcNature(s_lid, s_hid) != nature) { | |
s_lid = nextSeed(s_hid); | |
s_hid = nextSeed(s_lid); | |
if (METHOD == 3) | |
s_hid = nextSeed(s_hid); | |
skip++; | |
} | |
return skip; | |
} | |
private static int calcNature(int s_lid, int s_hid) { | |
int pid = (s_hid & 0xFFFF0000) | (s_lid >>> 16); | |
return Integer.remainderUnsigned(pid, 25); // pid % 25 | |
} | |
private static int nextSeed(int seed) { | |
return seed * 0x41c64e6d + 0x6073; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment