day 16 part 2, quite stuck
This commit is contained in:
parent
ae745dc0f2
commit
69250daf63
|
@ -1028,3 +1028,5 @@
|
||||||
;; what were you doing for 24-8 = 16 turns each? well, walking between rooms, yeah
|
;; what were you doing for 24-8 = 16 turns each? well, walking between rooms, yeah
|
||||||
;;
|
;;
|
||||||
;; while it runs, let's add printing "max so far"?
|
;; while it runs, let's add printing "max so far"?
|
||||||
|
|
||||||
|
;;; another recommendation from people in Matrix : https://github.com/michaelw/cl-dot for graphs
|
||||||
|
|
|
@ -532,17 +532,40 @@
|
||||||
|
|
||||||
;; let's generalize this?
|
;; let's generalize this?
|
||||||
(defun try-dropping (figures lateral-moves
|
(defun try-dropping (figures lateral-moves
|
||||||
times grid)
|
times grid height)
|
||||||
;; (print-grid grid)
|
;; (print-grid grid)
|
||||||
(let* ((top (1- (array-dimension grid 0))) ; max row with stone, get's smaller. 0 on the TOP
|
(let* ((top (1- (array-dimension grid 0))) ; max row with stone, get's smaller. 0 on the TOP
|
||||||
(percent-index (floor (/ times 100)))
|
(percent-index (floor (/ times 100)))
|
||||||
(running-percent-index 0))
|
(running-percent-index 0)
|
||||||
|
(additional-count 0))
|
||||||
;; outer loop is simple dotimes for amount of figures we want to drop
|
;; outer loop is simple dotimes for amount of figures we want to drop
|
||||||
(dotimes (i times)
|
(dotimes (i times)
|
||||||
|
;; fuck i forgot about my inverted TOP. it goes to 0
|
||||||
|
(when (< top (/ height 20))
|
||||||
|
;; ok. let's think about this.
|
||||||
|
;; my "TOP" for 10 rows is 8, overall indices start from 0
|
||||||
|
;; but "TOP" would be what?
|
||||||
|
;; it would start on 9. on the "already occupied" line
|
||||||
|
;; (by the floor, which we don't want to count)
|
||||||
|
;; so if TOP is 2, then 2 is "already occupied"
|
||||||
|
;; and only 2 left, so it's 7 elements
|
||||||
|
;; 10 - 2 - 1 how much we're need to count
|
||||||
|
;; which row i want to copy? the TOP, right?
|
||||||
|
;; if top is 9, then
|
||||||
|
;;
|
||||||
|
;; ok. let's count TOP at the moment of TRUNCATE
|
||||||
|
;; that would leave us with 1 unnecessary - the manual "floor"
|
||||||
|
(incf additional-count
|
||||||
|
(- (array-dimension *test-grid* 0) top 1))
|
||||||
|
(format t "Truncating~%" )
|
||||||
|
(setq grid (truncate-grid grid top height))
|
||||||
|
(setq top (1- (array-dimension grid 0)))
|
||||||
|
)
|
||||||
|
|
||||||
(when (= percent-index running-percent-index)
|
(when (= percent-index running-percent-index)
|
||||||
(setq running-percent-index 0)
|
(setq running-percent-index 0)
|
||||||
(format t "One more: ~a%, , intermediate height: ~a; the step is ~a; the times is ~a~%" (floor (* 100 (/ i times))) top i times)
|
(format t "One more: ~a%, , intermediate height: ~a; the step is ~a; the times is ~a~%"
|
||||||
|
(floor (* 100 (/ i times))) (- (array-dimension grid 0) top 1) i times)
|
||||||
)
|
)
|
||||||
(incf running-percent-index)
|
(incf running-percent-index)
|
||||||
|
|
||||||
|
@ -570,7 +593,8 @@
|
||||||
;; more moves down exist
|
;; more moves down exist
|
||||||
;; do move down, and loop for the lateral change and possible exit
|
;; do move down, and loop for the lateral change and possible exit
|
||||||
(setq hook (cons (1+ (car hook)) (cdr hook))))))
|
(setq hook (cons (1+ (car hook)) (cdr hook))))))
|
||||||
top)
|
(+ additional-count (- (array-dimension grid 0) top 1)))
|
||||||
|
|
||||||
;; (print-grid grid)
|
;; (print-grid grid)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -680,15 +704,15 @@
|
||||||
;; How tall will the tower be after 1000000000000 rocks have stopped?
|
;; How tall will the tower be after 1000000000000 rocks have stopped?
|
||||||
;; so. let's print out intermediate? each 1% ?
|
;; so. let's print out intermediate? each 1% ?
|
||||||
|
|
||||||
(init-test-grid 1000000)
|
|
||||||
;; 866549760 bytes available, 112800000000144 requested.
|
;; 866549760 bytes available, 112800000000144 requested.
|
||||||
(floor (/ 112800000000144 866549760))
|
(floor (/ 112800000000144 866549760))
|
||||||
(floor (/ 910721024 1024 1024 1024)) ; available
|
(floor (/ 910721024 1024 1024 1024)) ; available
|
||||||
(floor (/ 112800000000144 1024 1024 1024)) ; 105000 iGb requested
|
(floor (/ 112800000000144 1024 1024 1024)) ; 105000 iGb requested
|
||||||
;; so, no
|
;; so, no
|
||||||
;; so, how'd i print report each 1% ?
|
;; so, how'd i print report each 1% ?
|
||||||
|
(init-test-grid 10000)
|
||||||
(defparameter *task-2-run-result* 0)
|
(defparameter *task-2-run-result* 0)
|
||||||
(setq *task-2-run-result
|
(setq *task-2-run-result*
|
||||||
(try-dropping *endless-shapes*
|
(try-dropping *endless-shapes*
|
||||||
*endless-input-laterals* 2022 *test-grid*)) ; this is not right. no lateral moves done
|
*endless-input-laterals* 2022 *test-grid*)) ; this is not right. no lateral moves done
|
||||||
(- (array-dimension *test-grid* 0) *task-2-run-result* 1)
|
(- (array-dimension *test-grid* 0) *task-2-run-result* 1)
|
||||||
|
@ -698,3 +722,58 @@
|
||||||
;; ok. i'd want to what? maybe every million size truncate?
|
;; ok. i'd want to what? maybe every million size truncate?
|
||||||
;; when size get to 1M, get last row (height - 1?)
|
;; when size get to 1M, get last row (height - 1?)
|
||||||
;; copy that last row to the first, add to the
|
;; copy that last row to the first, add to the
|
||||||
|
|
||||||
|
(defun truncate-grid (grid top-row height)
|
||||||
|
(let*
|
||||||
|
((rownum (1- (array-dimension grid 0))) ; bottom row
|
||||||
|
(new-grid (make-array `(,height 7) :initial-element #\.))
|
||||||
|
(rowsize (array-dimension grid 1))
|
||||||
|
(row-bottom (make-array rowsize
|
||||||
|
:displaced-to new-grid
|
||||||
|
:displaced-index-offset (* rownum rowsize)))
|
||||||
|
(row-top (make-array rowsize
|
||||||
|
:displaced-to grid
|
||||||
|
:displaced-index-offset (* top-row rowsize))))
|
||||||
|
(gc :full t)
|
||||||
|
(loop for i from 0 below (array-total-size row-bottom) do
|
||||||
|
(setf (aref row-bottom i) (aref row-top i)))
|
||||||
|
new-grid))
|
||||||
|
|
||||||
|
;;; well, it will not work.
|
||||||
|
;; but let's try? first on test, and then maybe cancel
|
||||||
|
(/ 56000512 1024 1024) ; 54 Mb, that's WTF
|
||||||
|
(gc :full t)
|
||||||
|
|
||||||
|
(init-test-grid 100)
|
||||||
|
(defparameter *test-run-result* 0)
|
||||||
|
(setq *test-run-result* (try-dropping *endless-shapes*
|
||||||
|
*endless-test-laterals* 2022 *test-grid* 100)) ; this is not right. no lateral moves done
|
||||||
|
;; ok my 7010 is to be deducted from 10000
|
||||||
|
;; oh and one more transformation. hmmm hmmm
|
||||||
|
|
||||||
|
;; with enough grid 3068 - ok
|
||||||
|
;; when doing by 1000 - nok 3063. i'm missing rows somewhere
|
||||||
|
;;
|
||||||
|
;; i'm looking height when i'm truncating
|
||||||
|
|
||||||
|
(room t)
|
||||||
|
|
||||||
|
(init-test-grid 700)
|
||||||
|
(defparameter *test-run-result* 0)
|
||||||
|
(setq *test-run-result* (try-dropping *endless-shapes*
|
||||||
|
*endless-test-laterals* 2022 *test-grid* 700)) ; this is not right. no lateral moves done
|
||||||
|
;; but loosing 2 when do 1 truncating
|
||||||
|
;; 3087 when doing how many truncating?
|
||||||
|
;; for 500 600 700 wildly different numbers, so
|
||||||
|
|
||||||
|
;; yup. fuck if i only transfer last row - then hole in that last row is considered what?
|
||||||
|
;; yuck. i'd need to transfer serveral layers and still no guarantee
|
||||||
|
;;
|
||||||
|
;; how about i transfer 100 rows?
|
||||||
|
;; i'd init grid on my own, keep 100 rows below this is ugly as hell
|
||||||
|
;;
|
||||||
|
;; so, only good way is to actually trigger TRANSFER when there's possibility in
|
||||||
|
;; good enough floor
|
||||||
|
;;
|
||||||
|
;; and to know how to calculate correct amount of "negative space" below.
|
||||||
|
;; yuk.
|
||||||
|
|
Loading…
Reference in New Issue