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
// 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")}"); |
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
// 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 |
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
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; |