M
M
Maksik2017-10-07 14:14:04
ruby
Maksik, 2017-10-07 14:14:04

Reading binary trees from an archive in Ruby?

Need help. There is an archive trees.zip with files like: barbra.tree, caryl.tree and so on. Inside each file is a serialized tree in JSON format in the form:
[1 ,,[3,[5,2]]]]
For example, one of the aline.tree files contains the following code inside:

[29,]],[24,]],[15,,[25,[42,2]]]]]]]],[18,,[19,,[26,[38,0]]]]]],[16,]],[22,,[31,[9,5]]]]]]]]]],[41,]]]],[41,]],[17,,[35,[42,18]]]]]]]],[35,,[49,,[34,[44,44]]]]]],[5,]],[40,,[12,[47,7]]]]]]]]]]]]

More classic wood look:
1
  /     \
  2      3
/  \    /  \
3   4   5   2

It is necessary to read some trees by name from the archive and display them in a format that is represented by the classic view. Tree names must be passed to the program using ENV variables.
Example:
$ NAME=small ruby trees.rb

     1
  /     \
  2      3
/  \    /  \
3   4   5   2

$ NAME=funny ruby trees.rb

Данное дерево не растет в данном лесу.

$ ruby trees.rb

Безымянных деревьев у нас не растет.

They must be read from the archive and, based on the data in the file, output a binary tree.
Please tell me how to do it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question