Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created June 29, 2024 17:25
Show Gist options
  • Save Chouser/21ebf6952bd3ed7884ed5c5c32fee323 to your computer and use it in GitHub Desktop.
Save Chouser/21ebf6952bd3ed7884ed5c5c32fee323 to your computer and use it in GitHub Desktop.
https://4clojure.oxal.org/#/problem/117
; 227
#(loop [[[y x] & q] (for [[y r] (map list (range) %)
[x c] (map list (range) r)
:when (= \M c)]
[y x])
b (vec (map vec %))]
(if x
(if (= \C ((b y) x))
true
(recur
(into q
(for [[j k] [[-1 0] [1 0] [0 -1] [0 1]]
c [[(+ j y) (+ k x)]]
:when (#{\ \C} (get-in b c))]
c))
(assoc-in b [y x] \.)))
false))
; 224
#((fn f [[[y x] & q] b]
(if x
(if (= \C ((b y) x))
true
(f (into q
(for [[j k] [[-1 0] [1 0] [0 -1] [0 1]]
c [[(+ j y) (+ k x)]]
:when (#{\ \C} (get-in b c))]
c))
(assoc-in b [y x] \.)))
false))
(for [[y r] (map list (range) %)
[x c] (map list (range) r)
:when (= \M c)]
[y x]) (vec (map vec %)))
; 215
(fn [b]
(loop [b b]
(let [c (vec (for [f [#(map list (range) %)]
[y r] (f b)]
(vec (for [[x s] (f r)
n [(set (map #(get-in b (map + [y x] %)) [[0 1] [1 0] [0 -1] [-1 0]]))]]
(cond
(n 1) 1
(and (n \M) (= s \C)) 1
(and (n \M) (= s \ )) \M
1 s)))))]
(if (= b c)
(= 1 ((c 0) 0))
(recur c)))))
; goal: 188
; 186
(fn f [b]
(let [c (vec (for [f [#(map list (range) %)]
[y r] (f b)]
(vec (for [[x s] (f r)
n [(set (map #(get-in b (map + [y x] %)) [[0 1] [1 0] [0 -1] [-1 0]]))]]
(if (n 1)
1
(if (n \M)
({\ \M \C 1} s s)
s))))))]
(if (= b c)
(= 1 ((c 0) 0))
(f c))))
; 183
(fn f [b]
(let [m #(map list (range) %)
c (vec (for [[y r] (m b)]
(vec (for [[x s] (m r)
n [(set (map #(get-in b (map + [y x] %)) [[0 1] [1 0] [0 -1] [-1 0]]))]]
(or (n 1)
(if (n \M)
({\ \M \C 1} s s)
s))))))]
(if (= b c)
(= 1 ((c 0) 0))
(f c))))
; 212
(fn M [v]
(let [m #(map list (range) %)]
((fn f [b]
(let [B (into {}
(for [[c s] b
n [(set (map #(b (map + c %)) [[0 1] [1 0] [0 -1] [-1 0]]))]]
[c (or (n 1)
(if (n \M)
({\ \M \C 1} s s)
s))]))]
(if (= b B)
(= 1 (B [0 0]))
(f B))))
(into {} (for [[y r] (m v) [x s] (m r)] [[y x] s])))))
; with claggett:
; 106
(fn f [a b c]
(and (not= a c)
(if (re-seq #"CM|MC" (pr-str c))
true
(f b c (apply map str (map #(.replaceAll % " M|M " "MM") c))))))
0
0
(def f *1)
(f ["M C"])
(f ["M # C"])
(f ["C######"
" # "
" # # "
" # #M"
" # "])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment