Skip to content

Instantly share code, notes, and snippets.

@m1el
Created December 11, 2018 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m1el/72a020bad2d7d8001170f44771f2d004 to your computer and use it in GitHub Desktop.
Save m1el/72a020bad2d7d8001170f44771f2d004 to your computer and use it in GitHub Desktop.
id = 8772
def powl(id, x,y):
return (((x+10)*y+id)*(x+10) // 100) % 10 - 5
grid = [0]*(300*300)
for y0 in range(300):
for x0 in range(300):
c = x0 + y0*300
grid[c] = powl(id, x0+1,y0+1)
ms = 0
mc = (0,0,0)
sums = [0]*(300*300)
for sz in range(300):
for y in range(300-sz):
for x in range(300-sz):
cd = x + y*300
cs = x + sz + (y+sz)*300
sums[cd] += grid[cs]
for dx in range(sz):
cs = x+dx+(y+sz)*300
sums[cd] += grid[cs]
for dy in range(sz):
cs = x+sz+(y+dy)*300
sums[cd] += grid[cs]
if sums[cd] > ms:
ms = sums[cd]
mc = (x+1,y+1,sz+1)
print(sz,ms,mc)
print(ms,mc)
fn main() {
fn powl(id: isize, x: isize, y: isize) -> isize {
(((x+10)*y+id)*(x+10) / 100) % 10 - 5
}
let id = 8772;
let start = std::time::Instant::now();
let mut grid = vec![0; 300*300];
for y in 0..300 {
for x in 0..300 {
let c = x + y*300;
grid[c] = powl(id, (x+1) as isize,(y+1)as isize);
}
}
let mut ms = 0;
let mut mc = (0,0,0);
let mut sums = vec![0; 300*300];
for sz in 0..300 {
for y in 0..300-sz {
for x in 0..300-sz {
let cd = x+y*300;
let cs = (x+sz)+(y+sz)*300;
sums[cd] += grid[cs];
for dx in 0..sz {
let cs = (x+dx)+(y+sz)*300;
sums[cd] += grid[cs];
}
for dy in 0..sz {
let cs = (x+sz)+(y+dy)*300;
sums[cd] += grid[cs];
}
if sums[cd] > ms {
ms = sums[cd];
mc = (x+1,y+1,sz+1);
}
}
}
println!("sz: {}, mc: {:?}", sz, mc);
}
println!("mc: {:?}", mc);
println!("elapsed: {:?}", start.elapsed());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment