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.
31 lines
790 B
31 lines
790 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 (list (|| it y) (+ it y) (* it y)) (-list lx)))) numbers)))) |
|
|
|
(apply '+ (-map 'car (-filter 'sequence-works-p data))) |
|
97902809384118 |
|
|
|
|
|
1153997401072 |
|
|
|
(|| 523 79)
|
|
|