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
private Vector3 EnemyMovement(Transform closestUnit, Transform enemy) { | |
Vector3 enemyToUnit = closestUnit.position - enemy.position; | |
int maxManhattanDistancePerMove = 3; | |
int xDirection = Math.Sign(enemyToUnit.x); | |
int zDirection = Math.Sign(enemyToUnit.z); | |
int xSteps = (int) Math.Min(maxManhattanDistancePerMove, Math.Abs(enemyToUnit.x)); | |
int stepsLeft = maxManhattanDistancePerMove - xSteps; | |
int zSteps = (int) Math.Min(stepsLeft, Math.Abs(enemyToUnit.z)); | |
int dx = xDirection * xSteps; | |
int dz = zDirection * zSteps; |
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
C = 0.36 # uF | |
R1 = 1000 # Ohms | |
def analog_read(): | |
return 10000 | |
def read_resistance(): | |
n = 10 |
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
// Sketch for a servo that turns with the light intensity | |
// See video demo at https://youtu.be/BSZc9sFR4vs | |
#include <Servo.h> | |
const Servo myServo; | |
const int lightSensor = A0; | |
const int red = 7; | |
const int green = 8; | |
const int speaker = 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
package flying | |
import scala.io.Source | |
case class Runway(airportId: String, runwayName: String, length: Int, surface: String) | |
class Runways { | |
/** Runways data from http://ourairports.com/data/, converted from csv to tsv with a spreadsheet program */ | |
private val source = Source.fromFile("/Users/daveb/Documents/Flying/data/runways.tsv") | |
val runways = ( |
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
def passthrough_filter(parents): | |
return filter(lambda _: True, parents) | |
def random_subset_filter(parents): | |
return filter(lambda _: random.random() < .15, parents) | |
def upcoming_filter(parents): | |
return filter(lambda parent: parent.has_upcoming, parents) | |
def upcoming_wanted_filter(parents): |
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
import math | |
import numpy | |
from timeit import timeit | |
HIGHEST = 100000 | |
ARRAY_LEN = HIGHEST + 1 # For 0 | |
def make_sieve(): | |
sieve = numpy.ones(ARRAY_LEN) | |
mark_composites(sieve) | |
return sieve |
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
/* Display the numbers from 1 to 100 that are not divisible by both | |
4 and 7, but for those numbers divisible by 4, show ÷4 instead, and | |
for those divisible by 7, show ÷7 instead. */ | |
object Solution1 extends App { | |
println( | |
(1 to 100 map(n => { | |
def divBy(div: Int) = n % div == 0 | |
(divBy(4), divBy(7)) match { | |
case (false, false) => Some(n) |
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
val combinations: Seq[Seq[Int]] = numDice match { | |
case 1 => for (a <- 1 to numSides) yield Seq(a) | |
case 2 => for (a <- 1 to numSides; b <- 1 to numSides) yield Seq(a, b) | |
case 3 => for (a <- 1 to numSides; b <- 1 to numSides; c <- 1 to numSides) yield Seq(a, b, c) | |
} |
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
class SharpSnowballArray { | |
@SubscribeEvent | |
def replaceSnowballWithArrow(event: EntityJoinWorldEvent) { | |
val entity = event.entity | |
val world = entity.worldObj | |
entity match { | |
case snowball: EntitySnowball if ! world.isRemote => | |
-2 to 2 foreach(xOff => { | |
-2 to 2 foreach (yOff => { |