https://github.com/trescube/largest-island
https://github.com/trescube/largest-island
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/trescube/largest-island
- Owner: trescube
- Created: 2015-03-30T13:19:48.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-06-02T19:31:26.000Z (about 4 years ago)
- Last Synced: 2025-01-30T01:14:14.146Z (5 months ago)
- Language: Groovy
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Largest Island Detection
This project is an experiment of mine to show how generative testing can be used to solve the algorithmic problem of detecting the `x`,`y` pairs on an island of black points in an `m` x `n` grid.
Grid.java contains the main logic for initializing a grid with black pairs and detecting an island. This is Algorithms 101 and not very exciting.
ProbabilisticIslandGenerator is the main driver for generative testing in this project. It operates in a reverse fashion of island detection in that it selects a random starting `x`,`y` pair then probabilistically determines if a neighbor should be black or not, recursively visiting black nodes. ProbabilisticIslandGenerator takes 3 parameters:
- height of the grid
- width of the grid
- probability that a neighbor is black or notHere's an example grid generated with height=20, width=20, and probability=0.5:
```
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
--------------------
------------------BB
------------------BB
----------BB-----BBB
--------BBBB--BBBBBB
------BBBBBBB---BBBB
------BBBBBBB-BBBBBB
------BBBBBBBBBBBBBB
----BBBBB--BBBBBBBBB
BBBBBB-BB----BBBBBB-
BBBBBBBBBB--BBBBBBBB
BBBBBBBB-B----BBBBBB
```The unit test in GridSpec.groovy asserts that the blackPairs passed to the Grid instance are the same that make up the island when starting from a random `x`,`y` pair in blackPairs.