Skip to content

Month: November 2021

Lego Powered UP fibonacci

Version 1. Stores fibonacci(n) and fibonacci(n+1) in the variables a and b up to n=10. Waits 1 second between each iteration for visibility.

Pseudocode:

a = 0
b = 1
for (10) {
  wait(1)
  b = a + b
  a = b - a
}

Version 2. Blinks a powered up hub (88009 or any other). The led blinks the number of times of fibonacci(n) sequence.

Pseudocode:

a = 0
b = 1
light(RED)
for (10) {
  wait(1)
  b = a + b
  a = b - a
  c = b
  while (c!=0) {
    light(GREEN)
    wait(0.5)
    light(RED)
    c = c - 1
  }
}

It may look like a wait is needed at the second red light but in practice each block takes a little delay to execute.

flatten directory structure

Move files in current subdirectories to the current directory.

find . -mindepth 2 -type f -exec mv -t . -i '{}' +

Delete local folders that are empty.

 find . -empty -type d -delete