Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Cut-a-rectangle/Common-Lisp/cut-a-rectangle-1.lisp
Normal file
43
Task/Cut-a-rectangle/Common-Lisp/cut-a-rectangle-1.lisp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(defun cut-it (w h &optional (recur t))
|
||||
(if (oddp (* w h)) (return-from cut-it 0))
|
||||
(if (oddp h) (rotatef w h))
|
||||
(if (= w 1) (return-from cut-it 1))
|
||||
|
||||
(let ((cnt 0)
|
||||
(m (make-array (list (1+ h) (1+ w))
|
||||
:element-type 'bit
|
||||
:initial-element 0))
|
||||
(cy (truncate h 2))
|
||||
(cx (truncate w 2)))
|
||||
|
||||
(setf (aref m cy cx) 1)
|
||||
(if (oddp w) (setf (aref m cy (1+ cx)) 1))
|
||||
|
||||
(labels
|
||||
((walk (y x turned)
|
||||
(when (or (= y 0) (= y h) (= x 0) (= x w))
|
||||
(incf cnt (if turned 2 1))
|
||||
(return-from walk))
|
||||
|
||||
(setf (aref m y x) 1)
|
||||
(setf (aref m (- h y) (- w x)) 1)
|
||||
(loop for i from 0
|
||||
for (dy dx) in '((0 -1) (-1 0) (0 1) (1 0))
|
||||
while (or turned (< i 2)) do
|
||||
(let ((y2 (+ y dy))
|
||||
(x2 (+ x dx)))
|
||||
(when (zerop (aref m y2 x2))
|
||||
(walk y2 x2 (or turned (> i 0))))))
|
||||
(setf (aref m (- h y) (- w x)) 0)
|
||||
(setf (aref m y x) 0)))
|
||||
|
||||
(walk cy (1- cx) nil)
|
||||
(cond ((= h w) (incf cnt cnt))
|
||||
((oddp w) (walk (1- cy) cx t))
|
||||
(recur (incf cnt (cut-it h w nil))))
|
||||
cnt)))
|
||||
|
||||
(loop for w from 1 to 9 do
|
||||
(loop for h from 1 to w do
|
||||
(if (evenp (* w h))
|
||||
(format t "~d x ~d: ~d~%" w h (cut-it w h)))))
|
||||
30
Task/Cut-a-rectangle/Common-Lisp/cut-a-rectangle-2.lisp
Normal file
30
Task/Cut-a-rectangle/Common-Lisp/cut-a-rectangle-2.lisp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
2 x 1: 2
|
||||
2 x 2: 2
|
||||
3 x 2: 3
|
||||
4 x 1: 4
|
||||
4 x 2: 4
|
||||
4 x 3: 9
|
||||
4 x 4: 22
|
||||
5 x 2: 5
|
||||
5 x 4: 39
|
||||
6 x 1: 6
|
||||
6 x 2: 6
|
||||
6 x 3: 23
|
||||
6 x 4: 90
|
||||
6 x 5: 263
|
||||
6 x 6: 1018
|
||||
7 x 2: 7
|
||||
7 x 4: 151
|
||||
7 x 6: 2947
|
||||
8 x 1: 8
|
||||
8 x 2: 8
|
||||
8 x 3: 53
|
||||
8 x 4: 340
|
||||
8 x 5: 1675
|
||||
8 x 6: 11174
|
||||
8 x 7: 55939
|
||||
8 x 8: 369050
|
||||
9 x 2: 9
|
||||
9 x 4: 553
|
||||
9 x 6: 31721
|
||||
9 x 8: 1812667
|
||||
Loading…
Add table
Add a link
Reference in a new issue