forked from noops-challenge/golfbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution for three challenges (noops-challenge#21)
* feature: add solution for 10print * feature: add solution to the hexcode challenge * feature: add solution for conways game of life * chore: add screenshot to conway solution
- Loading branch information
1 parent
31270cb
commit f412686
Showing
9 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
while(1){process.stdout.write(Math.random() > .5 ? '\\' : '/')} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 10Print JS | ||
|
||
Solution to the 10Print challenge | ||
|
||
## Run the program | ||
|
||
This runs in terminal, and requires that NodeJS is installed | ||
|
||
``` | ||
node 10print.js | ||
``` | ||
|
||
**NOTE**: this runs infinitely, hit 'Control + C' to exit the program |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Conway's Game of Life | ||
|
||
JS based implementation of Conway's game of life. | ||
|
||
## Run | ||
|
||
This requires NodeJS, and is run in the terminal: | ||
|
||
``` | ||
node conway.js | ||
``` | ||
|
||
## Explanation | ||
|
||
Here's the unminified JS code to look over: | ||
|
||
``` | ||
const nextStage = (array) => { | ||
const newArray = []; | ||
for (let i = 0; i < array.length; i++) { | ||
newArray[i] = []; | ||
for (let j = 0; j < array[i].length; j++) { | ||
// count up all the different cells around the current cell. | ||
let l = [[i, j-1],[i, j+1],[i-1, j-1],[i-1, j],[i-1, j+1],[i+1, j-1],[i+1, j],[i+1, j+1]].reduce((count, p) => { | ||
let a = array[p[0]] || [] | ||
return count + (a[p[1]] || 0) | ||
}, 0); | ||
// check how many living cells are around, and based on that AND current status, set the new status of the cell | ||
newArray[i][j] = array[i][j] == 1 ? (l < 2 ? 0 : (l < 4 ? 1 : (l > 3 ? 0 : 1))) : (l == 3 ? 1 : 0) | ||
} | ||
} | ||
return newArray; | ||
} | ||
// build a new random board, first need a new array representing the different rows | ||
let board = new Array(20).fill(0).map(() => { | ||
// build an array of the columns in the rows. | ||
return new Array(20).fill(0).map(() => { | ||
// random number of whether the cell starts with life | ||
return Math.floor(Math.random() * 2) | ||
}) | ||
}) | ||
// infinitely rebuild the board | ||
while(1) { | ||
board = nextStage(board); | ||
console.log(board); | ||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Hexcode | ||
|
||
This is a JS based solution to the hexcode challenge. | ||
|
||
## Run | ||
|
||
This requires NodeJS to run: | ||
|
||
``` | ||
node hexcode.js | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let i=0;while(i<16777216){let a=i.toString(16);console.log(`#${'0'.repeat(6-a.length)}${a}`);i++} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.