Question: Full python program for the following: You have flasks that can contain 0 to 4 units of chemicals. Each chemical is represented by a pair
Full python program for the following: You have flasks that can contain to units of chemicals. Each chemical is represented by a pair of identical letters, such as AA BB CC and so forth. When you have a unit of chemical AA in a flask and pour another chemical BB on top of it they do not mix. Chemical BB stays on top of chemical AA
BB
AA
When you pour from a flask that has some unmixed chemicals to another flask, only the top most chemical flows to the next flask. In this imaginary laboratory, you can assume that you either have chemicals and flasks or chemicals and flasks. In either case, there will always be units of each chemical, all distributed randomly in the available flasks. Do not use the literal value of to represent units in your program, define a global constant instead. When a flask has only units of the same chemical, it seals automatically and cant be used anymore. The flask cannot seal if there is a different chemical in the flask. Your goal is to make a game where you start with chemical units distributed randomly across the flasks. The goal of the game is to do the least number of pouring in order to get all the chemicals in sealed flasks.
Part : Implementation
You have several flasks, each with a capacity limit of units. Alongside, you possess a collection of chemicals, where each chemical type is available in quantities of units. The file chemicals.txt is read and chemicals are queued into a bounded queue. From that bounded queue, the chemicals are distributed into flasks. Each flask should be implemented as a bounded stack. The first line of the file indicates the number of flasks and the number of chemicals respectively, separated by a space. After the first line, the text file contains two types of lines:
: Name of the chemical. For example AA or BB or CC Each chemical should be enqueued into a bounded queue.
: F This means to dequeue x chemicals from the queue, and add them to flask y one at a time. You must use a bounded queue of size to store the chemical once you have read it from the file. You must check if the queue is full when adding chemicals. If it is full and the text file tells you to add another chemical, discard that chemical and move on to the next line. You must use a bounded queue of size to store the chemical once you have read it from the file. You must check if the queue is full when adding chemicals. If it is full and the text file tells you to add another chemical, discard that chemical and move on to the next line. After taking input, move the chemical as specified by the user, then display your flasks. The flasks should be displayed with at most in one line. If there are more than flasks, the remaining should be displayed in the next row of flasks. There should be spaces between each flask, and the number of the flask should be underneath the second dash of the flask. Should you need rows to display all the flasks, the rows should be separated by line of space.On each turn, ask the user to enter the source and destination flask numbers. Make the changes to the flasks based on the game rules and display the flasks at the end. Display sealed flasks as such. Continue taking input and displaying the flasks until the game ends. The game ends when the user enters the word exit or all chemicals are in sealed flasks.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
