-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_snippets.clj
55 lines (39 loc) · 1.16 KB
/
_snippets.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(ns snippets
(:require [clojure.test :refer :all]
[clojure.string :as str]))
;; USEFUL SNIPPETS FOUND IN SOLUTIONS
;; dotimes instead of doseq (+ distinct)
(dotimes [_ (read)]
(apply println
(sort
(distinct
(let [n (read) a (read) b(read)]
(for [ i (range n)]
(+ (* a i) (* b (- n i 1)))))))))
;; reading input
(defn str->nums [str]
(->> (str/split str #" ")
(map #(Integer/parseInt %))))
(def T (Integer/parseInt (read-line)))
(doseq [_ (range T)]
(solve (str->nums (read-line))))
;; reading input / clean
(defn save-prisoner []
(let [n (read)
m (read)
s (dec (read))]
(prn (inc (rem (+ s (dec m)) n)))))
(let [t (read)]
(dorun (repeatedly t save-prisoner)))
; can be tested
(with-in-str "3\n10 5 3\n10 5 3\n10 5 3\n"
(let [t (read)]
(dorun (repeatedly t save-prisoner))))
;; reading input
(defn readv [] (mapv read-string (str/split (read-line) #"\s")))
(defn readi [] (read-string (read-line)))
(defn readm [n] (vec (repeatedly n readv)))
(dotimes [i (readi)]
(let [[n m s] (readv)
last (inc (mod (+ (dec m) (dec s)) n))]
(println last)))