Skip to content

Instantly share code, notes, and snippets.

@kohske
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save kohske/f7fd450072d293de57b3 to your computer and use it in GitHub Desktop.

Select an option

Save kohske/f7fd450072d293de57b3 to your computer and use it in GitHub Desktop.
Gaykutan.R
# http://blog.goo.ne.jp/r-de-r/e/c9cc759642ea0c02560bd08c975fb156
b = 0.111111 * 1:9 # b は 0.111111 ~ 0.999999 の 9 種類
bz = b+0.000001
b2 = 2 * b
bz2 = 2*bz
b.sq = b ^ 2
bz.sq = bz ^ 2
n = 10000 # 探索範囲上限
ansa = c()
for (a in 1:n) {
x = a * b2 + b.sq
xz = a * bz2 + bz.sq
pp = floor(xz) - floor(x) - (xz == round(xz))
if (any(pp > 0)) {
ans = (a+b[which(pp>0)])^2
ansa = c(ansa, ans)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment