Tree from nesting levels: Difference between revisions

J: draft implementation
(Added Fōrmulæ solution)
(J: draft implementation)
Line 1,041:
 
Back to: [3,3,3,1,1,3,3,3]</pre>
 
=={{header|J}}==
 
Without any use cases for these trees, it's difficult to know if any implementation is correct.
 
Therefore, initially, we'll take the simplest implementation which satisfies an interpretation of the description of the task.
 
<lang J> <^:]each ''
 
<^:]each 1 2 4
┌───┬─────┬─────────┐
│┌─┐│┌───┐│┌───────┐│
││1│││┌─┐│││┌─────┐││
│└─┘│││2│││││┌───┐│││
│ ││└─┘│││││┌─┐││││
│ │└───┘│││││4│││││
│ │ ││││└─┘││││
│ │ │││└───┘│││
│ │ ││└─────┘││
│ │ │└───────┘│
└───┴─────┴─────────┘
<^:]each 3 1 3 1
┌───────┬───┬───────┬───┐
│┌─────┐│┌─┐│┌─────┐│┌─┐│
││┌───┐│││1│││┌───┐│││1││
│││┌─┐│││└─┘│││┌─┐│││└─┘│
││││3││││ ││││3││││ │
│││└─┘│││ │││└─┘│││ │
││└───┘││ ││└───┘││ │
│└─────┘│ │└─────┘│ │
└───────┴───┴───────┴───┘
<^:]each 1 2 3 1
┌───┬─────┬───────┬───┐
│┌─┐│┌───┐│┌─────┐│┌─┐│
││1│││┌─┐│││┌───┐│││1││
│└─┘│││2│││││┌─┐│││└─┘│
│ ││└─┘│││││3││││ │
│ │└───┘│││└─┘│││ │
│ │ ││└───┘││ │
│ │ │└─────┘│ │
└───┴─────┴───────┴───┘
<^:]each 3 2 1 3
┌───────┬─────┬───┬───────┐
│┌─────┐│┌───┐│┌─┐│┌─────┐│
││┌───┐│││┌─┐│││1│││┌───┐││
│││┌─┐│││││2│││└─┘│││┌─┐│││
││││3│││││└─┘││ ││││3││││
│││└─┘│││└───┘│ │││└─┘│││
││└───┘││ │ ││└───┘││
│└─────┘│ │ │└─────┘│
└───────┴─────┴───┴───────┘
<^:]each 3 3 3 1 1 3 3 3
┌───────┬───────┬───────┬───┬───┬───────┬───────┬───────┐
│┌─────┐│┌─────┐│┌─────┐│┌─┐│┌─┐│┌─────┐│┌─────┐│┌─────┐│
││┌───┐│││┌───┐│││┌───┐│││1│││1│││┌───┐│││┌───┐│││┌───┐││
│││┌─┐│││││┌─┐│││││┌─┐│││└─┘│└─┘│││┌─┐│││││┌─┐│││││┌─┐│││
││││3│││││││3│││││││3││││ │ ││││3│││││││3│││││││3││││
│││└─┘│││││└─┘│││││└─┘│││ │ │││└─┘│││││└─┘│││││└─┘│││
││└───┘│││└───┘│││└───┘││ │ ││└───┘│││└───┘│││└───┘││
│└─────┘│└─────┘│└─────┘│ │ │└─────┘│└─────┘│└─────┘│
└───────┴───────┴───────┴───┴───┴───────┴───────┴───────┘</lang>
 
=={{header|Julia}}==
6,962

edits