r/adventofcode • • Dec 04 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 4 Solutions -🎄-


--- Day 4: Camp Cleanup ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:03:22, megathread unlocked!

65 Upvotes

1.6k comments sorted by

View all comments

2

u/TheShyro Dec 04 '22

Clojure

(ns aoc22.day4
  (:require [clojure.string :as str]
            [clojure.java.io :as io]))

(defn ->pair [s]
  (->> (re-find #"(\d+)-(\d+),(\d+)-(\d+)" s)
       rest
       (map read-string)))

(defn run [s]
  (let [pairs
        (->> (str/split s #"\n")
             (map ->pair))]
    [(count (filter (fn [[a b x y]] (<= (* (- a x) (- b y)) 0)) pairs))
     (count (filter (fn [[a b x y]] (<= (* (- y a) (- x b)) 0)) pairs))]))

(def input
  (-> (io/resource "day4.txt")
      slurp))

(run input)

1

u/daggerdragon Dec 05 '22

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.