<commit_before>(ns com.nomistech.clojure-the-language.c-900-appy-stuff.s-100-science.ss-atomic-orbitals
  (:require [midje.sweet :refer :all]))

(def +orbitals-extra-at-energy-level+
  [{:s 1}
   {:p 3}
   {}
   {:d 5}
   {}
   {:f 7}
   {}])

(def +n-orbitals-extra-at-energy-level-diffs+
  (cons 0
        (for [m +orbitals-extra-at-energy-level+]
          (if (empty? m)
            0
            (apply + (for [[k v] m]
                       v))))))

(def +n-electrons-extra-at-energy-level-diffs+
  (map (partial * 2)
       +n-orbitals-extra-at-energy-level-diffs+))

(def +n-electrons-extra-at-energy-level+
  (->> +n-electrons-extra-at-energy-level-diffs+
       (reductions +)))

(def +noble-gases-atomic-numbers+
  (->> +n-electrons-extra-at-energy-level+
       (reductions +)))

;;;; ___________________________________________________________________________

(fact +n-orbitals-extra-at-energy-level-diffs+
  => [0 1 3 0 5 0 7 0])

(fact +n-electrons-extra-at-energy-level-diffs+
  => [0 2 6 0 10 0 14 0])

(fact +n-electrons-extra-at-energy-level+
  => [0 2 8 8 18 18 32 32])

(fact +noble-gases-atomic-numbers+
  => [0 2 10 18 36 54 86 118])

;;;; ___________________________________________________________________________

(defn successive-funcalls [fs v]
  (lazy-seq
   (if (empty? fs)
     '()
     (let [vv ((first fs) v)]
       (cons vv
             (successive-funcalls (rest fs)
                                  vv))))))

(defn successive-differences
  "The successive differences in `s`.
  `s` is a sequence of numbers."
  [s]
  (map - (rest s) s))

(defn successive-differences-incl-0
  "Zero consed on to the successive differences in `s`.
  `s` is a sequence of numbers."
  [s]
  (cons 0 (successive-differences s)))

;;;; ___________________________________________________________________________

(fact (successive-differences [1 10 100 1000])
  => [9 90 900])

(fact (successive-differences-incl-0 [1 10 100 1000])
  => [0 9 90 900])

(fact (successive-funcalls [inc - /] 9)
  => [10 -10 -1/10])

;;;; ___________________________________________________________________________

(fact (successive-funcalls [successive-differences-incl-0
                            successive-differences-incl-0
                            (fn [s] (map #(/ % 2)
                                         s))]
                           +noble-gases-atomic-numbers+)
  => [+n-electrons-extra-at-energy-level+
      +n-electrons-extra-at-energy-level-diffs+
      +n-orbitals-extra-at-energy-level-diffs+])

(fact (successive-funcalls [successive-differences-incl-0
                            successive-differences-incl-0]
                           +noble-gases-atomic-numbers+)
  => [[0 2 8 8 18 18 32 32]
      [0 2 6 0 10 0 14 0]])
<commit_msg>Add a 0 energy level to `+orbitals-extra-at-energy-level+`<commit_after>(ns com.nomistech.clojure-the-language.c-900-appy-stuff.s-100-science.ss-atomic-orbitals
  (:require [midje.sweet :refer :all]))

(def +orbitals-extra-at-energy-level+
  [{}
   {:s 1}
   {:p 3}
   {}
   {:d 5}
   {}
   {:f 7}
   {}])

(def +n-orbitals-extra-at-energy-level-diffs+
  (for [m +orbitals-extra-at-energy-level+]
    (if (empty? m)
      0
      (apply + (for [[k v] m]
                 v)))))

(def +n-electrons-extra-at-energy-level-diffs+
  (map (partial * 2)
       +n-orbitals-extra-at-energy-level-diffs+))

(def +n-electrons-extra-at-energy-level+
  (->> +n-electrons-extra-at-energy-level-diffs+
       (reductions +)))

(def +noble-gases-atomic-numbers+
  (->> +n-electrons-extra-at-energy-level+
       (reductions +)))

;;;; ___________________________________________________________________________

(fact +n-orbitals-extra-at-energy-level-diffs+
  => [0 1 3 0 5 0 7 0])

(fact +n-electrons-extra-at-energy-level-diffs+
  => [0 2 6 0 10 0 14 0])

(fact +n-electrons-extra-at-energy-level+
  => [0 2 8 8 18 18 32 32])

(fact +noble-gases-atomic-numbers+
  => [0 2 10 18 36 54 86 118])

;;;; ___________________________________________________________________________

(defn successive-funcalls [fs v]
  (lazy-seq
   (if (empty? fs)
     '()
     (let [vv ((first fs) v)]
       (cons vv
             (successive-funcalls (rest fs)
                                  vv))))))

(defn successive-differences
  "The successive differences in `s`.
  `s` is a sequence of numbers."
  [s]
  (map - (rest s) s))

(defn successive-differences-incl-0
  "Zero consed on to the successive differences in `s`.
  `s` is a sequence of numbers."
  [s]
  (cons 0 (successive-differences s)))

;;;; ___________________________________________________________________________

(fact (successive-differences [1 10 100 1000])
  => [9 90 900])

(fact (successive-differences-incl-0 [1 10 100 1000])
  => [0 9 90 900])

(fact (successive-funcalls [inc - /] 9)
  => [10 -10 -1/10])

;;;; ___________________________________________________________________________

(fact (successive-funcalls [successive-differences-incl-0
                            successive-differences-incl-0
                            (fn [s] (map #(/ % 2)
                                         s))]
                           +noble-gases-atomic-numbers+)
  => [+n-electrons-extra-at-energy-level+
      +n-electrons-extra-at-energy-level-diffs+
      +n-orbitals-extra-at-energy-level-diffs+])

(fact (successive-funcalls [successive-differences-incl-0
                            successive-differences-incl-0]
                           +noble-gases-atomic-numbers+)
  => [[0 2 8 8 18 18 32 32]
      [0 2 6 0 10 0 14 0]])

{'fraction_non_alphanumeric': 0.15306859205776174, 'fraction_numerical': 0.04657039711191336, 'mean_word_length': 2.4267161410018554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4337615', 'n_tokens_mistral': 2137, 'n_tokens_neox': 1880, 'n_words': 416}