Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected timeout on Code Kata: Wonderlands / 3 #19

Open
oliverjensen-wk opened this issue Nov 7, 2017 · 1 comment
Open

Unexpected timeout on Code Kata: Wonderlands / 3 #19

oliverjensen-wk opened this issue Nov 7, 2017 · 1 comment

Comments

@oliverjensen-wk
Copy link

In the tiny-maze problem, I'm getting a code timeout that I don't understand. My submission fails the second test (4x4 maze) with the following error:

Execution Time Out! Your code execution time took more than 2.5 seconds.

However, executing the identical test in a local REPL returns instantly. In don't understand where the extra delay is coming from.

For reference, my code is as follows:

(ns tiny-maze.solver)

(defn find-start [maze]
  (let [width (count (first maze))
        flat  (flatten maze)
        idx   (.indexOf flat :S)]
    [(quot idx width) (rem idx width)]
    ))

(defn get-loc [row col maze]
  (nth (nth maze row) col))

(defn mark-place [row col maze]
  (partition (count (first maze))
    (for [r (range (count maze))
          c (range (count (first maze)))]
      (if (and (= r row) (= c col)) :x (get-loc r c maze)))))

(defn solve-maze-helper [cr cc maze]
  (if (or (< cr 0) (< cc 0) (>= cr (count maze)) (>= cc (count (first maze))))
    false
    (let [current   (get-loc cr cc maze)
          progress  (mark-place cr cc maze)]
      (if (= current :E) progress
        (if (and (not= current 0) (not= current :S)) false
          (or 
            (solve-maze-helper (inc cr) cc progress)
            (solve-maze-helper (dec cr) cc progress)
            (solve-maze-helper cr (inc cc) progress)
            (solve-maze-helper cr (dec cc) progress)))))))

(defn solve-maze 
  [maze]
  (let [[row col] (find-start maze)]
    (solve-maze-helper row col maze)))
@oliverjensen-wk oliverjensen-wk changed the title Timeout on Kata Wonderlands / 3 Unexpected timeout on Kata Wonderlands / 3 Nov 7, 2017
@oliverjensen-wk oliverjensen-wk changed the title Unexpected timeout on Kata Wonderlands / 3 Unexpected timeout onn Code Kata: Wonderlands / 3 Nov 7, 2017
@oliverjensen-wk oliverjensen-wk changed the title Unexpected timeout onn Code Kata: Wonderlands / 3 Unexpected timeout on Code Kata: Wonderlands / 3 Nov 7, 2017
@ertugrulcetin
Copy link
Member

@oliverjensen-wk thanks for reaching out! There is a time limitation for security reason which is 2.5 seconds so you need to optimize your code for this problem, sorry about that :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants