That is how to do it

main
Jacopo De Simoi 1 year ago
parent d7384b3548
commit 456617d42d
  1. 31
      p7/operators.el

@ -0,0 +1,31 @@
(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 (list (|| it y) (+ it y) (* it y)) (-list lx)))) numbers))))
(apply '+ (-map 'car (-filter 'sequence-works-p data)))
97902809384118
1153997401072
(|| 523 79)
Loading…
Cancel
Save