Skip to content

Instantly share code, notes, and snippets.

View bartosz-witkowski's full-sized avatar

Bartosz Witkowski bartosz-witkowski

View GitHub Profile
type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
import jm.music.data.Note
import jm.constants.Durations
import scala.util.Random
def digitToNote(d: Digit): Note = {
/*
* C is 1, D is 2, E is 3 etc
package logprog
import scalaz._, Scalaz._
import shapeless._
abstract class GenericUnifiable[T, Children <: HList] {
def decompose(t: T): VarId \/ Children
def mapChildren(t: T)(f: Children => Children): T
def topLevelEquivalent(t1: T, t2: T): Boolean
}
def f(w: Int, b: Int): Double = 0.5 * (w / (w + b)) + 0.5 * ((50 - w)/(100 - w - b))
val wbs = (for (w <- 0 to 50; b <- 0 to 50) yield (w, b)).tail
wbs.map { t => (t, f(t._1, t._2)) }.maxBy(_._2)
f: A -> B
a1 b_1,, b_2, b_3, ..., b_n // ord(B) constant functions
a2 a1 -> ord(B), a2 -> ord(B) // ord(B) constant functions // from the firs arg * ord(B) constant functions from the second arg
we can think of adding inhabitants of "input" arguments as having "another" as
having permutations (with repetition)
- where the ord(B) how many possibilities of "outcomes we have" and the amount
object MaybeRef {
sealed abstract class Optional
implicit class MaybeRefFunctions[A](val dis: MaybeRef[A]) extends AnyVal {
def map[B](f: A => B): MaybeRef[B] = {
if (dis == null) {
null
} else {
Tag(f(Tag.unwrap(dis)))
}
package fsp
import scala.annotation.tailrec
class OhGodWhatHaveIDoneQueue[A](
val min: Int,
val _0: List[A],
val _1: List[A],
val _2: List[A],
val _3: List[A]) {
@bartosz-witkowski
bartosz-witkowski / PairingHeap.scala
Created December 25, 2014 14:06
Pairing heap implementation
package ph
import scalaz._, Scalaz._
import scala.annotation.tailrec
sealed abstract class PairingHeap[A : Order] {
def merge(that: PairingHeap[A]): PairingHeap[A] = this match {
case Empty() =>
@bartosz-witkowski
bartosz-witkowski / Entites.scala
Created October 16, 2014 19:51
"Entity component system" with type classes
case class Map(
// in real code use something that has better copy characteristics like some tree
walls: List[Wall],
boundaries: MapBoundaries)
case class World(
player: PlayerCharacter,
map: Map,
val _10 = Stream.from(1).take(10)
val data = Stream.continually(_10).take(10).flatten.toArray
// Exiting paste mode, now interpreting.
_10: scala.collection.immutable.Stream[Int] = Stream(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
data: Array[Int] = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> :paste
// Entering paste mode (ctrl-D to finish)