using System.Collections.Generic;
private readonly int conveyorInit = 0;
private readonly int conveyorLength = 44;
private readonly int minIndex = 11;
private readonly int maxEntryIndex = 38;
private Dictionary<int, List<(double weight, int type)>> conveyorBelt;
conveyorBelt = new Dictionary<int, List<(double, int)>>();
for (int i = conveyorInit; i <= conveyorLength; i++)
conveyorBelt[i] = new List<(double, int)> { (0.0, 0) };
public void AddSteel(int steelType, int length, float weightPerMeterFloat)
double weightPerMeter = (double)weightPerMeterFloat;
int startIndex = minIndex;
while (startIndex <= maxEntryIndex)
var entry = conveyorBelt[startIndex][0];
if (entry.Equals((0.0, 0)) || !entry.type.ToString().StartsWith("13"))
if (startIndex > maxEntryIndex)
Console.WriteLine("Error: No eligible starting position for type 13 steel within allowed region.");
int endIndex = Math.Min(startIndex + length - 1, conveyorLength);
for (int i = startIndex; i <= endIndex; i++)
var entry = conveyorBelt[i][0];
if (!(entry.Equals((0.0, 0)) || !entry.type.ToString().StartsWith("13")))
Console.WriteLine($"Error: Contiguous eligible block for merging not found at index {i} for type 13 steel.");
for (int i = startIndex; i <= endIndex; i++)
var entry = conveyorBelt[i][0];
if (entry.Equals((0.0, 0)))
conveyorBelt[i].Add((weightPerMeter, steelType));
double newWeight = entry.weight + weightPerMeter;
string mergedTypeStr = "13" + entry.type.ToString();
int mergedType = int.Parse(mergedTypeStr);
conveyorBelt[i].Add((newWeight, mergedType));
int startIndex = minIndex;
while (startIndex <= maxEntryIndex && !conveyorBelt[startIndex][0].Equals((0.0, 0)))
if (startIndex > maxEntryIndex)
Console.WriteLine("Error: No free starting slot available within allowed region.");
int endIndex = Math.Min(startIndex + length - 1, conveyorLength);
for (int i = startIndex; i <= endIndex; i++)
if (conveyorBelt[i][0].Equals((0.0, 0)))
conveyorBelt[i].Add((weightPerMeter, steelType));
public void MoveConveyor()
conveyorBelt[conveyorLength].Clear();
conveyorBelt[conveyorLength].Add((0.0, 0));
for (int i = conveyorLength; i > conveyorInit; i--)
conveyorBelt[i] = new List<(double, int)>(conveyorBelt[i - 1]);
conveyorBelt[conveyorInit].Clear();
conveyorBelt[conveyorInit].Add((0.0, 0));
public void PrintConveyor()
Console.WriteLine("Current Conveyor State:");
for (int i = conveyorInit; i <= conveyorLength; i++)
if (conveyorBelt[i].Count > 0)
Console.Write($"Index {i}: ");
foreach (var (weight, type) in conveyorBelt[i])
Console.Write($"[Type {type}, {weight} kg/m] ");
ConveyorFIFO conveyor = new ConveyorFIFO();
conveyor.AddSteel(8, 3, 2.5f);
conveyor.AddSteel(9, 4, 2.5f);
conveyor.AddSteel(10, 3, 3.0f);
conveyor.AddSteel(11, 4, 5.2f);
conveyor.AddSteel(12, 2, 4.2f);
conveyor.AddSteel(14, 2, 4.2f);
conveyor.AddSteel(15, 2, 4.2f);
conveyor.AddSteel(16, 2, 4.2f);
conveyor.AddSteel(17, 2, 4.2f);
conveyor.AddSteel(18, 3, 4.2f);
conveyor.AddSteel(19, 4, 4.2f);
Console.WriteLine("Before adding type 13:");
conveyor.PrintConveyor();
conveyor.AddSteel(13, 3, 2.5f);
conveyor.AddSteel(13, 4, 5.0f);
Console.WriteLine("After adding type 13:");
conveyor.PrintConveyor();
for (int i = 0; i < 7; i++)
Console.WriteLine($"Moving Conveyor Step {i + 1}...");
conveyor.PrintConveyor();