Coder Social home page Coder Social logo

saylenty / dotsplacementissue Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 332 KB

Algorithm solves the problem of the points placement in accordance with the length specified in the matrix

Python 14.24% Java 85.76%
python-3 dots-position placement-engine recursion algorithm java-8 javafx

dotsplacementissue's Introduction

dotsPlacementIssue

Algorithm solves the problem of the points placement according to the length which is specified in the matrix.

Implantation details

The main idea of this algorithm is to try every possible combination of calculated coordinates until the correct answer(s) is found. This is a recursive algorithm with backtracking approach.

Available solvers

  • Python implementation - finds the first possible solution
  • Java implementation
    • Simple single-thread approach
    • Rotation approach => optimized Simple one
    • Concurrent
      • Based on ForkJoin task - use concurrent technique for solving the task
      • Based on CountedCompleter task - similar to ForkJoin but with minimal interprocess communication

Available visualization

Java implementation has a JavaFX2 visualization:
JavaFX2 visualization

Example

The following matrix has been specified:

0 2 2 4 4 6 6 8 8 8
2 0 4 2 6 4 8 6 10 8
2 4 0 6 2 8 4 10 6 8
4 2 6 0 8 2 10 4 12 8
4 6 2 8 0 10 2 12 4 8
6 4 8 2 10 0 12 2 14 8
6 8 4 10 2 12 0 14 2 8
8 6 10 4 12 2 14 0 16 8
8 10 6 12 4 14 2 16 0 8
8 8 8 8 8 8 8 8 8 0

Note: Matrix must be symmetric and square one.
We skip the first row and col which are in range [0; <rows_length or cols_length>)
According to the matrix we can say the distance between two dots.
Thus, the distances:

  • From point [0] to point [0] = 0 (distance to itself is zero -> obvious)
  • From point [0] to point [1] = 2
  • Frm point [0] to point [2] = 2
    ...
  • 0->9 = 8
  • 1->0 = 2
  • 1->1 = 0 (distance to itself is zero -> obvious)
    ...

The initial dot 0 always has coordinates (0, 0).
After running the program one of the results is:
[(0, 0), (-1, 1), (1, -1), (-2, 2), (2, -2), (-3, 3), (3, -3), (-3, 5), (5, -3), (4, 4)]
If we visualise the result using Cartesian coordinate system we will get the picture:

result

Note: Blue color was used to indicate rules of calculating the distance.
Pay attention: The distance is not weight of the line which directly connects two dots (lines may be angular).

dotsplacementissue's People

Contributors

saylenty avatar

Watchers

 avatar

dotsplacementissue's Issues

Add unit tests

Create Unit tests for the project using JUnit5 framework.

Doc improvents

Create animation to show how algorithm works in dynamic

Implement RotationPointsFinder

The main idea behind this implementation is to reduce the algorithm complexity using points rotation.

Noticeable that the number of available solutions is always N*4. So that, why not calculate N solutions and then rotate each of them across X and Y axis to get the final answer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.