- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6.clj
34 lines (31 loc) · 998 Bytes
/
6.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
(ns6
(:require [clojure.test :refer [deftest testing is run-tests]]))
(defnread-input
[]
(slurp"./clojure/input.txt"))
(defnconvert
[num-rows]
(let [input (read-input)
n (count input)
result (vec (repeat num-rows ""))]
(loop [i 0
row 0
direction 1
result result]
(if (= i n)
(apply str result)
(let [updated-result (update result row str (nth input i))
new-row (if (or (= row 0) (= row (dec num-rows)))
(+ row direction)
(+ row direction))]
(recur (inc i)
new-row
(if (or (= new-row 0) (= new-row (dec num-rows)))
(- direction)
direction)
updated-result))))))
(deftestzigzag-problem
(testing"should return the zigzag string"
(is (= (convert3) "PAYPALISHIRING"))
(is (= (convert4) "PINALSIGYAHRPI"))
(is (= (convert1) "A"))))