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
//Manager Class | |
import java.util.ArrayList; | |
public class Manager | |
{ | |
private ArrayList<Photographer> photographers; | |
private ArrayList<Assignment> assignments; | |
private Portfolio portfolio; | |
public Manager() { |
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
// Sum of a Range | |
function range (start, finish, step) { | |
if (step === undefined) { | |
step = 1; | |
} | |
array = []; | |
var reverse = false; | |
step = Math.abs(step) | |
console.log(start, finish, step); | |
if (start > finish){ |
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
// Flattening | |
var arrays = [[1, 2, 3], [4, 5], [6]]; | |
//arrays = arrays.concat([5000]); | |
arrays = arrays.reduce(function(prev, cur) { return prev.concat(cur); }); | |
console.log(arrays); | |
// → [1, 2, 3, 4, 5, 6] | |
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
// A Vector Type | |
function Vector(x, y){ | |
this.x = x; | |
this.y = y; | |
}; | |
Vector.prototype.plus = function(other_vector) { | |
return new Vector(this.x + other_vector.x, this.y + other_vector.y); | |
}; |
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
// Artificial Stupidity | |
function SmartPlantEater() { | |
this.energy = 20; | |
this.last_reproduction = 0; | |
} | |
SmartPlantEater.prototype.act = function(view) { | |
var space = view.find(" "); | |
if (this.energy > 60 && space && this.last_reproduction > 60) { | |
this.last_reproduction = 0; | |
return {type: "reproduce", direction: space}; |
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
// Retry | |
function MultiplicatorUnitFailure() {} | |
MultiplicatorUnitFailure.prototype = Object.create(Error.prototype); | |
function primitiveMultiply(a, b) { | |
if (Math.random() < 0.5) | |
return a * b; | |
else | |
throw new MultiplicatorUnitFailure(); | |
} |
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
// Regex Golf | |
verify(/ca[rt]/, | |
["my car", "bad cats"], | |
["camper", "high art"]); | |
verify(/pr?op/, | |
["pop culture", "mad props"], | |
["plop"]); |
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
// Month Names | |
var monthName = function() { | |
var names = ["January", "February", "March", "April", "May", | |
"June", "July", "August", "September", "October", | |
"November", "December"]; | |
return { | |
name: function(number) { return names[number]; }, | |
number: function(name) { return names.indexOf(name); } | |
}; | |
}(); |
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
/* | |
Background: | |
- The Grid object has an array of Vector objects accessible in the Grid's "vectors" attribute | |
- A Vector object has a "value" attribute that contains "O", "X", or null if not set | |
- The checkForWin method on the Grid returns true if and only if there is a win state in tic-tac-toe | |
* The win state is determined by looping through all the various winCombos, where winCombos is an array of arrays, whose inner arrays represent the 3 indexes of the Grid's "vectors" array that refer to row, collumn, or diagonal on a tic-tac-toe board which -if all containing the same Vector "value" value- constitutes a win. | |
*/ | |
// Elegant, non-performant |
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
//1) Fix computer algorithm (assigning to Anth) | |
// In Player's .makeMove method: | |
if (index == null) { | |
// No block? Try for center... | |
//console.log('computer is attempting to center'); | |
if (grid.vectors[4].value == null) { | |
index = 4; | |
} | |
} |
OlderNewer