This file contains hidden or 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 hidden or 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 hidden or 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.collection.parallel.immutable.ParRange | |
import scala.collection.GenSeq | |
object Solution extends App { | |
private val NoTimes = Seq.empty[(Int, Int)] | |
private val NoStart = Option.empty[Int] | |
private val StdListStart = "[" | |
private val StdListEnd = "]" | |
private val Sample = (-5, 60, Seq(Seq((0, 5), (15, 30), (45, 60)), Seq((5, 15), (30, 40)))) | |
private val stdin = "" // """\[(\d+), (\d+)\]""".r |
This file contains hidden or 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 prep | |
class BST[E <: Ordered[E]](root: Node[E]) { | |
def this() = this(Empty()) | |
lazy val seq = root.seq | |
def + (e: E): BST[E] = new BST(root + e) | |
def smallest(k: Int): E = seq(seq.size - k) | |
} |
This file contains hidden or 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 MyMap.Bucket | |
class MyMap[K, V](buckets: Vector[Bucket[K, V]]) { | |
def + (kv: (K, V)) = updated(kv._1, _ + kv) | |
def - (k: K) = updated(k, _ - k) | |
def get(k: K) = getBucket(k).get(k) map (_._2) | |
def contains(k: K) = getBucket(k) contains k | |
private def updated(k: K, f: Bucket[K, V] => Bucket[K, V]) = { | |
val i = index(k) |
This file contains hidden or 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 java.time.ZonedDateTime | |
import Math.max | |
case class Ride(customerId: Long, driverId: Long, start: ZonedDateTime, stop: ZonedDateTime) | |
object Ride { | |
private implicit val zonedDateTimeOrdering: Ordering[ZonedDateTime] = Ordering.fromLessThan(_ isBefore _) | |
def longestCustomerChainDriverId(rides: Seq[Ride]): Long = { | |
def maxDriverChain(acc: (Option[Long], Int), driverRides: (Long, Seq[Ride])) = { |
This file contains hidden or 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 forcomp | |
object Anagrams { | |
/** A word is simply a `String`. */ | |
type Word = String | |
/** A sentence is a `List` of words. */ | |
type Sentence = List[Word] |
This file contains hidden or 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 math import atan2, cos, sin, sqrt, pi | |
from robot import angle_trunc | |
import sys | |
''' | |
Created on Jun 2, 2017 | |
@author: john_jimenez | |
''' | |
sys.setrecursionlimit(10000) |
This file contains hidden or 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 math import atan2, cos, sin, sqrt, pi | |
from robot import angle_trunc | |
''' | |
pr1.3 | |
Created on May 26, 2017 | |
@author: john jimenez (jjimenez36) | |
''' |
This file contains hidden or 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 math import atan2, cos, sin, sqrt, pi | |
''' | |
pr1.2 | |
Created on May 26, 2017 | |
@author: john jimenez (jjimenez36) | |
''' | |
def estimate_next_pos(m_i, other = None): |