Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/1286289 to your computer and use it in GitHub Desktop.
Save amalloy/1286289 to your computer and use it in GitHub Desktop.
;; amalloy's solution to Love Triangle
;; https://4clojure.com/problem/127
(fn [m t e c i a r v g]
(let [p (t #(<= % (m g))
(i #(* 2 %) 1))
H (c g)
W (c p)
g (v (for [y g]
(v
(for [x p]
(> (bit-and x y) 0)))))
o #(and (e true?
(a < [-1 -1] % [H W]))
(get-in g %))
z (fn [s g]
(->> #{s}
(i #(set
(mapcat g %)))
(t #(e o %))
(a c)
(apply +)))
n [-1 0] ne [-1 1] e [0 1] se [1 1]
s [1 0] sw [1 -1] w [0 -1] nw [-1 -1]
t (for [x [[n e] [e s] [s w] [w n]
[nw n ne] [ne e se]
[sw s se] [nw w sw]]]
(fn [p]
(for [d x]
(a + d p))))
o (m
(for [y (r H) x (r W)
g t]
(z [y x] g)))]
(when (>= o 3)
o)))
#(apply max %)
take-while
every?
count
iterate
map
range
vec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment