Skip to content

Instantly share code, notes, and snippets.

@rudrathegreat
Created November 24, 2018 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudrathegreat/bfafd7af975f0737458c8d63c0eda84d to your computer and use it in GitHub Desktop.
Save rudrathegreat/bfafd7af975f0737458c8d63c0eda84d to your computer and use it in GitHub Desktop.
Compute Fibonacci Sequence With the BBC MicroBit
'''
This program will not display each individual number on the
microbit display. Instead, there is a different program to
show those numbers. This program needs a BBC Microbit to run.
The number of numbers my BBC MicroBit was able of calculate
in the Fibonacci Sequence was 9000 before it came across a
memory error, running out of memory to calculate any more.
'''
from microbit import *
def fibonacci(x):
a = 0
b = 1
for i in range(x-2):
c = b
b = a + b
a = c
return i + 3
while True:
if button_a.is_pressed():
start_time = running_time()
numbersGenerated = fibonacci(6844)
end_time = running_time()
time = end_time - start_time
display.scroll('run time: ' + str(time) + 'ms')
if button_b.is_pressed():
display.scroll('Num Gen: ' + str(numbersGenerated))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment