Created
May 6, 2022 11:49
-
-
Save MinecraftPublisher/7c3f56f9ea508e563627336534c66700 to your computer and use it in GitHub Desktop.
Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function cellGoer() { | |
| let grid = [ | |
| /** Row 1 */ | |
| [2, 5, 6], | |
| [1, 6, 7, 3], | |
| [2, 7, 8, 4], | |
| [3, 8, 9], | |
| /** Row 2 */ | |
| [1, 6, 10, 11], | |
| [1, 2, 5, 7, 11, 12], | |
| [2, 3, 6, 8, 12, 13], | |
| [3, 4, 7, 9, 13, 14], | |
| [4, 8, 14, 15], | |
| /** Row 3 */ | |
| [5, 11, 16, 17], | |
| [5, 6, 10, 12, 17, 18], | |
| [6, 7, 11, 13, 18, 19], | |
| [7, 8, 12, 14, 19, 20], | |
| [8, 9, 13, 15, 20, 21], | |
| [9, 14, 21, 22], | |
| /** Row 4 */ | |
| [10, 17, 23], | |
| [10, 11, 16, 18, 23, 24], | |
| [11, 12, 17, 19, 24, 25], | |
| [12, 13, 18, 20, 25, 26], | |
| [13, 14, 19, 21, 26, 27], | |
| [14, 15, 20, 22, 27, 28], | |
| [15, 21, 28], | |
| /** Row 5 */ | |
| [16, 17, 24, 29], | |
| [17, 18, 23, 25, 29, 30], | |
| [18, 19, 24, 26, 30, 31], | |
| [19, 20, 25, 27, 31, 32], | |
| [20, 21, 26, 28, 32, 33], | |
| [21, 22, 27, 33], | |
| /** Row 6 */ | |
| [23, 24, 30, 34], | |
| [24, 25, 29, 31, 34, 35], | |
| [25, 26, 30, 32, 35, 36], | |
| [26, 27, 31, 33, 36, 37], | |
| [27, 28, 32, 37], | |
| /** Row 7 */ | |
| [29, 30, 35], | |
| [30, 31, 34, 36], | |
| [31, 32, 35, 37], | |
| [32, 33, 36], | |
| ] | |
| let mark = new Array(37).fill(false); | |
| let iterations = 0; | |
| let list = []; | |
| for (let cell in grid) { | |
| if (Math.random() >= 0.5) { | |
| list.push(parseInt(cell) + 1); | |
| mark[cell] = true; | |
| } | |
| } | |
| while (mark.filter(e => e === true).length !== 37) { | |
| for (let cell in grid) { | |
| /** Check how many of its neighbors are canned */ | |
| let count = 0; | |
| for (let neighbor of grid[cell]) { | |
| if (mark[neighbor - 1]) count++; | |
| } | |
| if (count >= 3) { | |
| mark[cell] = true; | |
| } | |
| } | |
| if (iterations++ >= 100) { | |
| return []; | |
| } | |
| } | |
| return list; | |
| } | |
| let smallest = new Array(37).fill(0); | |
| let iter = 0; | |
| while (true) { | |
| console.clear(); | |
| console.log('Iteration: ' + iter++ + '\nLowest: ' + smallest.length + '\nList: ' + smallest); | |
| let lowest = new Array(38).fill(0); | |
| for (i = 0; i < 100; i++) { | |
| let list = cellGoer(); | |
| if (list.length !== 0) { | |
| if (list.length <= lowest.length) { | |
| lowest = list; | |
| } | |
| } | |
| } | |
| if(lowest.length <= smallest.length) smallest = lowest; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment