Created
May 18, 2023 03:17
-
-
Save diabycode/de9dfe98e77ac61daaa7df4fa5c064a4 to your computer and use it in GitHub Desktop.
Test pour post de développeur chez Cinetpay !
This file contains 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
class Machine { | |
constructor(name, machiningTime) { | |
this.name = name | |
this.machiningTime = machiningTime | |
this.isWorking = true | |
} | |
repair(time) { | |
console.log(`${this.name} est en panne ! La réparation prendra ${time} minutes.`) | |
this.machiningTime += time | |
this.isWorking = true | |
} | |
processPiece(piece) { | |
if (Math.random() <= 0.25) { | |
this.isWorking = false | |
} | |
if (!this.isWorking) { | |
// La machine est en panne | |
const repairTime = Math.floor(Math.random() * (10 - 5 + 1) + 5) | |
this.repair(repairTime) | |
} | |
// Usinage de la pièce | |
console.log(`${this.name} traite une pièce (${piece}).`); | |
return this.machiningTime; | |
} | |
} | |
function assemblePistons(numPistons) { | |
let numHeads = numJupes = numAxes = numPistons; | |
const machiningTimes = { MT: 2, MJ: 3, MA: 2.5, MP: 1 } | |
const machines = { | |
MT: new Machine('Machine Tête', machiningTimes.MT), | |
MJ: new Machine('Machine Jupe', machiningTimes.MJ), | |
MA: new Machine('Machine Axe', machiningTimes.MA), | |
MP: new Machine('Machine Principale', machiningTimes.MP) | |
}; | |
let totalTime = 0 | |
while (numHeads >= 1 && numJupes >= 1 && numAxes >= 1) { | |
// Tri des pièces | |
totalTime += 1 | |
// Usinage des pièces (tête, jupe, axe) | |
totalTime += machines.MT.processPiece('tête') | |
totalTime += machines.MJ.processPiece('jupe') | |
totalTime += machines.MA.processPiece('axe') | |
// Assemblage des pièces | |
totalTime += machines.MP.processPiece('piston') | |
numHeads -= 1 | |
numJupes -= 1 | |
numAxes -= 1 | |
console.log("-------------") | |
} | |
return totalTime | |
} | |
const numPistonsToAssemble = 100 | |
const totalAssemblyTime = assemblePistons(numPistonsToAssemble) | |
console.log(`Temps total nécessaire pour assembler ${numPistonsToAssemble} pistons : ${totalAssemblyTime} minutes.`) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment