Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello all! I came across this conveyor belt coding challenge on a forum from 2010 and thought I'd give it a go. Although I only know JavaScript and every answer/ starting point for the challenge I've seen is in C++ or PHP.

Any pointers would be highly appreciated:)

----- Coding Challenge ------

There is a factory production line around a single a conveyor belt.

Components (of type A and B) come onto the start of the belt at random
intervals; workers must take one component of each type from the belt

as they come past, and combine them to make a finished product.

The belt is divided into fixed-size slots; each slot can hold only one
component or one finished product. There are a number of worker
stations on either side of the belt, spaced to match the size of the
slots on the belt, like this (fixed-width font ASCII pic):

v v v v v workers
---------------------
-> | A | | B | A | P | -> conveyor belt
---------------------
^ ^ ^ ^ ^ workers

In each unit of time, the belt moves forwards one position, and there

is time for a worker on one side of each slot to EITHER take an item
from the slot or replace an item onto the belt. The worker opposite
them can't touch the same belt slot while they do this.
(So you can't have one worker picking something from a slot while
their counterpart puts something down in the same place).

Once a worker has collected one of both types of component, they can
begin assembling the finished product. This takes an amount of time,

so they will only be ready to place the assembled product back on the

belt on the fourth subsequent slot. While they are assembling the
product, they can't touch the conveyor belt. Workers can only hold
two items (component or product) at a time: one in each hand.

Create a simulation of this, with three pairs of workers. At each
time interval, the slot at the start of the conveyor belt should have

an equal (1/3) chance of containing nothing, a component A or a
component B.

Run the simulation for 100 steps, and compute how many finished
products come off the production line, and how many components of each
type go through the production line without being picked up by any
workers.

What I have tried:

I'd love to show what I've tried but it's the initial starting block I'm struggling with.
Posted
Updated 6-Jan-22 1:59am

1 solution

It doesn't matter what the language is, it's about the approach. @OriginalGriff has written an article on how to start that approach - How to Write Code to Solve a Problem, A Beginner's Guide[^]

An additional hint I would give - don't attempt to "convert" any code written in another language - start from scratch in your chosen language to leverage all that it can offer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900