
Visual: Finding shortest path from node (1) to all other nodes.
Step 6: Repeat steps 3-5 until all vertices are flagged as visited.
This can be done trivially by looping through all visited vertices and all adjacent unvisited vertices to those visited vertices, keeping the vertex with the minimum weight edge connecting it. To reiterate: The new current vertex must be unvisited and have a minimum weight edges from a visited vertex to it.
Step 5: From the set of unvisited vertices, arbitrarily set one as the new current vertex, provided that there exists an edge to it such that it is the minimum of all edges from a vertex in the set of visited vertices to a vertex in the set of unvisited vertices. Step 4: For all vertices adjacent to the current vertex, set the distance from the source to the adjacent vertex equal to the minimum of its present distance and the sum of the weight of the edge from the current vertex to the adjacent vertex and the distance from the source to the current vertex. Step 3: Flag the current vertex as visited. Step 2: Set the current vertex to the source. Step 1: Set the distance to the source to 0 and the distance to the remaining vertices to infinity. All edges must have nonnegative weightsĭijkstra's algorithm was, originally, published by Edsger Wybe Dijkstra, winner of the 1972 A. Input.onGesture(Gesture.Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a graph Let’s add the code to increment ||variables:step|| by 1 when the micro:bit is shaken. We can use the ||input:on shake|| event to detect a step (it should notice a step most of the time). let step = 0Īssuming you attach the micro:bit to your foot or ankle, it will get shaken when you take a step.
To build a counter, we’ll need a variable ||variables:step|| to store the number of steps. If you built a watch in the make portion of the of the Watch project, you can use the code from this project with it too. Each shake event increments a counter variable. A step counter is also known as a pedometer.
This project turns the micro:bit into a simple step counter.