John Chandler avatar John Chandler committed 22049bc

Moved kata 2 solutions into their own directory

Comments (0)

Files changed (10)

code_kata_2a.clj

-; http://codekata.pragprog.com/2007/01/kata_two_karate.html
-
-(ns code-kata)
-
-(defn is-single-item? [ list ]
-  (= 1 (count list)))
-
-(defn mid-index [ list ]
-  (quot (count list) 2))
-
-(defn bsearch [ list value slice-start slice-end ]
-  (if (empty? list)
-	-1
-	(let [ slice (subvec list slice-start slice-end)]
-	  (if (is-single-item? slice)
-		(if (= value (first slice) )
-		  slice-start
-		  -1)
-		(let [ mid (mid-index slice) ]
-		  (let [ mid-value (get slice mid) ]
-			(if (= value mid-value)
-			  (+ slice-start mid)
-			  (if (< value mid-value)
-				(bsearch list value slice-start (- slice-end mid))
-				(bsearch list value (+ slice-start mid) slice-end)))))))))
-
-(defn
-  #^{:test (fn []
-			 (assert (= -1 (chop 3 []) ))
-			 (assert (= -1 (chop 3 [1]) ))
-			 (assert (=  0 (chop 1 [1]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5]) ))
-			 (assert (=  1 (chop 3 [1 3 5]) ))
-			 (assert (=  2 (chop 5 [1 3 5]) ))
-			 (assert (= -1 (chop 0 [1 3 5]) ))
-			 (assert (= -1 (chop 2 [1 3 5]) ))
-			 (assert (= -1 (chop 4 [1 3 5]) ))
-			 (assert (= -1 (chop 6 [1 3 5]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5 7]) ))
-			 (assert (=  1 (chop 3 [1 3 5 7]) ))
-			 (assert (=  2 (chop 5 [1 3 5 7]) ))
-			 (assert (=  3 (chop 7 [1 3 5 7]) ))
-			 (assert (= -1 (chop 0 [1 3 5 7]) ))
-			 (assert (= -1 (chop 2 [1 3 5 7]) ))
-			 (assert (= -1 (chop 4 [1 3 5 7]) ))
-			 (assert (= -1 (chop 6 [1 3 5 7]) ))
-			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
-  chop
-  [item list]
-  (bsearch list item 0 (count list))
-)
-
-(test #'chop)
-
-

code_kata_2b.clj

-; http://codekata.pragprog.com/2007/01/kata_two_karate.html
-
-
-(defn
-  #^{:test (fn []
-			 (assert (= -1 (chop 3 []) ))
-			 (assert (= -1 (chop 3 [1]) ))
-			 (assert (=  0 (chop 1 [1]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5]) ))
-			 (assert (=  1 (chop 3 [1 3 5]) ))
-			 (assert (=  2 (chop 5 [1 3 5]) ))
-			 (assert (= -1 (chop 0 [1 3 5]) ))
-			 (assert (= -1 (chop 2 [1 3 5]) ))
-			 (assert (= -1 (chop 4 [1 3 5]) ))
-			 (assert (= -1 (chop 6 [1 3 5]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5 7]) ))
-			 (assert (=  1 (chop 3 [1 3 5 7]) ))
-			 (assert (=  2 (chop 5 [1 3 5 7]) ))
-			 (assert (=  3 (chop 7 [1 3 5 7]) ))
-			 (assert (= -1 (chop 0 [1 3 5 7]) ))
-			 (assert (= -1 (chop 2 [1 3 5 7]) ))
-			 (assert (= -1 (chop 4 [1 3 5 7]) ))
-			 (assert (= -1 (chop 6 [1 3 5 7]) ))
-			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
-  chop
-  [item list]
-  (if (empty? list)
-	-1
-	(loop [ min 0 mid (quot (count list) 2) max (count list)]
-	  (if (= item (get list mid))
-		mid
-		(if (or (= mid min) (= mid max))
-		  -1
-		  (if (< item (get list mid))
-			(recur min (quot (+ mid min) 2) mid)       ; look left
-			(recur mid (quot (+ mid max) 2) max))))))) ; look right
-
-(test #'chop)
-

code_kata_2c.clj

-; http://codekata.pragprog.com/2007/01/kata_two_karate.html
-
-(ns code-kata)
-
-(defn evaluate-list
-  " Returns offset if list contains only item, otherwise -1 "
-  [ item list offset ]
-  (if (= item (first list))
-	offset
-	-1))
-
-(defn get-left-half
-  " Returns the left half of the list "
-  [ list mid ]
-  (first (split-at mid list)))
-
-(defn get-right-half
-  " Returns the right half of the list "
-  [ list mid ]
-  (first (rest (split-at mid list))))
-
-(defn bsearch
-  " Returns index of item if in list, otherwise -1 "
-  [ dummy item list offset ]
-  (if (empty? list)
-	-1
-    (if (= 1 (count list))
-	  (evaluate-list item list offset)
-	  (let [ mid        (quot (count list) 2)
-			 left-half  (bsearch dummy item (get-left-half list mid)  offset )
-			 right-half (bsearch dummy item (get-right-half list mid) (+ mid offset)) ]
-		(if (= -1 left-half)
-		  right-half
-		  left-half)))))
-  
-(defn
-  #^{:test (fn []
-			 (assert (= -1 (chop 3 []) ))
-			 (assert (= -1 (chop 3 [1]) ))
-			 (assert (=  0 (chop 1 [1]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5]) ))
-			 (assert (=  1 (chop 3 [1 3 5]) ))
-			 (assert (=  2 (chop 5 [1 3 5]) ))
-			 (assert (= -1 (chop 0 [1 3 5]) ))
-			 (assert (= -1 (chop 2 [1 3 5]) ))
-			 (assert (= -1 (chop 4 [1 3 5]) ))
-			 (assert (= -1 (chop 6 [1 3 5]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5 7]) ))
-			 (assert (=  1 (chop 3 [1 3 5 7]) ))
-			 (assert (=  2 (chop 5 [1 3 5 7]) ))
-			 (assert (=  3 (chop 7 [1 3 5 7]) ))
-			 (assert (= -1 (chop 0 [1 3 5 7]) ))
-			 (assert (= -1 (chop 2 [1 3 5 7]) ))
-			 (assert (= -1 (chop 4 [1 3 5 7]) ))
-			 (assert (= -1 (chop 6 [1 3 5 7]) ))
-			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
-  chop
-  [item list]
-  (let [ mid         (quot (count list) 2)
-		 left-agent  (agent -1)
-		 right-agent (agent -1) ]
-	(send left-agent  bsearch item (get-left-half list mid)  0)
-	(send right-agent bsearch item (get-right-half list mid) mid)
-	(await left-agent right-agent)
-	(if (= -1 @left-agent)
-	  @right-agent
-	  @left-agent)))
-
-(test #'chop)
-
-(shutdown-agents)
-

code_kata_2d.clj

-; http://codekata.pragprog.com/2007/01/kata_two_karate.html
-
-(ns code-kata)
-
-  
-(defn
-  #^{:test (fn []
-			 (assert (= -1 (chop 3 []) ))
-			 (assert (= -1 (chop 3 [1]) ))
-			 (assert (=  0 (chop 1 [1]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5]) ))  ; failing
-			 (assert (=  1 (chop 3 [1 3 5]) ))
-			 (assert (=  2 (chop 5 [1 3 5]) ))  ; failing
-			 (assert (= -1 (chop 0 [1 3 5]) ))
-			 (assert (= -1 (chop 2 [1 3 5]) ))
-			 (assert (= -1 (chop 4 [1 3 5]) ))
-			 (assert (= -1 (chop 6 [1 3 5]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5 7]) )) ; failing
-			 (assert (=  1 (chop 3 [1 3 5 7]) ))
-			 (assert (=  2 (chop 5 [1 3 5 7]) ))
-			 (assert (=  3 (chop 7 [1 3 5 7]) ))
-			 (assert (= -1 (chop 0 [1 3 5 7]) ))
-			 (assert (= -1 (chop 2 [1 3 5 7]) ))
-			 (assert (= -1 (chop 4 [1 3 5 7]) ))
-			 (assert (= -1 (chop 6 [1 3 5 7]) ))
-			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
-  chop
-  [item list]
-  (def start        (atom 0))
-  (def offset       (atom (quot (count list) 2)))
-  (def current-item (atom nil))
-
-  (loop [ position (+ @start @offset) ]
-	(reset! current-item (get list position))
-	(if (nil? @current-item)
-	  -1
-	  (if (= @current-item item)
-		position
-		(if (= @offset 0)
-		  -1
-		  (do
-			(reset! start  position)
-			(reset! offset (quot @offset 2))
-			(if (< @current-item item)
-			  (recur (+ position @offset))  ; go right
-			  (recur (- position @offset))  ; go left
-	  	    )
-	      )
-        )
-      )
-    )
-  )
-)
-
-(test #'chop)
-

code_kata_2e.clj

-; http://codekata.pragprog.com/2007/01/kata_two_karate.html
-
-; ------------------------------------------------------------
-;  Algorithm taken from Programming Pearls, 2nd Edition, p.36
-;   written by Jon Bentley, published by Addison Wesley
-; ------------------------------------------------------------
-
-(ns code-kata)
-
-
-(defmacro mid []
-  (list 'quot '(+ lower upper) 2) )
-
-(defmacro get-mid []
-  (list 'get 'list '(mid)))
-
-(defmacro get-upper []
-  (list '- '(count list) 1 ))
-
-(defmacro look-left []
-  (list 'recur 'lower '(- (mid) 1)))
-
-(defmacro look-right []
-  (list 'recur '(+ (mid) 1) 'upper ))
-
-(defmacro search-exhausted []
-  (list '> 'lower 'upper))
-
-(defmacro do-search [ & body ]
-  ; NOT WORKING - "Can only recur from tail position"
-  `(loop [ ~'lower 0
-		   ~'upper (get-upper) ] ~@body
-     {:lower ~'lower :upper ~'upper }))
-
-(defn
-  #^{:test (fn []
-			 (assert (= -1 (chop 3 []) ))
-			 (assert (= -1 (chop 3 [1]) ))
-			 (assert (=  0 (chop 1 [1]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5]) ))
-			 (assert (=  1 (chop 3 [1 3 5]) ))
-			 (assert (=  2 (chop 5 [1 3 5]) ))
-			 (assert (= -1 (chop 0 [1 3 5]) ))
-			 (assert (= -1 (chop 2 [1 3 5]) ))
-			 (assert (= -1 (chop 4 [1 3 5]) ))
-			 (assert (= -1 (chop 6 [1 3 5]) ))
-
-			 (assert (=  0 (chop 1 [1 3 5 7]) ))
-			 (assert (=  1 (chop 3 [1 3 5 7]) ))
-			 (assert (=  2 (chop 5 [1 3 5 7]) ))
-			 (assert (=  3 (chop 7 [1 3 5 7]) ))
-			 (assert (= -1 (chop 0 [1 3 5 7]) ))
-			 (assert (= -1 (chop 2 [1 3 5 7]) ))
-			 (assert (= -1 (chop 4 [1 3 5 7]) ))
-			 (assert (= -1 (chop 6 [1 3 5 7]) ))
-			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
-  chop
-  [item list]
-  (do-search
-	(if (search-exhausted)
-	  -1
-	  (if (< (get-mid) item)
-		(look-right)
-		(if (= (get-mid) item)
-		  (mid)
-		  (look-left))))))
-
-(test #'chop)

kata2/code_kata_2a.clj

+; http://codekata.pragprog.com/2007/01/kata_two_karate.html
+
+(ns code-kata)
+
+(defn is-single-item? [ list ]
+  (= 1 (count list)))
+
+(defn mid-index [ list ]
+  (quot (count list) 2))
+
+(defn bsearch [ list value slice-start slice-end ]
+  (if (empty? list)
+	-1
+	(let [ slice (subvec list slice-start slice-end)]
+	  (if (is-single-item? slice)
+		(if (= value (first slice) )
+		  slice-start
+		  -1)
+		(let [ mid (mid-index slice) ]
+		  (let [ mid-value (get slice mid) ]
+			(if (= value mid-value)
+			  (+ slice-start mid)
+			  (if (< value mid-value)
+				(bsearch list value slice-start (- slice-end mid))
+				(bsearch list value (+ slice-start mid) slice-end)))))))))
+
+(defn
+  #^{:test (fn []
+			 (assert (= -1 (chop 3 []) ))
+			 (assert (= -1 (chop 3 [1]) ))
+			 (assert (=  0 (chop 1 [1]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5]) ))
+			 (assert (=  1 (chop 3 [1 3 5]) ))
+			 (assert (=  2 (chop 5 [1 3 5]) ))
+			 (assert (= -1 (chop 0 [1 3 5]) ))
+			 (assert (= -1 (chop 2 [1 3 5]) ))
+			 (assert (= -1 (chop 4 [1 3 5]) ))
+			 (assert (= -1 (chop 6 [1 3 5]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5 7]) ))
+			 (assert (=  1 (chop 3 [1 3 5 7]) ))
+			 (assert (=  2 (chop 5 [1 3 5 7]) ))
+			 (assert (=  3 (chop 7 [1 3 5 7]) ))
+			 (assert (= -1 (chop 0 [1 3 5 7]) ))
+			 (assert (= -1 (chop 2 [1 3 5 7]) ))
+			 (assert (= -1 (chop 4 [1 3 5 7]) ))
+			 (assert (= -1 (chop 6 [1 3 5 7]) ))
+			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
+  chop
+  [item list]
+  (bsearch list item 0 (count list))
+)
+
+(test #'chop)
+
+

kata2/code_kata_2b.clj

+; http://codekata.pragprog.com/2007/01/kata_two_karate.html
+
+
+(defn
+  #^{:test (fn []
+			 (assert (= -1 (chop 3 []) ))
+			 (assert (= -1 (chop 3 [1]) ))
+			 (assert (=  0 (chop 1 [1]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5]) ))
+			 (assert (=  1 (chop 3 [1 3 5]) ))
+			 (assert (=  2 (chop 5 [1 3 5]) ))
+			 (assert (= -1 (chop 0 [1 3 5]) ))
+			 (assert (= -1 (chop 2 [1 3 5]) ))
+			 (assert (= -1 (chop 4 [1 3 5]) ))
+			 (assert (= -1 (chop 6 [1 3 5]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5 7]) ))
+			 (assert (=  1 (chop 3 [1 3 5 7]) ))
+			 (assert (=  2 (chop 5 [1 3 5 7]) ))
+			 (assert (=  3 (chop 7 [1 3 5 7]) ))
+			 (assert (= -1 (chop 0 [1 3 5 7]) ))
+			 (assert (= -1 (chop 2 [1 3 5 7]) ))
+			 (assert (= -1 (chop 4 [1 3 5 7]) ))
+			 (assert (= -1 (chop 6 [1 3 5 7]) ))
+			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
+  chop
+  [item list]
+  (if (empty? list)
+	-1
+	(loop [ min 0 mid (quot (count list) 2) max (count list)]
+	  (if (= item (get list mid))
+		mid
+		(if (or (= mid min) (= mid max))
+		  -1
+		  (if (< item (get list mid))
+			(recur min (quot (+ mid min) 2) mid)       ; look left
+			(recur mid (quot (+ mid max) 2) max))))))) ; look right
+
+(test #'chop)
+

kata2/code_kata_2c.clj

+; http://codekata.pragprog.com/2007/01/kata_two_karate.html
+
+(ns code-kata)
+
+(defn evaluate-list
+  " Returns offset if list contains only item, otherwise -1 "
+  [ item list offset ]
+  (if (= item (first list))
+	offset
+	-1))
+
+(defn get-left-half
+  " Returns the left half of the list "
+  [ list mid ]
+  (first (split-at mid list)))
+
+(defn get-right-half
+  " Returns the right half of the list "
+  [ list mid ]
+  (first (rest (split-at mid list))))
+
+(defn bsearch
+  " Returns index of item if in list, otherwise -1 "
+  [ dummy item list offset ]
+  (if (empty? list)
+	-1
+    (if (= 1 (count list))
+	  (evaluate-list item list offset)
+	  (let [ mid        (quot (count list) 2)
+			 left-half  (bsearch dummy item (get-left-half list mid)  offset )
+			 right-half (bsearch dummy item (get-right-half list mid) (+ mid offset)) ]
+		(if (= -1 left-half)
+		  right-half
+		  left-half)))))
+  
+(defn
+  #^{:test (fn []
+			 (assert (= -1 (chop 3 []) ))
+			 (assert (= -1 (chop 3 [1]) ))
+			 (assert (=  0 (chop 1 [1]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5]) ))
+			 (assert (=  1 (chop 3 [1 3 5]) ))
+			 (assert (=  2 (chop 5 [1 3 5]) ))
+			 (assert (= -1 (chop 0 [1 3 5]) ))
+			 (assert (= -1 (chop 2 [1 3 5]) ))
+			 (assert (= -1 (chop 4 [1 3 5]) ))
+			 (assert (= -1 (chop 6 [1 3 5]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5 7]) ))
+			 (assert (=  1 (chop 3 [1 3 5 7]) ))
+			 (assert (=  2 (chop 5 [1 3 5 7]) ))
+			 (assert (=  3 (chop 7 [1 3 5 7]) ))
+			 (assert (= -1 (chop 0 [1 3 5 7]) ))
+			 (assert (= -1 (chop 2 [1 3 5 7]) ))
+			 (assert (= -1 (chop 4 [1 3 5 7]) ))
+			 (assert (= -1 (chop 6 [1 3 5 7]) ))
+			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
+  chop
+  [item list]
+  (let [ mid         (quot (count list) 2)
+		 left-agent  (agent -1)
+		 right-agent (agent -1) ]
+	(send left-agent  bsearch item (get-left-half list mid)  0)
+	(send right-agent bsearch item (get-right-half list mid) mid)
+	(await left-agent right-agent)
+	(if (= -1 @left-agent)
+	  @right-agent
+	  @left-agent)))
+
+(test #'chop)
+
+(shutdown-agents)
+

kata2/code_kata_2d.clj

+; http://codekata.pragprog.com/2007/01/kata_two_karate.html
+
+(ns code-kata)
+
+  
+(defn
+  #^{:test (fn []
+			 (assert (= -1 (chop 3 []) ))
+			 (assert (= -1 (chop 3 [1]) ))
+			 (assert (=  0 (chop 1 [1]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5]) ))  ; failing
+			 (assert (=  1 (chop 3 [1 3 5]) ))
+			 (assert (=  2 (chop 5 [1 3 5]) ))  ; failing
+			 (assert (= -1 (chop 0 [1 3 5]) ))
+			 (assert (= -1 (chop 2 [1 3 5]) ))
+			 (assert (= -1 (chop 4 [1 3 5]) ))
+			 (assert (= -1 (chop 6 [1 3 5]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5 7]) )) ; failing
+			 (assert (=  1 (chop 3 [1 3 5 7]) ))
+			 (assert (=  2 (chop 5 [1 3 5 7]) ))
+			 (assert (=  3 (chop 7 [1 3 5 7]) ))
+			 (assert (= -1 (chop 0 [1 3 5 7]) ))
+			 (assert (= -1 (chop 2 [1 3 5 7]) ))
+			 (assert (= -1 (chop 4 [1 3 5 7]) ))
+			 (assert (= -1 (chop 6 [1 3 5 7]) ))
+			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
+  chop
+  [item list]
+  (def start        (atom 0))
+  (def offset       (atom (quot (count list) 2)))
+  (def current-item (atom nil))
+
+  (loop [ position (+ @start @offset) ]
+	(reset! current-item (get list position))
+	(if (nil? @current-item)
+	  -1
+	  (if (= @current-item item)
+		position
+		(if (= @offset 0)
+		  -1
+		  (do
+			(reset! start  position)
+			(reset! offset (quot @offset 2))
+			(if (< @current-item item)
+			  (recur (+ position @offset))  ; go right
+			  (recur (- position @offset))  ; go left
+	  	    )
+	      )
+        )
+      )
+    )
+  )
+)
+
+(test #'chop)
+

kata2/code_kata_2e.clj

+; http://codekata.pragprog.com/2007/01/kata_two_karate.html
+
+; ------------------------------------------------------------
+;  Algorithm taken from Programming Pearls, 2nd Edition, p.36
+;   written by Jon Bentley, published by Addison Wesley
+; ------------------------------------------------------------
+
+(ns code-kata)
+
+
+(defmacro mid []
+  (list 'quot '(+ lower upper) 2) )
+
+(defmacro get-mid []
+  (list 'get 'list '(mid)))
+
+(defmacro get-upper []
+  (list '- '(count list) 1 ))
+
+(defmacro look-left []
+  (list 'recur 'lower '(- (mid) 1)))
+
+(defmacro look-right []
+  (list 'recur '(+ (mid) 1) 'upper ))
+
+(defmacro search-exhausted []
+  (list '> 'lower 'upper))
+
+(defmacro do-search [ & body ]
+  ; NOT WORKING - "Can only recur from tail position"
+  `(loop [ ~'lower 0
+		   ~'upper (get-upper) ] ~@body
+     {:lower ~'lower :upper ~'upper }))
+
+(defn
+  #^{:test (fn []
+			 (assert (= -1 (chop 3 []) ))
+			 (assert (= -1 (chop 3 [1]) ))
+			 (assert (=  0 (chop 1 [1]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5]) ))
+			 (assert (=  1 (chop 3 [1 3 5]) ))
+			 (assert (=  2 (chop 5 [1 3 5]) ))
+			 (assert (= -1 (chop 0 [1 3 5]) ))
+			 (assert (= -1 (chop 2 [1 3 5]) ))
+			 (assert (= -1 (chop 4 [1 3 5]) ))
+			 (assert (= -1 (chop 6 [1 3 5]) ))
+
+			 (assert (=  0 (chop 1 [1 3 5 7]) ))
+			 (assert (=  1 (chop 3 [1 3 5 7]) ))
+			 (assert (=  2 (chop 5 [1 3 5 7]) ))
+			 (assert (=  3 (chop 7 [1 3 5 7]) ))
+			 (assert (= -1 (chop 0 [1 3 5 7]) ))
+			 (assert (= -1 (chop 2 [1 3 5 7]) ))
+			 (assert (= -1 (chop 4 [1 3 5 7]) ))
+			 (assert (= -1 (chop 6 [1 3 5 7]) ))
+			 (assert (= -1 (chop 8 [1 3 5 7]) )) ) }
+  chop
+  [item list]
+  (do-search
+	(if (search-exhausted)
+	  -1
+	  (if (< (get-mid) item)
+		(look-right)
+		(if (= (get-mid) item)
+		  (mid)
+		  (look-left))))))
+
+(test #'chop)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.