https://github.com/diego999/qr-code-game
Find the shortest path starting from the top of the QR Code to the bottom, in a way to minimize the number of black cases and then, the number of white cases.
https://github.com/diego999/qr-code-game
Last synced: about 2 months ago
JSON representation
Find the shortest path starting from the top of the QR Code to the bottom, in a way to minimize the number of black cases and then, the number of white cases.
- Host: GitHub
- URL: https://github.com/diego999/qr-code-game
- Owner: Diego999
- License: mit
- Created: 2015-01-18T12:29:00.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-26T18:35:07.000Z (over 10 years ago)
- Last Synced: 2025-01-14T13:56:28.144Z (9 months ago)
- Language: Python
- Size: 146 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QR-Code-Game
Find the shortest path starting from the top of the QR Code to the bottom, in a way to minimize the number of black cases and then, the number of white cases.# Algorithm 1
It consider the QR Code as a grid graph and where each pixel is a vertice.
Each vertex has an edge to its neighbors. The value of a edge is as follows :- If current case is a white case and the neighbor case is a black one -> 1
- If current case is a white case and also its neighbor -> 0
- If current case is a black case and the neighbor case is a white one -> 0
- If current case is a black case and also its neighbor -> 1It simply uses 0-1 BFS and get a minimum black cases paths in O(V+E). However, I didn't get time to find the BEST path between several minimum black cases paths, but it is MUCH faster than algorithm 2.
# Algorithm 2
It consider the QR Code as a grid graph and where each pixel is a vertice.
Each vertex has an edge to its neighbors. The value of a edge is as follows :- If current case is a white case and the neighbor case is a black one -> 1
- If current case is a white case and also its neighbor -> 0 + epsilon
- If current case is a black case and the neighbor case is a white one -> 0 + epsilon
- If current case is a black case and also its neighbor -> 1So moving in a black case has a cost. 0 + epsilon is a weight in order to minimize the number of white case in a path, if we have several "optimal" path.
And then, we create 2 subsets of vertices : the first one is the top vertices, the second one the bottom vertices.
Finally, we use dijsktra for each pair of vertices between thoses subsets, and we keep the shortest one.
The algorithm runs in O(V^(3/2) Lg(V))
# Requirements :
- [graph-tools](http://graph-tool.skewed.de/)
- pypng
- [pyqrcode](https://github.com/mnooner256/pyqrcode)# Examples :
- Small example


- Larger example


