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
import { makeAutoObservable } from 'mobx'; | |
class SnakeGameStore { | |
// Defining the game grid size | |
gridSize = 10; | |
// Defining the snake's initial position and direction | |
snake = [{ x: 5, y: 5 }]; | |
direction = { x: 0, y: 1 }; // Starts moving downwards |
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
class Node { | |
id | |
value = 0.0 | |
type | |
constructor(id, type) { | |
this.id = id | |
this.type = type |
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
(defn is-merge [s part1 part2] | |
(let [s-len (count s) | |
p1-len (count part1) | |
p2-len (count part2)] | |
(if (> s-len (+ p1-len p2-len)) | |
false | |
(loop [s-idx 0 | |
p1-idx 0 | |
p2-idx 0] | |
(if (= s-idx s-len) |
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 compatibilityDistance(network1, network2, c1 = 1, c2 = 1, c3 = 0.4) { | |
const i1 = new Set(network1.connections.map((c) => c.innovation)); | |
const i2 = new Set(network2.connections.map((c) => c.innovation)); | |
const disjoint = | |
[...i1].filter((i) => !i1.has(i)).length + | |
[...i2].filter((i) => !i2.has(i)).length; | |
const excess = Math.max(i1.size, i2.size) - Math.min(i1.size, i2.size); | |
const matching = network1.connections.filter((c1) => i2.has(c1.innovation)); |
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 calculateFitness(network, data) { | |
let fitness = 0; | |
for (const { input, output } of data) { | |
const prediction = network.propagate(input); | |
const error = output[0] - prediction[0]; | |
fitness += 1 - Math.abs(error * error); | |
} | |
// Normalize the fitness value by dividing it by the number of data points | |
return fitness / data.length; | |
} |
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
const learningRate = 0.3; | |
class Sigmoid { | |
static calculate(x) { | |
return 1 / (1 + Math.exp(-x)); | |
} | |
static derivative(x) { | |
const fx = Sigmoid.calculate(x); | |
return fx * (1 - fx); |
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 getPINs(observed) { | |
// TODO: This is your job, detective! | |
function flatten(array) | |
{ | |
if(array.length == 0) | |
return array; | |
else if(Array.isArray(array[0])) | |
return flatten(array[0]).concat(flatten(array.slice(1))); | |
else |
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
const ErrorsContainer = ({errors}) => { | |
if (errors.length === 0) { | |
return null; | |
} | |
return errors.map(err => { | |
if (err.displayType === MODAL_ERROR_DISPLAY_TYPE) { | |
return <ModalError error={err} key={Math.random()} />; | |
} |
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
React.isValidElement(Component()) | |
String(component).includes('return React.createElement') |
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
class MyChart { | |
constructor(){ | |
this.foo = "foo"; | |
return this; | |
} | |
sayFoo(){ |