Skip to content

Instantly share code, notes, and snippets.

Instructions:
You'll be writing a C-style command line program to assign teams for a simple game. Here's how the game works:
Each team in the game is composed of units. Each unit has two attributes: an "attack power" and a "defense power", both integers.
Each round of the game, we choose a random order for the teams. This defines a set of pairs of teams, which face off against each other. So, the first team in the list fights the second team in the list, the third team fights the fourth team, and so on. If we have an odd number of teams, the last team in the list always becomes the first team in the list for the next round.
When two teams face off, they do simultaneous damage to each other. The maximum amount of damage done to a team is the difference between the sum of the team's unit's "defense power" attributes and the sum of the other team's unit's "attack power". The actual damage done to each team in a fight is a random integer between 0 and that difference.
Each team starts with the same number of hi
//
// main.cpp
// Team Balancing
//
// Created by Brooke, Fabien
//
#include <iostream>
#include <string>
#include <vector>
/**
* Returns a string concatenation of the elements of a matrix (2d array) in "spiral" order.
* @param {[[]]} matrix - the 2d array
* @param {string} [separator] - optional separator to use between values in string, defaults to ", "
* @returns {string}
*/
function spiralMatrix(matrix, separator) {
if (matrix.length === 0 || matrix[0].length === 0) {
return "";
}
#!/bin/bash
# Re-route HTTP port 80 to 8080
iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
# Re-route HTTPS port 443 to 8443
iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8443 -j ACCEPT
// in-order binary tree traversal, returns array containing each node's value
function inOrder(node) {
if (node == null) return [];
return inOrder(node.left).concat([node.value]).concat(inOrder(node.right));
}
@fabslab
fabslab / pong.js
Last active April 5, 2016 03:12
Pong game I started in JS one night so I could play with Canvas. Currently low on features but high on nostalgia.
(function() {
var requestAnimationFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function(callback) { return window.setTimeout(callback, 1000/60); };
var cancelAnimationFrame =
@fabslab
fabslab / require-template.js
Created August 22, 2013 21:14
RequireJS loader plugin for returning a compiled template. Underscore is used here - swap out for your favourite template library.
// RequireJS loader plugin for returning a compiled template
// Underscore is used here, swap out for your favourite template library
define(['text', 'underscore'], function(textLoader, _) {
var buildMap = {};
return {
load: function(name, req, onload, config) {
@fabslab
fabslab / higher-order-messaging.js
Last active December 15, 2015 21:49
Higher-order messaging in JavaScript using Proxy
// Inspired by this version for Ruby http://kbullock.ringworld.org/2007/03/26/higher-order-messaging/
if (typeof Proxy != "undefined") {
try {
Array.prototype.where = new Proxy(Array.prototype.filter, {
apply: function(target, thisValue, args) {
return new Proxy({}, {
get: function(enumTarget, name) {
@fabslab
fabslab / additional_resources.md
Last active December 15, 2015 20:40
JavaScript Proxy demos