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
from decimal import Decimal, getcontext | |
from vector import Vector | |
getcontext().prec = 30 | |
class Line(object): | |
__NO_NONZERO_ELTS_FOUND_MSG = 'No nonzero elements found' |
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
# Write a function 'kalman_filter' that implements a multi- | |
# dimensional Kalman Filter for the example given | |
from math import * | |
class matrix: | |
# implements basic operations of a matrix class | |
def __init__(self, value): |
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
# In this exercise, you should implement the | |
# resampler shown in the previous video. | |
from math import * | |
import random | |
landmarks = [[20.0, 20.0], [80.0, 80.0], [20.0, 80.0], [80.0, 20.0]] | |
world_size = 100.0 | |
class robot: |
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
''' | |
Created on Jun 3, 2017 | |
@author: john_jimenez | |
''' | |
# ---------- | |
# User Instructions: | |
# | |
# Define a function, search() that returns a list | |
# in the form of [optimal path length, row, col]. For |
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 scala.annotation.tailrec | |
import System.in | |
import java.util.Scanner | |
object Solution { | |
private val ops = Map("add" -> add _, "find" -> find _) | |
def main(args: Array[String]): Unit = { | |
val sc = new Scanner(in) | |
var n = sc.nextInt() |
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 util.Random.nextInt | |
/** | |
Dice | |
Write a program that simulates throwing two six-sided dice 200 times, and creates a histogram of the results, like this: | |
2: XXXX | |
3: XXXXXXXXXX | |
4: XXXXXXXXXXXXXXXXXXXXXX | |
5: XXXXXXXXXXXXXXXXXXXXX |
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 util.Random.nextInt | |
trait RandomMap[K, V] { | |
def + (kv: (K, V)): RandomMap[K, V] | |
def apply(k: K): V | |
def remove(k: K): RandomMap[K, V] | |
def random: V | |
} | |
object RandomMap { |
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
trait Monoid[A] { | |
def op(a1: A, a2: A): A | |
def zero: A | |
} | |
val intAddition = new Monoid[Int] { | |
def op(int1: Int, int2: Int) = int1 + int2 | |
def zero = 0 | |
} |
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 cats.data.State | |
import cats.syntax.applicative._ // for pure | |
object PostOrderCalc { | |
type CalcState[A] = State[List[Int], A] | |
def evalInput(str: String): Int = | |
evalAll(str.split(" ").toList).runA(Nil).value | |
def evalAll(input: List[String]): CalcState[Int] = |
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
// prime: cannot be divided by any number other than itself and 1 //import cats.data.State | |
trait Prime0 { | |
def isPrime(n: Int): Boolean | |
def countPrimes(n: Int): (Int, Prime0) //trait Prime | |
} | |
object Prime0 extends App { | |
private val InitPrimeCount = Seq(0, 0, 1, 2) | |
//object Prime | |
def apply(): Prime0 = new PrimeImpl(InitPrimeCount) |