Created
May 4, 2012 07:45
-
-
Save ulsa/2592954 to your computer and use it in GitHub Desktop.
neighbors for a cell in clojurescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cljs.user> (neighbors [1 1]) | |
([0 0] [0 1] [0 2] [1 0] [1 2] [2 0] [2 1] [2 2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn neighbors [[x y]] | |
(for [dx [-1 0 1] | |
dy (if (zero? dx) [-1 1] [-1 0 1])] | |
[(+ x dx) (+ y dy)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function neighbors(p__36) { | |
var vec__37__38 = p__36; | |
var x__39 = cljs.core.nth.call(null, vec__37__38, 0, null); | |
var y__40 = cljs.core.nth.call(null, vec__37__38, 1, null); | |
var iter__614__auto____51 = (function iter__41(s__42) { | |
return (new cljs.core.LazySeq(null, false, (function () { | |
var s__42__45 = s__42; | |
while (true) { | |
if (cljs.core.truth_(cljs.core.seq.call(null, s__42__45))) { | |
var dx__46 = cljs.core.first.call(null, s__42__45); | |
var iterys__612__auto____49 = ((function (s__42__45) { | |
return (function iter__43(s__44) { | |
return (new cljs.core.LazySeq(null, false, ((function (s__42__45) { | |
return (function () { | |
var s__44__47 = s__44; | |
while (true) { | |
if (cljs.core.truth_(cljs.core.seq.call(null, s__44__47))) { | |
var dy__48 = cljs.core.first.call(null, s__44__47); | |
return cljs.core.cons.call(null, cljs.core.Vector.fromArray([cljs.core._PLUS_.call(null, x__39, dx__46), cljs.core._PLUS_.call(null, y__40, dy__48)]), iter__43.call(null, cljs.core.rest.call(null, s__44__47))); | |
} else { | |
return null; | |
} | |
break; | |
} | |
}); | |
})(s__42__45)))); | |
}); | |
})(s__42__45)); | |
var fs__613__auto____50 = cljs.core.seq.call(null, iterys__612__auto____49.call(null, (cljs.core.truth_(cljs.core.zero_QMARK_.call(null, dx__46)) ? cljs.core.Vector.fromArray([-1, 1]) : cljs.core.Vector.fromArray([-1, 0, 1])))); | |
if (cljs.core.truth_(fs__613__auto____50)) { | |
return cljs.core.concat.call(null, fs__613__auto____50, iter__41.call(null, cljs.core.rest.call(null, s__42__45))); | |
} else { | |
{ | |
var G__52 = cljs.core.rest.call(null, s__42__45); | |
s__42__45 = G__52; | |
continue; | |
} | |
} | |
} else { | |
return null; | |
} | |
break; | |
} | |
}))); | |
}); | |
return iter__614__auto____51.call(null, cljs.core.Vector.fromArray([-1, 0, 1])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment