Mercurial > hg > Database > Christie
comparison scripts/ring.rb @ 140:77169cd8a5e8
マージ blockchain
author | musou_aka |
---|---|
date | Wed, 02 Jan 2019 21:48:37 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
138:6b33e7dfb146 | 140:77169cd8a5e8 |
---|---|
1 def create_nodes(node_num) | |
2 (0..node_num - 1).map { |i| | |
3 i = "node" + i.to_s | |
4 } | |
5 end | |
6 | |
7 def print_dot(connections) | |
8 puts "digraph test {" | |
9 connections.each { |connection| | |
10 print "\t" | |
11 print connection[0] | |
12 print " -> " | |
13 print connection[1] | |
14 print ' [label="' + connection[2] + '"]' | |
15 puts | |
16 } | |
17 puts "}" | |
18 end | |
19 | |
20 node_num = ARGV[0].to_i | |
21 nodes = create_nodes(node_num) | |
22 connections = Array.new | |
23 nodes.each_with_index { |node, i| | |
24 connections << [nodes[i], nodes[(i + 1) % node_num], "right"] | |
25 connections << [nodes[i], nodes[i - 1], "left"] | |
26 } | |
27 print_dot(connections) | |
28 |