Minecraft Binary Plot
Tue 10 October 2017Fibonacci Sequence Binary Plot¶
The program creates an array of numbers, starting with 1, 1, and then array[n-1] + array [n-2]. To convert the number to binary, while x > 1: we find x mod 2 and then set to x = floor (x/2). The program creates a black and white binary plot of the Fibonacci sequence like this:
http://mathworld.wolfram.com/FibonacciNumber.html
Here is the MakeCode JavaScript for this program:
let blocktype = 0
let list: number[] = []
let binarray: number[] = []
let item = 0
let x = 0
let height = 0
let column = 0
player.onChat("run", function () {
fibiter()
})
function fibiter() {
column = 0
for (let i = 0; i < 2; i++) {
item = 1
list.insertAt(0, item)
int = item
inttobin()
column = column + 1
}
for (let i = 0; i < 87; i++) {
item = list[0] + list[1]
list.insertAt(0, item)
int = item
inttobin()
column += 1
}
}
function inttobin() {
height = 0
while (0 < int) {
binarray.insertAt(0, int % 2)
if (int % 2 == 0) {
blocktype = blocks.block(Block.BlockOfQuartz)
} else {
blocktype = blocks.block(Block.Obsidian)
}
blocks.place(blocktype, positions.create(30, height, column))
int = Math.floor(int/2)
height += 1
}
}
let int = 0
x = 0
And here is the result:
You can see in the lower left hand side of the triangle where the computational limit of MakeCode is reached in converting the Fibonacci number to binary (it appears as a triangle of white blocks, or zeroes).