C -> D o D
D -> C
D -> t
D -> D o D
D -> t
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
# PROBLEM: Small brewery produces ale and beer | |
# Production is limited by scarce resources: corn, hops, barley malt. | |
# Recipes for ale and beer require differenty proportions of resources | |
# | |
# Ale (barrel) | |
# - 5lb corn | |
# - 4oz hops | |
# - 35lb malt | |
# - $13 profit | |
# |
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
const reduce = (reducer, initial, [head, ...tail]) => | |
head // condition to go or stop | |
? reduce(reducer, reducer(initial, head), tail) // recursion | |
: initial // stop | |
const map = (mapper, [head, ...tail]) => | |
head // condition to go or stop | |
? [ mapper(head), ...map(mapper, tail) ] //recursion | |
: [] // stop |
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
/* | |
* For something like A == 2 AND (B > 3 OR C >= 4 ) | |
*/ | |
start | |
= additive | |
additive | |
= left:multiplicative _ "OR" _ right:additive { return left + " OR " + right; } | |
/ multiplicative |
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
sequence: (A B C ...) => A B C ... | |
ordered choice: (/ A B C ...) => A / B / C / ... | |
optional branch: (? ...) => (...)? | |
zero or more: (* ...) => (...)* | |
one or more: (+ ...) => (...)+ | |
not: (! ...) => !(...) | |
and (lookahead): (& ...) => &(...) | |
drop node: (: ...) - Drops a node from the parse tree. | |
concat captures: (~ ...) - Concatenates captures. |
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
// Parse a document using "offside rule" indentation (as in Python) into lines | |
// grouped by indentation level, using PEG.js. | |
// Attempts to segregate the "stateful" rules from the other production/parsing | |
// rules by "disallowing" indentation-level-sensitive rules from consuming any | |
// text. | |
{ var margin_stack = [""]; } | |
Document | |
= content: Element+ |
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
class OrderBook(side: Side, orderTypes: (Order => OrderType)) | |
extends mutable.Publisher[OrderBookEvent] { | |
private case class OrdersAtLimit(limit: Double, orders: FastList[Order]) | |
private case class OrderLocation(list: FastList.Entry[OrdersAtLimit], entry: FastList.Entry[Order]) | |
private val marketBook: FastList[Order] = FastList() | |
private val limitBook = FastList[OrdersAtLimit]() | |
private val priceOrdering = if (side == Sell) Ordering[Double] else Ordering[Double].reverse |
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 com.euronextclone; | |
import com.euronextclone.ordertypes.Limit; | |
import com.google.common.base.Function; | |
import com.google.common.base.Optional; | |
import com.google.common.base.Predicate; | |
import com.google.common.collect.FluentIterable; | |
import com.google.common.collect.Lists; | |
import hu.akarnokd.reactive4java.reactive.DefaultObservable; | |
import hu.akarnokd.reactive4java.reactive.Observable; |
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
sealed trait PriceLevel | |
case object MarketPrice extends PriceLevel | |
case class LimitPrice(limit: Double) extends PriceLevel | |
case object PegPrice extends PriceLevel |
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
sealed trait OrderBookEvent | |
case class Trade(buyingBroker: String, sellingBroker: String, | |
price: Double, qty: Double) extends OrderBookEvent | |
case class RejectedOrder(order: Order) extends OrderBookEvent | |
case class CancelledOrder(order: Order) extends OrderBookEvent |