using System.Collections.Generic;
public static void Main()
List<Location> locations = new() {
new() { Updated = DateTime.Now, Lat = 41 + new Random().NextDouble(), Lng = -71 + new Random().NextDouble() },
new() { Updated = DateTime.Now.AddMinutes(25), Lat = 41.980663, Lng = -73.959216 }
var bridge = claims.BridgeUsed(locations);
if (bridge is not null) {
Console.WriteLine(bridge.Name);
public class Coordinate {
public double Latitude {get;set;}
public double Longitude {get;set;}
public class BridgeBounds {
public Coordinate SW {get;set;}
public Coordinate NE {get;set;}
public string Name {get;set;}
public BridgeBounds Box1 {get;set;}
public BridgeBounds Box2 {get;set;}
public decimal Charge {get;set;}
public bool BridgeThresholdMet(Location location1, Location location2) {
return (Math.Abs((location1.Updated - location2.Updated).TotalMinutes) <= 30);
public Bridge BridgeUsed(List<Location> locations) {
foreach (var bridge in GetBridges()) {
foreach (var location in locations) {
if (InBox(1, location, bridge)) {
foreach (var bridge in GetBridges()) {
foreach (var location in locations) {
if (InBox(2, location, bridge)) {
public bool InBox(int boxNumber, Location location, Bridge bridge) {
return boxNumber == 1 ? (location.Lat >= bridge.Box1.SW.Latitude && location.Lng >= bridge.Box1.SW.Longitude && location.Lat <= bridge.Box1.NE.Latitude && location.Lng <= bridge.Box1.NE.Longitude) :
(location.Lat >= bridge.Box2.SW.Latitude && location.Lng >= bridge.Box2.SW.Longitude && location.Lat <= bridge.Box2.NE.Latitude && location.Lng <= bridge.Box2.NE.Longitude);
public List<Bridge> GetBridges() {
List<Bridge> bridges = new();
Name = "Kingston-Rhinecliff Bridge",
Box1 = new() { NE = new() { Latitude = 41.986660, Longitude = -73.951749 }, SW = new() { Latitude = 41.972751, Longitude = -73.972091 } },
Box2 = new() { NE = new() { Latitude = 41.980025, Longitude = -73.925828 }, SW = new() { Latitude = 41.968475, Longitude = -73.941793 } },
Box1 = new() { NE = new() { Latitude = 71.986660, Longitude = -73.951749 }, SW = new() { Latitude = 71.972751, Longitude = -73.972091 } },
Box2 = new() { NE = new() { Latitude = 71.980025, Longitude = -73.925828 }, SW = new() { Latitude = 71.968475, Longitude = -73.941793 } },
public DateTime Updated {get;set;}
public double Lat {get;set;}
public double Lng {get;set;}