HackerRank Warmup

Solve Me First

https://www.hackerrank.com/challenges/solve-me-first/problem

1
2
3
(defn solveMeFirst [x y]
(+ x y)
)

Simple Array Sum

https://www.hackerrank.com/challenges/simple-array-sum/problem

1
2
3
(defn simpleArraySum [ar]
(apply + ar)
)

Compare the Triplets

https://www.hackerrank.com/challenges/compare-the-triplets/problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(defn compare [ax bx]
(map (fn [a b]
{:alice (if (> a b) 1 0)
:bob (if (< a b) 1 0)})
ax bx))

(defn calc-points [res]
(reduce (fn [acc v]
(let [a (:alice v)
b (:bob v)]
(-> acc
(update :alice #(+ % a))
(update :bob #(+ % b)))))
{:alice 0
:bob 0}
res))

(defn print-points [m]
[(:alice m) (:bob m)])

(defn compareTriplets [ax bx]
(-> (compare ax bx)
(calc-points)
(print-points)))

A Very Big Sum

https://www.hackerrank.com/challenges/a-very-big-sum/problem

1
2
3
(defn aVeryBigSum [ar]
(apply + ar)
)

Birthday Cake Candles

https://www.hackerrank.com/challenges/birthday-cake-candles/problem

1
2
3
4
5
6
7
(defn birthdayCakeCandles [candles]
(->> (frequencies candles)
(sort-by first)
(reverse)
first
second)
)
공유하기