This file contains 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
license: mit |
This file contains 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 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) | |
} |
This file contains 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
//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) |
This file contains 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
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 | |
); |