#153 answer seems correct but judge just times out

104 views
Skip to first unread message

Dustin Lee

unread,
Aug 3, 2012, 2:33:40 PM8/3/12
to 4clo...@googlegroups.com
I strongly suspect this is far from the elegant solution they are looking for:

(fn pairwise-disjoint2 [coll]
  (let [coll2 (vec coll)]
    (every? #(= % true)
   (for [i (range (count coll2))
 j (range (count coll2))
 :when (and (not (= i j))
    (> j i))]
     (= (count (into #{} (concat (nth coll2 i)
      (nth coll2 j))))
     (count (concat (nth coll2 i)
    (nth coll2 j))))))))

But when I enter it in for judging it just times out.  In my interactive console it tests just fine (on the first few problems at least).  If I enter a purposely bad solution it comes back immediately to say fail.

Any idea what I'm doing wrong?  Or is the judge being weird?

dustin

Toni Tuominen

unread,
Aug 4, 2012, 2:45:39 PM8/4/12
to 4clo...@googlegroups.com
I am having similar problems with multiple koans, which is sort of ruining the fun for me.

73 tic-tac-toe works on the repl but times out when submitting. My solution 

(fn tic-tac-toe [board]
  (let [row-fn (fn [board] board)
        col-fn (fn [board] (partition 3 (for [x (range 3) y (range 3)]
                               (get-in board [y x]))))
        diag-fn (fn [board] (list
                             (for [x (range 3) y (range 3) :when (= x y)]
                              (get-in board [y x]))
                             (for [x (range 2 -1 -1) y (range 2 -1 -1) :when (= x y)]
                               (get-in board [y x]))))]
       (loop [groups (apply concat (map #(%1 %2)
                               (vector row-fn col-fn diag-fn) 
                               (repeat board)))]
            (cond
             (empty? groups) nil
             (every? #{:x} (first groups)) :x
             (every? #{:o} (first groups)) :o
             :else (recur (rest groups))))))

And for 120 sum of square digits

(fn [nums]
  (letfn [(digits [n]
                  (let [result n
                        expo (Math/floor (Math/log10 result))]
                       (loop [s []
                              r result
                              e expo]
                         (if (neg? e)
                           s
                           (recur (conj s (int (quot r (Math/pow 10 e))))
                                  (rem r (Math/pow 10 e))
                                  (dec e))))))
          (sum-squared-components [digits]
                              (apply + (map #(* % %) digits)))]
  (->> nums
       (map digits)
       (map sum-squared-components)
       (map vector nums)
       (filter (fn [[x y]] (< x y)))
       (count))))

Would be nice to know what it is causing this behaviour.

- Toni

Alan Malloy

unread,
Aug 4, 2012, 8:50:03 PM8/4/12
to 4clo...@googlegroups.com
Sorry, everyone, about the timeout issues over the past week or two. We
updated our sandboxing library to get some new features but the slowdown
is dramatic. I've rolled back to the older version for the moment, and
everything should be much snappier now. Let us know if you're still
having trouble with timeouts.

Toni Tuominen

unread,
Aug 5, 2012, 8:10:42 AM8/5/12
to 4clo...@googlegroups.com
Tic-tac-toe passed now. Square digits passed first 3 but the last one (with range 1000) still timed out :( On my macbook air it takes 180 ms to run. I guess the digit parsing stuff is too slow on the sandbox. Even when I changed that to faster one (runs in 26 ms on my machine) the last one still times out.

- Toni
Reply all
Reply to author
Forward
0 new messages