18
1
Challenge
Factory workers are usually very hard-working. However, their work is now being commonly replaced with machines.
You have to write a program that takes a number as input. It will print out a factory of 10 workers 10 times. Every time, each worker has a 1/input
chance of being 'fired' and replaced by a machine.
Input
An integer, coming from STDIN or a function call.
Output
10 cases of the factory, each one with usually more workers fired.
Output format - how to print a factory
A factory looks like this:
|0000000000|
or |0000011001|
A pipe represents the walls, a 0 represents a worker, and a 1 represents a machine, so the first print of the factory will always be |0000000000|
.
Example
Input: 10
Output:
|0000000000| //always start off with this
|0000000010| //a 1/10 chance means that this worker lost his job
|0000010010|
|0010010010|
|1010010010|
|1010110010|
|1010110011|
|1010111011|
|1010111111|
|1110111111|
Input: 5
Output:
|0000000000| //always start here
|0000001001| //a 1/5 chance means that 2 workers got fired
|1000101001|
|1000101111|
|1101101111|
|1111111111| //after achieving all machinery, the machines continue to be printed
|1111111111|
|1111111111|
|1111111111|
|1111111111|
NOTE
The number of workers fired is RANDOM - in my examples for 1/5 chance
there would always be 2 workers fired but your program has to do this randomly - sometimes 1 and sometimes 3 - they just have 1/5 chance of being fired.
The input is always
>1
? what happens if you still have a worker after 10 iterations ? – Rod – 2018-03-21T18:59:21.4871It doesn't matter - the worker can be considered very lucky ;) – lolad – 2018-03-21T19:04:48.097
2Does an input of 10 mean that each worker has a 1/10 chance of losing their job each time, or that 1/10th of the workers will be fired each time? – 12Me21 – 2018-03-21T19:06:29.483
1The former as specified in the NOTE (sometimes 1 sometimes 3) – Weijun Zhou – 2018-03-21T19:07:19.367
can we have spaces between the workers, like
| 0 0 0 0 0 0 0 0 0 0 |
? – Uriel – 2018-03-21T19:11:44.8671@12Me21 it means each worker has a 1/10 chance of losing their job, NOT the latter. – lolad – 2018-03-21T19:22:24.003
6@Uriel No, I'm mean =) – lolad – 2018-03-21T19:22:53.087
@Arnauld it seems like it was simply a mistake, and I was the only one who took it as correct :) – Jonathan Allan – 2018-03-21T21:19:30.593
Shouldthe 1/x chance per worker or per employed worker? – Pureferret – 2018-03-22T09:02:55.243
1@Pureferret It doesn´t matter. Any worker already sacked could have a (x-1)/x chance of not being fired again; but he stays fired. – Titus – 2019-02-22T17:26:16.123