;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Implement count system ;;;;;;;;;;;;;;;;;;;;;;;;;;; ; variables (defparameter *search_que* '(1)) (defparameter *history* '(1)) (defparameter *depth_list* '(1)) (defparameter *depth* 1) (defparameter *goal_depth_list* '()) (defvar *start* 1) ; functions (defun n_to_bit (node) (count #\1 (format nil "~b" node)) ) (defun add_node (node n) (cond ((or (> node n) (< node *start*) (> (count node *history*) 0)) (return-from add_node nil) )) (push node *search_que*) (push node *history*) (push *depth* *depth_list*) ) (defun add-neghboring-node (n now) ; next (add_node (+ now (n_to_bit now)) n) ; prev (add_node (- now (n_to_bit now)) n) ) ; add a present node to the que ; pop a node from que or return -1 ; return count if a node is the goal ; add neighboring node which isn't searched to the que (defun loop-count-goal (n) (loop (if (<= (length *search_que*) 0) (return-from loop-count-goal -1)) (if (= (car *search_que*) n) (push *depth* *goal_depth_list*)) ; (return-from loop-count-goal *depth*)) (setf *depth* (1+ (pop *depth_list*))) (add-neghboring-node n (pop *search_que*)) ) ) (defun n3 () (loop-count-goal (parse-integer (read-line))) (cond ((= (length *goal_depth_list*) 0) (princ -1)) (t (princ (loop for i in *goal_depth_list* minimize i)))) ) (n3)