Last active
January 23, 2018 16:03
-
-
Save joebo/efe931be700fc8954387cdc945d80d62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# solution for tests on https://pastebin.com/BEdkvnHz | |
(de noRed (X) (not (match (list '@X ~(chop ":\"red\"") '@Y) X))) | |
(de parse (Input) | |
(let (Input (list (chop Input)) C NIL) | |
(recur NIL | |
(make | |
(while (and (setq C (pop Input)) (<> "}" C) (<> "]" C)) | |
(if (or (= C "{") (= C "[")) (link (recurse)) (link C)) ) ) ) ) ) | |
(de filterRed (L) | |
(recur (L) | |
(make | |
(for C L | |
(link | |
(if (not (atom C)) | |
(if (noRed C) (recurse C)) | |
C ) ) ) ) ) ) | |
(de sumNum (Lst) | |
(let Lst (fish 'atom Lst) | |
(sum format (apply split (diff Lst (chop "1234567890-")) Lst)) )) | |
(de part2 (Str) | |
(sumNum (filterRed (parse Str))) ) | |
(test 6 (part2 " [1,2,3]")) | |
(test 4 (part2 "[1,{\"c\":\"red\",\"b\":2},3]")) | |
(test 0 (part2 "{\"d\":\"red\",\"e\":[1,2,3,4],\"f\":5}")) | |
(test 6 (part2 "[1,\"red\",5] ")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment