<commit_before>(ns adventofcode.days.day3
  (:require [clojure.string :as str])
  (:require [clojure.java.io :as io]))

(defn input [path]
  (line-seq (io/reader path)))

; get greatest number of one row
(defn greatest
  [entry]
  (first (reverse (sort (map #(Integer/parseInt %) (str/split (str/trim entry) #"\s+"))))))

; sum of 2 smaller numbers
(defn sum
  [entry]
  (apply + (rest (reverse (sort (map #(Integer/parseInt %) (str/split (str/trim entry) #"\s+")))))))

; comparator returns -1 if it's a valid triangle
(defn check-valid-triangle
  [entry]
  (compare (greatest entry) (sum entry)))

(defn part1
  []
  (-> (filter #(= % -1) (map #(check-valid-triangle %) (input "././files/day3_input.txt")))
      (count)))

; => 993
<commit_msg>feat(aoc): add solution for day 3<commit_after>(ns adventofcode.days.day3
  (:require [clojure.string :as str])
  (:require [clojure.java.io :as io]))

(defn input [path]
  (line-seq (io/reader path)))

; get greatest number of one row
(defn greatest
  [entry]
  (first (reverse (sort (map #(Integer/parseInt %) (str/split (str/trim entry) #"\s+"))))))

; sum of 2 smaller numbers
(defn sum
  [entry]
  (apply + (rest (reverse (sort (map #(Integer/parseInt %) (str/split (str/trim entry) #"\s+")))))))

; comparator returns -1 if it's a valid triangle
(defn check-valid-triangle
  [entry]
  (compare (greatest entry) (sum entry)))

(defn part1
  []
  (-> (filter #(= % -1) (map #(check-valid-triangle %) (input "././files/day3_input.txt")))
      (count)))

; => 993

(defn part2
  []
  (-> (filter #(= % -1) (map #(check-valid-triangle %) (map #(str/join " " %) (partition 3 (flatten (apply map vector (map #(str/split (str/trim %) #"\s+") (input "././files/day3_input.txt"))))))))
      (count)))

; => 1849

{'fraction_non_alphanumeric': 0.2083096186681844, 'fraction_numerical': 0.015367103016505406, 'mean_word_length': 3.738544474393531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1557140', 'n_tokens_mistral': 685, 'n_tokens_neox': 653, 'n_words': 183}