-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
orbit-stabilizer
committed
Dec 12, 2024
1 parent
44aaa9e
commit f8e1177
Showing
9 changed files
with
155 additions
and
124 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# Ignore all text files | ||
*.txt | ||
.lsp | ||
.clj-kondo | ||
.cpcache | ||
__pycache__ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(require '[clojure.string :as str]) | ||
|
||
(defn read-file [file-name] | ||
(->> (slurp file-name) | ||
(str/split-lines))) | ||
|
||
(defn make-race [lines] | ||
(->> lines | ||
(map #(re-seq #"\d+" %)) | ||
(map #(str/join "" %)) | ||
(map parse-long))) | ||
|
||
(defn compute-ways-to-win [[t d]] | ||
(let [x (/ (- t (Math/sqrt (- (* t t) (* 4 d)))) 2) | ||
y (/ (+ t (Math/sqrt (- (* t t) (* 4 d)))) 2)] | ||
(+ (- (- (Math/ceil y) 1) (+ (Math/floor x) 1)) 1))) | ||
|
||
(defn main [file-name] | ||
(->> (read-file file-name) | ||
(make-race) | ||
(compute-ways-to-win))) | ||
|
||
(main "z_input.txt") |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(require '[clojure.string :as str]) | ||
|
||
(defn cycle-str [coll] | ||
(lazy-cat coll (cycle-str coll))) | ||
|
||
(defn build-directions [document] | ||
(->> document | ||
(first) | ||
(cycle-str))) | ||
|
||
(defn build-network [document] | ||
(->> document | ||
((comp next next)) | ||
(map #(str/split % #"=")))) | ||
|
||
(defn main [file-name] | ||
(->> (slurp file-name) | ||
(str/split-lines) | ||
(build-network))) | ||
|
||
|
||
(main "sample.txt") | ||
|
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
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
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