public override string SecondStar() { var floor1Assembly = new Assembly() .WithGenerator(Element.Thulium) .WithChip(Element.Thulium) .WithGenerator(Element.Plutonium) .WithGenerator(Element.Strontium) .WithGenerator(Element.Elerium) .WithChip(Element.Elerium) .WithGenerator(Element.Dilithium) .WithChip(Element.Dilithium); var floor2Assembly = new Assembly() .WithChip(Element.Plutonium) .WithChip(Element.Strontium); var floor3Assembly = new Assembly() .WithGenerator(Element.Promethium) .WithChip(Element.Promethium) .WithGenerator(Element.Ruthenium) .WithChip(Element.Ruthenium); var floor4Assembly = new Assembly(); var initialBuildingState = new BuildingState(0, new List <Assembly> { floor1Assembly, floor2Assembly, floor3Assembly, floor4Assembly }, 0); var result = MinimumStepsToTopFloor(initialBuildingState, 3, 14); return(result.ToString()); }
private string FirstStarUsingClasses() { var floor1Assembly = new Assembly() .WithGenerator(Element.Thulium) .WithChip(Element.Thulium) .WithGenerator(Element.Plutonium) .WithGenerator(Element.Strontium); var floor2Assembly = new Assembly() .WithChip(Element.Plutonium) .WithChip(Element.Strontium); var floor3Assembly = new Assembly() .WithGenerator(Element.Promethium) .WithChip(Element.Promethium) .WithGenerator(Element.Ruthenium) .WithChip(Element.Ruthenium); var floor4Assembly = new Assembly(); var initialBuildingState = new BuildingState(0, new List <Assembly> { floor1Assembly, floor2Assembly, floor3Assembly, floor4Assembly }, 0); var result = MinimumStepsToTopFloor(initialBuildingState, 3, 10); return(result.ToString()); }
public static int MinimumStepsToTopFloor(BuildingState initialState, int targetFloor, int targetAssemblyCount) { bool TargetCondition(BuildingState b) => b.Elevator == targetFloor && b.FloorSetup[targetFloor].Chips.Count + b.FloorSetup[targetFloor].Generators.Count == targetAssemblyCount; var(terminationNode, _) = initialState.ShortestPath(floor => floor.SafeFloorRearrangements(), TargetCondition); return(terminationNode.Depth); }
public void BuildingEqualityChips() { var building1 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), }, 0); var building2 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), }, 0); Assert.Equal(building1, building2); }
protected bool Equals(BuildingState other) { if (Elevator != other.Elevator) { return(false); } for (var i = 0; i < Floors.Count; i++) { if (!Floors[i].Equals(other.Floors[i])) { return(false); } } return(true); }
public void BuildingEqualityMixOfChipAndGenerator() { var building1 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), new Assembly().WithGenerator(Element.Hydrogen) }, 0); var building2 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), new Assembly().WithGenerator(Element.Hydrogen) }, 0); Assert.Equal(building1, building2); }
public void BuildingSafeFloorRearrangements() { var building = new BuildingState(0, new List <Assembly> { new Assembly() .WithChip(Element.Hydrogen) .WithChip(Element.Lithium), new Assembly() .WithGenerator(Element.Hydrogen) .WithGenerator(Element.Lithium) }, 0); var expectedState1 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), new Assembly() .WithChip(Element.Lithium) .WithGenerator(Element.Lithium) .WithGenerator(Element.Hydrogen) }, 0); var expectedState2 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Lithium), new Assembly() .WithChip(Element.Hydrogen) .WithGenerator(Element.Lithium) .WithGenerator(Element.Hydrogen) }, 0); var expectedState3 = new BuildingState(1, new List <Assembly> { new Assembly(), new Assembly() .WithChip(Element.Hydrogen) .WithChip(Element.Lithium) .WithGenerator(Element.Lithium) .WithGenerator(Element.Hydrogen) }, 0); var safeRearrangements = building.SafeFloorRearrangements(); Assert.Equal(3, safeRearrangements.Count); Assert.Contains(expectedState1, safeRearrangements); Assert.Contains(expectedState2, safeRearrangements); Assert.Contains(expectedState3, safeRearrangements); }
public void BuildingHashCode() { var building1 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), new Assembly().WithGenerator(Element.Hydrogen) }, 0); var building2 = new BuildingState(1, new List <Assembly> { new Assembly().WithChip(Element.Hydrogen), new Assembly().WithGenerator(Element.Hydrogen) }, 0); var hashCode1 = building1.GetHashCode(); var hashCode2 = building2.GetHashCode(); Assert.Equal(hashCode1, hashCode2); }
public void FirstStarExample() { var floor1Assembly = new Assembly().WithChip(Element.Hydrogen).WithChip(Element.Lithium); var floor2Assembly = new Assembly().WithGenerator(Element.Hydrogen); var floor3Assembly = new Assembly().WithGenerator(Element.Lithium); var floor4Assembly = new Assembly(); var initialBuildingState = new BuildingState(0, new List <Assembly> { floor1Assembly, floor2Assembly, floor3Assembly, floor4Assembly }, 0); int steps = Problem.MinimumStepsToTopFloor(initialBuildingState, 3, 4); Assert.Equal(11, steps); }