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.
1.2 KiB
1.2 KiB
Solution to p10
Load the file into a list of lines
(with-temp-buffer
(insert-file-contents "input-test")
(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))
and split into a list of list of chars
(setq data-chars (-map (lambda (str) (--map (- (string-to-char it) ?0) (split-string str "\\|.+" t)))
data))
| 8 | 9 | 0 | 1 | 0 | 1 | 2 | 3 |
| 7 | 8 | 1 | 2 | 1 | 8 | 7 | 4 |
| 8 | 7 | 4 | 3 | 0 | 9 | 6 | 5 |
| 9 | 6 | 5 | 4 | 9 | 8 | 7 | 4 |
| 4 | 5 | 6 | 7 | 8 | 9 | 0 | 3 |
| 3 | 2 | 0 | 1 | 9 | 0 | 1 | 2 |
| 0 | 1 | 3 | 2 | 9 | 8 | 0 | 1 |
| 1 | 0 | 4 | 5 | 6 | 7 | 3 | 2 |
this yields the coordinates of the 0s
(-map #'cadr
(--filter (eq (car it) 0)
(-mapcat #'identity
(-map-indexed (lambda (y l) (-map-indexed (lambda (x el) (list el (list x y))) l)) data-chars))))
| 2 | 0 |
| 4 | 0 |
| 4 | 2 |
| 6 | 4 |
| 2 | 5 |
| 5 | 5 |
| 0 | 6 |
| 6 | 6 |
| 1 | 7 |