You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

25 lines
760 B

(with-temp-buffer
(insert-file-contents "input")
(replace-regexp ":" "")
(goto-char (point-min))
(replace-regexp "^" "(")
(goto-char (point-min))
(replace-regexp "$" ")")
(goto-char (point-min))
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(eval-buffer))
;; now the variable data contains the lists of numbers; the car is the
;; result, the cdr is the numbers we need to combine
(defun || (a b)
(+ (* a (expt 10 (+ 1 (floor (log b 10))))) b))
(defun sequence-works-p (l)
(let ((result (car l))
(numbers (cdr l)))
(member result (-reduce (lambda (lx y) (-flatten (--map (-map (lambda (op) (funcall op it y)) '(+ * ||)) (-list lx)))) numbers))))
(apply '+ (-map 'car (-filter 'sequence-works-p data)))