A333466 Number of self-avoiding closed paths on an n X n grid which pass through four corners ((0,0), (0,n-1), (n-1,n-1), (n-1,0)).
1, 1, 11, 373, 44930, 17720400, 22013629316, 84579095455492
Offset: 2
Examples
a(2) = 1; +--+ | | +--+ a(3) = 1; +--*--+ | | * * | | +--*--+ a(4) = 11; +--*--*--+ +--*--*--+ +--*--*--+ | | | | | | *--*--* * *--* *--* *--* * | | | | | | *--*--* * *--* *--* *--* * | | | | | | +--*--*--+ +--*--*--+ +--*--*--+ +--*--*--+ +--*--*--+ +--*--*--+ | | | | | | * *--*--* * *--* * * *--* | | | | | | | | * *--*--* * * * * * *--* | | | | | | | | +--*--*--+ +--* *--+ +--*--*--+ +--*--*--+ +--*--*--+ +--* *--+ | | | | | | | | * * * * * *--* * | | | | | | * *--* * * * * *--* * | | | | | | | | | | +--* *--+ +--*--*--+ +--* *--+ +--* *--+ +--* *--+ | | | | | | | | * *--* * * * * * | | | | | | * * * *--* * | | | | +--*--*--+ +--*--*--+
Programs
-
Python
# Using graphillion from graphillion import GraphSet import graphillion.tutorial as tl def A333466(n): universe = tl.grid(n - 1, n - 1) GraphSet.set_universe(universe) cycles = GraphSet.cycles() for i in [1, n, n * (n - 1) + 1, n * n]: cycles = cycles.including(i) return cycles.len() print([A333466(n) for n in range(2, 10)])
-
Ruby
def search(x, y, n, used) return 0 if x < 0 || n <= x || y < 0 || n <= y || used[x + y * n] return 1 if x == 0 && y == 1 && [n - 1, n * (n - 1), n * n - 1].all?{|i| used[i] == true} cnt = 0 used[x + y * n] = true @move.each{|mo| cnt += search(x + mo[0], y + mo[1], n, used) } used[x + y * n] = false cnt end def A(n) return 1 if n < 3 @move = [[1, 0], [-1, 0], [0, 1], [0, -1]] used = Array.new(n * n, false) search(0, 0, n, used) end def A333466(n) (2..n).map{|i| A(i)} end p A333466(6)
Comments