Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Clojure, 71 bytes

Clojure, 71 bytes

(fn[n](every?(fn[[q w]](some q w))(partition 2 1(map #(set(str %))n))))

An anonymous function that accepts a sequence of numbers. Returns true/false.

I like how it reads. There's definitely a few areas that can be improved upon here. My function being passed to map can't easily be changed so that it doesn't require the function macro, which means the entire function can't make use of the macro, which likely added some bytes. It would also be nice if I could figure out a better way of unpacking the values in the every? predicate.

(defn number-chain? [nums]
 (let [; Turn each number into a set of characters
 set-nums (map #(set (str %)) nums)
 ; Partition the sets into lists of neighbors
 ; [1 2 3 4] -> [[1 2] [2 3] [3 4]]
 partitioned (partition 2 1 set-nums)]
 ; Does every second neighbor contain some element of the first?
 (every?
 (fn [[l1 l2]]
 (some l1 l2))
 partitioned)))

#Clojure, 71 bytes

(fn[n](every?(fn[[q w]](some q w))(partition 2 1(map #(set(str %))n))))

An anonymous function that accepts a sequence of numbers. Returns true/false.

I like how it reads. There's definitely a few areas that can be improved upon here. My function being passed to map can't easily be changed so that it doesn't require the function macro, which means the entire function can't make use of the macro, which likely added some bytes. It would also be nice if I could figure out a better way of unpacking the values in the every? predicate.

(defn number-chain? [nums]
 (let [; Turn each number into a set of characters
 set-nums (map #(set (str %)) nums)
 ; Partition the sets into lists of neighbors
 ; [1 2 3 4] -> [[1 2] [2 3] [3 4]]
 partitioned (partition 2 1 set-nums)]
 ; Does every second neighbor contain some element of the first?
 (every?
 (fn [[l1 l2]]
 (some l1 l2))
 partitioned)))

Clojure, 71 bytes

(fn[n](every?(fn[[q w]](some q w))(partition 2 1(map #(set(str %))n))))

An anonymous function that accepts a sequence of numbers. Returns true/false.

I like how it reads. There's definitely a few areas that can be improved upon here. My function being passed to map can't easily be changed so that it doesn't require the function macro, which means the entire function can't make use of the macro, which likely added some bytes. It would also be nice if I could figure out a better way of unpacking the values in the every? predicate.

(defn number-chain? [nums]
 (let [; Turn each number into a set of characters
 set-nums (map #(set (str %)) nums)
 ; Partition the sets into lists of neighbors
 ; [1 2 3 4] -> [[1 2] [2 3] [3 4]]
 partitioned (partition 2 1 set-nums)]
 ; Does every second neighbor contain some element of the first?
 (every?
 (fn [[l1 l2]]
 (some l1 l2))
 partitioned)))
Source Link
Carcigenicate
  • 3.6k
  • 2
  • 23
  • 31

#Clojure, 71 bytes

(fn[n](every?(fn[[q w]](some q w))(partition 2 1(map #(set(str %))n))))

An anonymous function that accepts a sequence of numbers. Returns true/false.

I like how it reads. There's definitely a few areas that can be improved upon here. My function being passed to map can't easily be changed so that it doesn't require the function macro, which means the entire function can't make use of the macro, which likely added some bytes. It would also be nice if I could figure out a better way of unpacking the values in the every? predicate.

(defn number-chain? [nums]
 (let [; Turn each number into a set of characters
 set-nums (map #(set (str %)) nums)
 ; Partition the sets into lists of neighbors
 ; [1 2 3 4] -> [[1 2] [2 3] [3 4]]
 partitioned (partition 2 1 set-nums)]
 ; Does every second neighbor contain some element of the first?
 (every?
 (fn [[l1 l2]]
 (some l1 l2))
 partitioned)))

AltStyle によって変換されたページ (->オリジナル) /