In this puzzle each empty square needs to be filled in with a different positive integer 1 to 40.
The rules are the same as the
first sequence fill in and are:
Each string of adjacent squares needs to form an arithmetic sequence.
A horizontal string of squares increases from left to right.
A vertical string of squares increases from top to bottom.
The following program uses single letters a - l to represent intersection values and single letters appended with v or h to represent vertical or horizontal increments involving those intersections, and appended with p (for prime) to represent another intersection's value along the line:
CLS
DIM g(8, 10), used(40)
FOR a = 1 TO 35
g(1, 3) = a
used(a) = 1
FOR ah = 1 TO 13
IF a + 3 * ah > 40 THEN EXIT FOR
g(1, 4) = a + ah: used(a + ah) = 1
g(1, 5) = a + 2 * ah: used(a + 2 * ah) = 1
g(1, 6) = a + 3 * ah: used(a + 3 * ah) = 1
FOR av = 1 TO 13
IF a + 3 * av > 40 THEN EXIT FOR
IF (used(a + av) OR used(a + 2 * av) OR used(a + 3 * av)) = 0 THEN
g(2, 3) = a + av: used(a + av) = 1
g(3, 3) = a + 2 * av: used(a + 2 * av) = 1
g(4, 3) = a + 3 * av: used(a + 3 * av) = 1
ap = a + 3 * ah
FOR bv = 1 TO 20
IF ap + 2 * bv > 40 THEN EXIT FOR
IF (used(ap + bv) OR used(ap + 2 * bv)) = 0 THEN
g(2, 6) = ap + bv: used(ap + bv) = 1
g(3, 6) = ap + 2 * bv: used(ap + 2 * bv) = 1
b = ap + 2 * bv
FOR bh = 1 TO 20
IF b + 2 * bh > 40 THEN EXIT FOR
IF (used(b + bh) OR used(b + 2 * bh)) = 0 THEN
g(3, 7) = b + bh: used(b + bh) = 1
g(3, 8) = b + 2 * bh: used(b + 2 * bh) = 1
bp = b + 2 * bh
FOR cv = 1 TO 13
IF bp + 2 * cv > 40 OR bp - cv < 1 THEN EXIT FOR
IF (used(bp - cv) OR used(bp + cv) OR used(bp + 2 * cv)) = 0 THEN
g(2, 8) = bp - cv: used(bp - cv) = 1
g(4, 8) = bp + cv: used(bp + cv) = 1
g(5, 8) = bp + 2 * cv: used(bp + 2 * cv) = 1
c = bp - cv
FOR ch = 1 TO 20
IF c + 2 * ch > 40 THEN EXIT FOR
IF (used(c + ch) OR used(c + 2 * ch)) = 0 THEN
g(2, 9) = c + ch: used(c + ch) = 1
g(2, 10) = c + 2 * ch: used(c + 2 * ch) = 1
cp = bp + 2 * cv
FOR dh = 1 TO 20
IF cp + 2 * dh > 40 OR cp - dh < 1 THEN EXIT FOR
IF (used(cp - dh) OR used(cp + dh) OR used(cp + 2 * dh)) = 0 THEN
g(5, 7) = cp - dh: used(cp - dh) = 1
g(5, 9) = cp + dh: used(cp + dh) = 1
g(5, 10) = cp + 2 * dh: used(cp + 2 * dh) = 1
d = cp - dh
FOR dv = 1 TO 20
IF d + 2 * dv > 40 THEN EXIT FOR
IF (used(d + dv) OR used(d + 2 * dv)) = 0 THEN
g(6, 7) = d + dv: used(d + dv) = 1
g(7, 7) = d + 2 * dv: used(d + 2 * dv) = 1
dp = cp + 2 * dh
FOR ev = 1 TO 20
IF dp + 2 * ev > 40 OR dp - ev < 1 THEN EXIT FOR
IF (used(dp - ev) OR used(dp + ev) OR used(dp + 2 * ev)) = 0 THEN
g(4, 10) = dp - ev: used(dp - ev) = 1
g(6, 10) = dp + ev: used(dp + ev) = 1
g(7, 10) = dp + 2 * ev: used(dp + 2 * ev) = 1
f = d + 2 * dv
FOR fh = 1 TO 39
IF f + fh > 40 OR f - fh < 1 THEN EXIT FOR
IF (used(f - fh) OR used(f + fh)) = 0 THEN
g(7, 6) = f - fh: used(f - fh) = 1
g(7, 8) = f + fh: used(f + fh) = 1
hp = a + 3 * av
FOR hh = 1 TO 39
IF hp + hh > 40 OR hp - hh < 1 THEN EXIT FOR
IF (used(hp - hh) OR used(hp + hh)) = 0 THEN
g(4, 2) = hp - hh: used(hp - hh) = 1
g(4, 4) = hp + hh: used(hp + hh) = 1
h = hp - hh
FOR hv = 1 TO 20
IF h + 2 * hv > 40 THEN EXIT FOR
IF (used(h + hv) OR used(h + 2 * hv)) = 0 THEN
g(5, 2) = h + hv: used(h + hv) = 1
g(6, 2) = h + 2 * hv: used(h + 2 * hv) = 1
i = h + 2 * hv
FOR jh = 1 TO 20
IF i + 2 * jh > 40 OR i - jh < 1 THEN EXIT FOR
IF (used(i - jh) OR used(i + jh) OR used(i + 2 * jh)) = 0 THEN
g(6, 1) = i - jh: used(i - jh) = 1
g(6, 3) = i + jh: used(i + jh) = 1
g(6, 4) = i + 2 * jh: used(i + 2 * jh) = 1
j = i - jh
FOR jv = 1 TO 20
IF j + 2 * jv > 40 THEN EXIT FOR
IF (used(j + jv) OR used(j + 2 * jv)) = 0 THEN
g(7, 1) = j + jv: used(j + jv) = 1
g(8, 1) = j + 2 * jv: used(j + 2 * jv) = 1
jp = i + jh
FOR lv = 1 TO 20
IF jp + 2 * lv > 40 THEN EXIT FOR
IF (used(jp + lv) OR used(jp + 2 * lv)) = 0 THEN
g(7, 3) = jp + lv: used(jp + lv) = 1
g(8, 3) = jp + 2 * lv: used(jp + 2 * lv) = 1
l = jp + 2 * lv
FOR lh = 1 TO 13
IF l + 3 * lh > 40 THEN EXIT FOR
IF (used(l + lh) OR used(l + 2 * lh) OR used(l + 3 * lh)) = 0 THEN
g(8, 4) = l + lh: used(l + lh) = 1
g(8, 5) = l + 2 * lh: used(l + 2 * lh) = 1
g(8, 6) = l + 3 * lh: used(l + 3 * lh) = 1
GOSUB pIt
FOR iii = 1 TO 40: PRINT used(iii); : NEXT:
PRINT
PRINT ah; av; bv; bh; cv; ch; dh; dv; ev; fh; hh; hv; jh; jv; lv; lh;
PRINT : PRINT
used(l + lh) = 0
used(l + 2 * lh) = 0
used(l + 3 * lh) = 0
END IF
NEXT lh
used(jp + lv) = 0
used(jp + 2 * lv) = 0
END IF
NEXT lv
used(j + jv) = 0
used(j + 2 * jv) = 0
END IF
NEXT jv
used(i - jh) = 0
used(i + jh) = 0
used(i + 2 * jh) = 0
END IF
NEXT jh
used(h + hv) = 0
used(h + 2 * hv) = 0
END IF
NEXT hv
used(hp - hh) = 0
used(hp + hh) = 0
END IF
NEXT hh
used(f - fh) = 0
used(f + fh) = 0
END IF
NEXT fh
used(dp - ev) = 0
used(dp + ev) = 0
used(dp + 2 * ev) = 0
END IF
NEXT ev
used(d + dv) = 0
used(d + 2 * dv) = 0
END IF
NEXT dv
used(cp - dh) = 0
used(cp + dh) = 0
used(cp + 2 * dh) = 0
END IF
NEXT dh
used(c + ch) = 0
used(c + 2 * ch) = 0
END IF
NEXT ch
used(bp - cv) = 0
used(bp + cv) = 0
used(bp + 2 * cv) = 0
END IF
NEXT cv
used(b + bh) = 0
used(b + 2 * bh) = 0
END IF
NEXT bh
used(ap + bv) = 0
used(ap + 2 * bv) = 0
END IF
NEXT bv
used(a + av) = 0
used(a + 2 * av) = 0
used(a + 3 * av) = 0
END IF
NEXT av
used(a + ah) = 0
used(a + 2 * ah) = 0
used(a + 3 * ah) = 0
NEXT ah
used(a) = 0
NEXT a
END
pIt:
FOR row = 1 TO 8: FOR col = 1 TO 10
amt = g(row, col)
IF amt = 0 THEN
PRINT " ";
ELSE
PRINT USING "## "; amt;
END IF
NEXT: PRINT : NEXT: PRINT
RETURN
It results in the following two solutions:
1 2 3 4
5 6 15 24 33
9 8 14 20
10 13 16 25 37
11 26 30 34 38
7 12 17 22 29 39
21 18 28 32 36 40
35 19 23 27 31
and
1 2 3 4
7 6 5 17 29
13 8 9 10
14 19 24 15 34
16 12 20 28 36
11 18 25 32 21 38
22 26 23 30 37 40
33 27 31 35 39
|
Posted by Charlie
on 2007-11-30 17:06:15 |