diff --git a/SICP/exercise_1_14.janet b/SICP/exercise_1_14.janet index f0fe5c9..368f4fb 100644 --- a/SICP/exercise_1_14.janet +++ b/SICP/exercise_1_14.janet @@ -62,22 +62,33 @@ (def label (string/format "(cc %d %d)" amount kind-of-coins)) (def node_name (string/format "node_%d" counter)) (def clr - (cond (= kind-of-coins 0) "lightgray" + (cond (<= kind-of-coins 0) "lightgray" + (< amount 0) "lightgray" (= amount 0) "cyan" + (= kind-of-coins 2) "pink" + (= kind-of-coins 3) "mediumorchid" + (= kind-of-coins 4) "mediumpurple1" + (= kind-of-coins 5) "khaki1" "lightgreen")) (cond - (= kind-of-coins 2) (dot/add-node (get (get graph :subgraphs) 1) node_name :label label :shape "box" :color clr) - (= kind-of-coins 1) (dot/add-node (get (get graph :subgraphs) 0) node_name :label label :shape "box" :color clr) + (= kind-of-coins 5) (dot/add-node (get (get graph :subgraphs) 4) node_name :label label :shape "box" :fillcolor clr :style "filled" :group "5") + (= kind-of-coins 4) (dot/add-node (get (get graph :subgraphs) 3) node_name :label label :shape "box" :fillcolor clr :style "filled" :group "4") + (= kind-of-coins 3) (dot/add-node (get (get graph :subgraphs) 2) node_name :label label :shape "box" :fillcolor clr :style "filled" :group "3") + (= kind-of-coins 2) (dot/add-node (get (get graph :subgraphs) 1) node_name :label label :shape "box" :fillcolor clr :style "filled" :group "2") + (= kind-of-coins 1) (dot/add-node (get (get graph :subgraphs) 0) node_name :label label :shape "box" :fillcolor clr :style "filled" :group "1") (do - (dot/add-node graph node_name :label label :shape "box" :color clr))) + (dot/add-node graph node_name :label label :shape "box" :fillcolor clr :style "filled"))) (dot/add-relation graph parent node_name) node_name) (defn count-change2 [amount denom] - (def graph (dot/create-graph :digraph "change")) - (dot/add-subgraph graph (dot/create-subgraph "rank_1" :rankdir "TB")) - (dot/add-subgraph graph (dot/create-subgraph "rank_2" :rankdir "LR")) + (def graph (dot/create "change" :graph_type :digraph)) + (dot/add-subgraph graph (dot/create-subgraph "rank_1")) + (dot/add-subgraph graph (dot/create-subgraph "rank_2" :rank "same")) + (dot/add-subgraph graph (dot/create-subgraph "rank_3" :rank "same")) + (dot/add-subgraph graph (dot/create-subgraph "rank_4" :rank "same")) + (dot/add-subgraph graph (dot/create-subgraph "rank_5" :rank "same")) (var counter 0) (defn cc [amount kind-of-coins parent] (def name (add-to graph counter amount kind-of-coins parent)) @@ -92,10 +103,10 @@ (cc (- amount (first-denomination kind-of-coins)) kind-of-coins name)))) (def result (cc amount denom "test")) - (dot/write-graph graph "exercise_1_14.gv") + (dot/write graph "exercise_1_14.gv") result) -(print (count-change2 11 1)) +(print (count-change2 11 2)) # Using the graph we can find the following relation for (cc n 1) # f(0,1) = 1