Skip to content

Instantly share code, notes, and snippets.

View mayonesa's full-sized avatar
🇺🇦

John Jimenez mayonesa

🇺🇦
  • Florida, USA
View GitHub Profile
from decimal import Decimal, getcontext
from vector import Vector
getcontext().prec = 30
class Line(object):
__NO_NONZERO_ELTS_FOUND_MSG = 'No nonzero elements found'
# 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):
# 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:
'''
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
@mayonesa
mayonesa / ContactTrie.scala
Last active December 11, 2017 17:08
Counts the number of names that start with the token provided
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()
@mayonesa
mayonesa / DiceHistogrammer.scala
Last active December 12, 2018 14:40
Shows 2-Die Histogram
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
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 {
@mayonesa
mayonesa / Monoids.scala
Created July 14, 2019 01:31
Monoids, Functional Programming in Scala
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
}
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] =
@mayonesa
mayonesa / Prime.scala
Last active February 4, 2022 17:23
Prime and count
// 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)