//TODO /// <Summary>Does this page need to show the location selector?</Summary> //public bool ShowLocationSelector(MenuHelper currentMenu) //{ // return currentMenu.ShowLocationSelection && HasLocations; //} public JsonResult UpdateStatus(int locationId, string status) { var locationCacher = new LocationCacher(SharedDbContext); var location = AllLocations.SingleOrDefault(l => l.Id == locationId); if (location == null) { return(new { Saved = false }.AsJsonResult()); } if (location.TallyStatus != status) { SharedDbContext.Location.Attach(location); location.TallyStatus = status; SharedDbContext.SaveChanges(); locationCacher.UpdateItemAndSaveCache(location); } return(new { Saved = true, Location = LocationInfoForJson(location) }.AsJsonResult()); }
public string SolvePart1() { var currentLocation = new Location(0, 0); while (currentLocation.X <= XBoundary && currentLocation.Y <= YBoundary) { Dictionary <Location, int> distances = AllLocations.ToDictionary(location => location, location => CalculateManhattanDistance(currentLocation, location)); IExtremaEnumerable <KeyValuePair <Location, int> >?sortedDistances = distances.MinBy(d => d.Value); KeyValuePair <Location, int> shortestDistance = sortedDistances.First(); if (sortedDistances.Count() == 1 || sortedDistances.Count(s => s.Value == shortestDistance.Value) == 1) { // Only add if the current location is closest to a single point. var newLocation = new Location(currentLocation.X, currentLocation.Y) { IsInfinite = currentLocation.X == 0 || currentLocation.Y == 0 || currentLocation.X == XBoundary || currentLocation.Y == YBoundary }; AllLocations.SingleOrDefault(l => l == shortestDistance.Key)?.ClosestLocations.Add(newLocation); } // Move to the next location if (currentLocation.Y == YBoundary) { currentLocation.X++; currentLocation.Y = 0; } else { currentLocation.Y++; } } List <Location> nonInfiniteLocations = AllLocations.Where(l => l.ClosestLocations.All(c => !c.IsInfinite)).ToList(); Location? largestNonInfinite = nonInfiniteLocations.MaxBy(l => l.ClosestLocations.Count).First(); return($"Part 1: {largestNonInfinite.ClosestLocations.Count}"); }