Skip to content

Instantly share code, notes, and snippets.

View ShlomoAbraham's full-sized avatar

Shlomo Abraham ShlomoAbraham

View GitHub Profile
@ShlomoAbraham
ShlomoAbraham / .block
Created October 17, 2019 15:47
fresh block
license: mit
import random
import itertools
# solution is a dictionary:
# - Key is a tuple of (score: int, cards_remaining: int)
# - Value is a tuple of (continue_drawing: bool, expected_value: float)
solution = {
(-1, 1): (True, 0),
(1, 1): (False, 1)
}
@ShlomoAbraham
ShlomoAbraham / ImmutableQueueDemo.cs
Last active May 18, 2018 14:01
Immutable Collections
//uses nuget System.Immutable.Collections
//using System.Immutable.Collections;
//On an implementation level, an ImmutableQueue is a linked list with head and tail pointers. So q is a reference to an empty list.
var q = ImmutableQueue<int>.Empty; //[]
//Create a new node, and point it towards the list 'q' (which is empty)
var q1 = q.Enqueue(1); // 1.
//Create a new node, and point it towards the list 'q1' (which is empty)
@ShlomoAbraham
ShlomoAbraham / RxStateExtensions.cs
Last active February 27, 2018 17:08
An example of state with Rx
void Main()
{
//For each number: If the previous even-indexed numbers sum to greater than 10, then multiply by -1
var numbers = Observable.Generate(new Random(), _ => true, r => r, r => r.Next(-5, 10))
.Take(100)
.Select((num, index) => Tuple.Create(num, index))
.StateSelect(0,
(state, indexedInt) => state > 10 ? indexedInt.Item1 * -1 : indexedInt.Item1, //result selector
(state, indexedInt) => indexedInt.Item2 % 2 == 0 ? state + indexedInt.Item1 : state
);