Created
December 5, 2022 16:52
-
-
Save tslater2006/9b6067835b51e7cf4417f57ff3b382b7 to your computer and use it in GitHub Desktop.
ChatGPT
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
namespace CrateMover | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Create a list of containers. | |
List<List<char>> containers = new List<List<char>>(); | |
containers.Add(new List<char> { 'a', 'b', 'c' }); | |
containers.Add(new List<char> { 'd', 'e', 'f' }); | |
containers.Add(new List<char> { 'g', 'h', 'i' }); | |
// Move two crates from container 0 to container 2. | |
MoveCrates(containers, 0, 2, 2); | |
// Print the contents of the containers. | |
for (int i = 0; i < containers.Count; i++) | |
{ | |
Console.WriteLine("Container {0}: {1}", i, string.Join(" ", containers[i])); | |
} | |
} | |
static void MoveCrates(List<List<char>> containers, int source, int destination, int numberOfCrates) | |
{ | |
// Check if the source container has enough crates to move. | |
if (containers[source].Count < numberOfCrates) | |
{ | |
throw new ArgumentException("The source container does not have enough crates to move."); | |
} | |
// Move the crates from the source container to the destination container. | |
for (int i = 0; i < numberOfCrates; i++) | |
{ | |
char crate = containers[source][i]; | |
containers[destination].Add(crate); | |
} | |
// Remove the crates from the source container. | |
containers[source].RemoveRange(0, numberOfCrates); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment