A333464
Number of self-avoiding walks from NW to SE corners on an n X n grid which pass through all points on the diagonal connecting NE and SW corners.
Original entry on oeis.org
1, 0, 2, 20, 752, 84008, 29145982, 30795358024, 99417240957788
Offset: 1
a(3) = 2;
S--*--+ S *--+
| | | |
*--+--* * + *
| | | |
+--*--E +--* E
a(4) = 20;
S--*--*--+ S--*--*--+ S--*--*--+
| | |
*--*--+--* *--*--+--* *--* +--*
| | | | |
* +--* * +--*--* * +--*
| | | | | | |
+--* *--E +--* E +--*--*--E
S--*--*--+ S--*--*--+ S--*--*--+
| | |
*--+--* *--+--* *--+ *
| | | | |
*--+ *--* *--+ *--+ *--*
| | | | |
+--*--* E +--*--*--E +--*--*--E
S--*--*--+ S--* *--+ S--* *--+
| | | | | | |
+--* *--* + * *--+ *
| | | | |
*--+--* * +--* * *--+--*--*
| | | | |
+--*--*--E +--* E +--*--*--E
S--* *--+ S *--*--+ S *--*--+
| | | | | | | | |
* + * *--* +--* * *--+ *
| | | | | | |
*--+ * * *--+--* * +--* *
| | | | | | |
+--*--* E +--*--*--E +--* E
S *--*--+ S *--*--+ S *--+
| | | | | | | | |
* * +--* * * +--* *--*--+ *
| | | | | | |
* + * * + *--* *--+--*--*
| | | | | | |
+--* *--E +--* E +--*--*--E
S *--+ S *--+ S *--+
| | | | | | | | |
*--* + * * *--+ * * *--+ *
| | | | | | | | |
*--+ * * * +--* * * + *--*
| | | | | | | | |
+--*--* E +--*--* E +--* *--E
S *--+ S *--+
| | | | | |
* *--+ * * + *
| | | | | |
* + * * +--* *
| | | | | |
+--* E +--* E
-
# Using graphillion
from graphillion import GraphSet
import graphillion.tutorial as tl
def A333464(n):
if n == 1: return 1
universe = tl.grid(n - 1, n - 1)
GraphSet.set_universe(universe)
start, goal = 1, n * n
paths = GraphSet.paths(start, goal)
for i in range(n):
paths = paths.including((n - 1) * (i + 1) + 1)
return paths.len()
print([A333464(n) for n in range(1, 10)])
-
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 == n - 1 && y == n - 1 && (0..n - 1).all?{|i| used[(n - 1) * (i + 1)] == 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 == 1
@move = [[1, 0], [-1, 0], [0, 1], [0, -1]]
used = Array.new(n * n, false)
search(0, 0, n, used)
end
def A333464(n)
(1..n).map{|i| A(i)}
end
p A333464(6)
A333795
Number of self-avoiding closed paths on an n X n grid which pass through all points on the two diagonals of the grid.
Original entry on oeis.org
1, 0, 6, 68, 6102, 1404416, 1094802826, 2524252113468
Offset: 2
a(2) = 1;
+--+
| |
+--+
a(4) = 6;
+--*--*--+ +--*--*--+ +--*--*--+
| | | | | |
*--+--+ * *--+ +--* * +--+--*
| | | | | |
*--+--+ * *--+ +--* * +--+--*
| | | | | |
+--*--*--+ +--*--*--+ +--*--*--+
+--*--*--+ +--* *--+ +--* *--+
| | | | | | | | | |
* +--+ * * +--+ * * + + *
| | | | | | | | | |
* + + * * +--+ * * +--+ *
| | | | | | | | | |
+--* *--+ +--* *--+ +--*--*--+
-
# Using graphillion
from graphillion import GraphSet
import graphillion.tutorial as tl
def A333795(n):
universe = tl.grid(n - 1, n - 1)
GraphSet.set_universe(universe)
cycles = GraphSet.cycles()
points = [i + 1 for i in range(n * n) if i % n - i // n == 0 or i % n + i // n == n - 1]
for i in points:
cycles = cycles.including(i)
return cycles.len()
print([A333795(n) for n in range(2, 10)])
A333796
Number of self-avoiding closed paths on an n X n grid which pass through all points on the diagonal connecting NW and SE corners.
Original entry on oeis.org
1, 2, 22, 716, 73346, 23374544, 23037365786, 69630317879888
Offset: 2
a(2) = 1;
+--*
| |
*--+
a(3) = 2;
+--*--* +--*
| | | |
*--+ * * +--*
| | | |
*--+ *--*--+
a(4) = 22;
+--*--*--* +--*--*--* +--*--*--*
| | | | | |
*--+--* * *--+--* * *--+--* *
| | | | | |
*--*--+ * *--+ * + *
| | | | | |
*--*--*--+ *--*--+ *--+
+--*--*--* +--*--*--* +--*--*--*
| | | | | |
*--+ *--* *--+ *--* *--+ *
| | | | | |
*--* +--* * +--* *--+ *
| | | | | |
*--*--*--+ *--*--+ *--+
+--*--*--* +--*--*--* +--*--*--*
| | | | | |
* +--*--* * +--* * * +--* *
| | | | | | | | | |
* *--+--* *--* + * * * + *
| | | | | | | |
*--*--*--+ *--+ *--* *--+
+--*--* +--*--* +--*--*
| | | | | |
*--+ *--* *--+ * *--+ *
| | | | | |
*--+ * *--* +--* * +--*
| | | | | |
*--+ *--*--*--+ *--*--+
+--*--* +--* *--* +--* *--*
| | | | | | | | | |
* +--* * +--* * * +--* *
| | | | | |
* *--+--* *--*--+ * * *--+ *
| | | | | | | |
*--*--*--+ *--+ *--* *--+
+--* *--* +--* +--*
| | | | | | | |
* + * * * +--*--* * +--*--*
| | | | | | | |
* *--+ * *--*--+ * * *--+ *
| | | | | | | |
*--*--*--+ *--+ *--* *--+
+--* +--* +--*
| | | | | |
* +--* * +--* * + *--*
| | | | | | | |
*--* +--* * +--* * *--+ *
| | | | | |
*--*--+ *--*--*--+ *--*--*--+
+--*
| |
* +
| |
* *--+--*
| |
*--*--*--+
-
# Using graphillion
from graphillion import GraphSet
import graphillion.tutorial as tl
def A333796(n):
universe = tl.grid(n - 1, n - 1)
GraphSet.set_universe(universe)
cycles = GraphSet.cycles()
points = [i + 1 for i in range(n * n) if i % n - i // n == 0]
for i in points:
cycles = cycles.including(i)
return cycles.len()
print([A333796(n) for n in range(2, 10)])
Showing 1-3 of 3 results.
Comments