Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

redoing datastruct

  • Loading branch information...
commit 480bc337058d8dcd8a741a2a58eba1110184075b 1 parent 71ce64a
Marco Munizaga authored
View
1  .gitignore
@@ -3,6 +3,7 @@
/checkouts
pom.xml
*.jar
+*.sw?
*.class
.lein-deps-sum
.lein-failures
View
103 chainshot2.clj
@@ -0,0 +1,103 @@
+(ns beadgame.chainshot2)
+
+
+
+(defmacro dbg[x] `(let [x# ~x] (println "dbg:" '~x "=" x#) x#))
+
+
+
+
+(defn readFile
+ "Read the file starting board file"
+ [filename]
+ (let [filecontents (slurp filename)]
+ (println "Reading file" filename)
+ (def file filecontents)))
+
+
+
+
+(comment
+
+ The nodes wil work something like this
+
+
+ {
+ :right other-node
+ :up nil}
+
+
+ (def root-node
+ { :right other-node
+ :up nil})
+
+ (def other-node2
+ { :right nil
+ :up nil})
+
+ (def other-node
+ { :right nil
+ :up other-node2})
+
+ (readFile "startBoard")
+ (def file (reverse (clojure.string/split file #"\n")))
+
+ (def file (map #(clojure.string/split % #" ") file))
+
+ (def node-file (map (fn [row] (map #(assoc {:up nil :right nil} :val %) row)) file))
+
+ ((first file) 0)
+ (first node-file)
+
+ (if (seq '(1))
+ (println "truthy")
+ (println "falsy"))
+
+
+ (let [root-row (first node-file)]
+ (loop [first-element (first root-row)
+ rest-elements (rest root-row)]
+ (if (seq rest-elements)
+ (recur
+ (conj-graph :right first-element (first rest-elements))
+ (rest rest-elements))
+ first-element)))
+
+
+ (conj-array :right (first (first node-file)) (rest (first node-file)))
+
+
+
+
+ )
+
+
+(conj-graph :right root-node other-node2)
+
+conj-graph
+
+(def a [:up :right])
+
+(defn conj-array
+ "conj-graphs a root node to an array of items in that order"
+ [direction root-node rest-elements]
+ (loop [first-element root-node
+ rest-elements rest-elements]
+ (if (seq rest-elements)
+ (recur
+ (conj-graph direction first-element (first rest-elements))
+ (rest rest-elements))
+ first-element)))
+
+(defn conj-graph
+ "Connects two nodes, the parents to the child.
+ If there is alread a node on the parents right it will be recursively placed
+ Specify the direction as in :up"
+
+ [direction parent child]
+ (if (nil? (parent direction))
+ (assoc parent direction child)
+ (assoc parent direction (conj-graph direction (parent direction) child))))
+
+
+))))))))))
View
2  target/repl-port
@@ -1 +1 @@
-53004
+36245
View
2  target/stale/dependencies
@@ -1 +1 @@
-([:dependencies [[org.clojure/clojure "1.4.0"]]])
+([:dependencies [[org.clojure/tools.nrepl "0.2.0-beta9" :exclusions [org.clojure/clojure]] [clojure-complete "0.2.1" :exclusions [org.clojure/clojure]] [org.thnetos/cd-client "0.3.4" :exclusions [org.clojure/clojure]] [org.clojure/clojure "1.4.0"]]])
Please sign in to comment.
Something went wrong with that request. Please try again.