Skip to content

Instantly share code, notes, and snippets.

View MrYossu's full-sized avatar

Avrohom Yisroel Silver (Mr Yossu) MrYossu

View GitHub Profile
@MrYossu
MrYossu / Symbolic differentiation.linq
Created October 10, 2023 22:50
C# code for symbolic differentiation
// See https://www.pixata.co.uk/2023/10/10/symbolic-differentiation-in-c/ for an explanation
// The code below can be pasted as-is into LinqPad (change the language to "C# statements"), or used in a console application in Visual studio.
DifExp de1 = new(new(1), "*", new(2));
Console.WriteLine($"{de1} -> {de1.Differentiate("x")}");
DifExp de2 = new(new("x"), "+", de1);
Console.WriteLine($"{de2} -> {de2.Differentiate("x")}");
@MrYossu
MrYossu / Buses2
Created February 28, 2022 15:41
A second, and slightly more realistic simulation
// Variables that control the simulation...
int timeBetweenBuses = 10;
// Capacity of a bus
int busCapacity = 50;
// The maximum number of passengers that can arrive at a bus stop at any one time
int maxNewPassengers = 10;
// The number of passengers that can board the bus in one time interval.
// If the number of passengers waiting exceeds this, the bus will be at the stop for longer
int boardingRate = 10;
// How far in advance of the first bus (assuming it didn't stop) that passengers arrive at a stop
@MrYossu
MrYossu / Buses
Last active January 31, 2022 14:35
First pass at simulating buses
Random r = new();
int delay = 250;
List<BusStop> busStops = new() { new(10), new(20), new(30), new(40), new(45), new(55), new(70), new(82), new(87), new(95), new(110) };
int maxDistance = busStops.Max(l => l.Distance);
string stopsDisplay = string.Join("", Enumerable.Range(0, maxDistance).Select(n => busStops.Any(bs => bs.Distance == n) ? "|" : "-")) + "|";
List<Bus> buses = new();
int timeBetweenBuses = 10;
// The maximum number of passengers that can arrive at a bus stop at any one time
int maxNewPassengers = 5;