This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 1. Get each of the characters from the triplet as keys to a hash-map | |
;; 2. The values are the characters before the key character in the secret string. | |
;; 3. Find the key which has no values. | |
;; 4. Add that character to the final string | |
;; 5. Remove it from the hash-map, and all instances of it from the map values. | |
;; 6. Goto 3 | |
;; 7. Once hash-map has no keys left. We are done! | |
(ns codewars.puzzle-strings | |
(:require [clojure.set :as set] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn is-tree [x i] | |
(= \# (nth i (mod x (count i))))) | |
(let [input (->> (slurp "input.txt") | |
(str/split-lines)) | |
x-step 7 | |
y-step 1] | |
(->> (take-nth y-step input) | |
(map is-tree (iterate #(+ x-step %) 0)) | |
(filter true?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -------------------------- part 1 | |
(defn valid? [passport] | |
(let [required-fields [:hgt :byr :eyr :ecl :iyr :pid :hcl]] | |
(every? #(passport %) required-fields))) | |
;; -------------------------- part 2 | |
(defn valid-year [min max byr] | |
(and byr (= 4 (count byr)) (re-matches #"\d+" byr) (<= min (Integer/parseInt byr) max))) | |
(defn valid-height [height] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; part 1 | |
(defn valid? [{:keys [min max c pwd]}] | |
(<= min ((frequencies pwd) c 0) max)) | |
;; part 2 | |
(defn xor [a b] | |
(or (and a (not b)) | |
(and b (not a)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn parse-input [] | |
(->> (slurp "puzzle-inputs/2020/day9") | |
(str/split-lines) | |
(map #(Long/parseLong %)))) | |
(defn reduce-window [part] | |
(let [min (apply min part) | |
max (apply max part)] | |
[(+ min max) (reduce + 0 part)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn remove-keys [m keys] | |
(if (seq keys) | |
(recur (dissoc m (first keys)) (rest keys)) | |
m)) | |
(let [test-img-map {:row1-col1 0 | |
:row1-col2 0 | |
:row1-col3 0 | |
:row2-col1 0 | |
:row2-col2 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; slow :( | |
(defn sieve-primes [upper] | |
(let [xs (->> (range 1 (inc upper)) | |
(set))] | |
(sort (reduce #(if (or (= 1 %2) (not (%1 %2))) | |
%1 | |
(let [multiples (range (* 2 %2) (inc upper) %2)] | |
(set/difference %1 multiples))) xs (range 1 (Math/sqrt (inc upper))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Saw this call | |
``` | |
dbs.Add(new Database("OnCallQueue", 666, 80, "online", "full")); | |
``` | |
And thought that Database constructor signature would be something like | |
``` | |
(string, int, int, string, string) | |
`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns exfn.app | |
(:require [reagent.dom :as dom] | |
[reagent.core :as reagent] | |
[re-frame.core :as rf] | |
[goog.string :as gstring] | |
[goog.string.format] | |
[clojure.string :as string])) | |
(comment | |
(str "DEV NOTE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns exfn.app | |
(:require [reagent.dom :as dom] | |
[re-frame.core :as rf])) | |
;;-- Events and Effects -------------------------------------------------------------------------- | |
(rf/reg-event-db | |
:initialize | |
(fn [_ _] | |
{:points []})) |
OlderNewer